1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-27 12:07:19 +00:00

More rearchitecting of tw5dropbox

This commit is contained in:
Jeremy Ruston 2012-10-10 21:59:25 +01:00
parent 5c1ab19573
commit af264108c2
19 changed files with 310 additions and 62 deletions

13
dbld.sh
View File

@ -2,13 +2,22 @@
# build TiddlyWiki5 in the Sky for Dropbox
pushd tw5dropbox/appwiki > /dev/null
node ../../core/boot.js \
--verbose \
--savetiddler $:/core/templates/tw5dropbox.template.js ../../../../../Apps/Static\ Web\ Apps/TiddlyWiki5/public/tw5dropbox.js text/plain [!is[shadow]] \
--savetiddler $:/core/templates/index.template.html ../../../../../Apps/TiddlyWiki5/My\ TiddlyWiki/index.html text/plain [!is[shadow]] \
--savetiddler $:/core/templates/styles.template.css ../../../../../Apps/Static\ Web\ Apps/TiddlyWiki5/public/styles.css text/plain [!is[shadow]] \
|| exit 1
popd > /dev/null
pushd tw5dropbox/mainwiki > /dev/null
node ../../core/boot.js \
--verbose \
--savetiddler $:/core/templates/tw5dropbox.template.js ../../../../../Apps/Static\ Web\ Apps/TiddlyWiki5/public/tw5dropbox.js text/plain [!is[shadow]] \
--savetiddler $:/core/templates/index.template.html ../../../../../Apps/Static\ Web\ Apps/TiddlyWiki5/public/index.html text/plain [!is[shadow]] \
--savetiddler $:/core/templates/styles.template.css ../../../../../Apps/Static\ Web\ Apps/TiddlyWiki5/public/styles.css text/plain [!is[shadow]] \
|| exit 1
popd > /dev/null

View File

@ -0,0 +1,22 @@
/*\
title: $:/plugins/dropbox/dropbox-app.js
type: application/javascript
module-type: dropbox-startup
Startup the Dropbox wiki app
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
exports.startup = function() {
// Load tiddlers
$tw.plugins.dropbox.loadTiddlerFiles("/My TiddlyWiki/tiddlers",function() {
console.log("Loaded all tiddlers",$tw.wiki.tiddlers);
});
};
})();

View File

@ -0,0 +1,36 @@
{
"tiddlers": [
{
"file": "../../plugins/async.js",
"fields": {
"title": "$:/plugins/dropbox/async.js",
"type": "application/javascript",
"library": "yes"
}
},
{
"file": "../../plugins/dropbox.js",
"fields": {
"title": "$:/plugins/dropbox/dropbox.js",
"type": "application/javascript",
"module-type": "startup"
}
},
{
"file": "../../plugins/logoutmacro.js",
"fields": {
"title": "$:/plugins/dropbox/logoutmacro.js",
"type": "application/javascript",
"module-type": "macro"
}
},
{
"file": "dropbox-app.js",
"fields": {
"title": "$:/plugins/dropbox/dropbox-app.js",
"type": "application/javascript",
"module-type": "dropbox-startup"
}
}
]
}

View File

@ -0,0 +1,3 @@
title: $:/DefaultTiddlers
AllTiddlers

View File

@ -0,0 +1,80 @@
title: $:/templates/PageTemplate
<!-- The navigator catches navigation events and updates the story and history tiddlers -->
<<navigator story:"$:/StoryTiddlers" history:"$:/History" ><
<!-- Zooming chooser -->
{{navigation-panel{
<<chooser><
<<list all>>
>>
}}}
<!-- Zooming navigator -->
<<zoomigator>>
<!-- The top navigation bar -->
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
{{nav{
<<reveal state:[[$:/plugins/dropbox/IsLoggedIn]] type:match text:no><
Not logged in
>>
<<reveal state:[[$:/plugins/dropbox/IsLoggedIn]] type:match text:yes><
Logged in as (($:/plugins/dropbox/UserName))
<<dropbox.logout>< Log me out >>
>>
<!-- Navigation menu -->
* HelloThere
* [[Docs]]
*{{divider-vertical}}
<!-- Full screen button -->
<<button full-screen class:"btn btn-warning"><Full screen>>
<!-- View button -->
<<button popup:ViewDropDownState class:"btn btn-danger"><View <span class="caret"></span>>>
<!-- View dropdown -->
{{pull-right{
<<reveal state:[[$:/EditMode]] type:nomatch text:yes><
<<button modal param:[[$:/messages/EnterEditMode]] set:[[$:/EditMode]] setTo:yes class:"btn btn-success"><Edit>>
>>
<!-- Save changes is only visible in edit mode -->
<<reveal state:[[$:/EditMode]] type:match text:yes><
<<button save-wiki param:"$:/core/templates/tiddlywiki5.encrypted.template.html" class:"btn pull-right"><Save Changes (encrypted)>>
>>
<<reveal state:[[$:/EditMode]] type:match text:yes><
<<button save-wiki class:"btn pull-right"><Save Changes>>
>>
}}}
}}}
<!-- This navigator intercepts navigation events and sets the text of the specified tiddler to the target tiddler title -->
<<navigator set:[[$:/CurrentView]]><
<<reveal state:ViewDropDownState type:popup position:below><
<div class="open">
{{dropdown-menu tw-suppress-missing-tiddlylink{
* <<link to:classic>< <<reveal state:[[$:/CurrentView]] type:match text:classic>< <span class="tw-ticked-menu-item"></span> >> Classic>>
* <<link to:sideways>< <<reveal state:[[$:/CurrentView]] type:match text:sideways>< <span class="tw-ticked-menu-item"></span> >> Sideways>>
* <<link to:zoomin>< <<reveal state:[[$:/CurrentView]] type:match text:zoomin>< <span class="tw-ticked-menu-item"></span> >> Zoomin>>
}}}
</div>
>>
>>
</div>
</div>
</div>
<!-- The main story references the same story and history tiddlers as the outer navigator -->
<div class="container">
<<story story:"$:/StoryTiddlers" history:"$:/History" storyviewTiddler:[[$:/CurrentView]] storyview:classic >>
</div>
>>

View File

@ -0,0 +1,4 @@
title: SiteSubtitle
type: application/x-tiddler
for Dropbox

View File

@ -0,0 +1,4 @@
title: SiteTitle
type: application/x-tiddler
TiddlyWiki5 in the Sky

View File

@ -0,0 +1,37 @@
title: $:/core/templates/index.template.html
type: text/x-tiddlywiki-html
<!doctype html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="application-name" content="TiddlyWiki" />
<meta name="generator" content="TiddlyWiki" />
<meta name="tiddlywiki-version" content="<<version>>" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta name="format-detection" content="telephone=no">
<meta name="copyright" content="
<<serialize "$:/core/copyright.txt" text/plain>>
" />
<title><<tiddler "$:/core/wiki/title">></title>
<!----------- This is a Tiddlywiki file. The points of interest in the file are marked with this pattern ----------->
<!----------- Raw markup ----------->
<<serialize "[tag[$:/core/wiki/rawmarkup]]" text/plain>>
</head>
<body>
<!----------- Static styles ----------->
<link rel="stylesheet" href="//dl-web.dropbox.com/spa/4f6lw6nhu5zn5pr/TiddlyWiki5/public/styles.css" type="text/css" />
<!----------- Miscellaneous shadow tiddlers ----------->
<div id="shadowArea" style="display:none;">
<<serialize "[is[shadow]] -[type[text/css]] -[type[application/javascript]has[module-type]] -[type[application/javascript]library[yes]] -[[$:/core/boot.js]] -[[$:/core/bootprefix.js]]" application/x-tiddler-html-div>>
</div>
<!----------- Ordinary tiddlers ----------->
<div id="storeArea" style="display:none;">
<<serialize "$1" application/x-tiddler-html-div>>
</div>
</body>
<script src="//cdnjs.cloudflare.com/ajax/libs/dropbox.js/0.6.1/dropbox.min.js"></script>
<script src="//dl-web.dropbox.com/spa/4f6lw6nhu5zn5pr/TiddlyWiki5/public/tw5dropbox.js"></script>
</html>

View File

@ -0,0 +1,22 @@
/*\
title: $:/plugins/dropbox/dropbox-main.js
type: application/javascript
module-type: dropbox-startup
Startup the Dropbox main app
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
exports.startup = function() {
// Load tiddlers
$tw.plugins.dropbox.loadWikiFiles("/",function() {
console.log("Loaded all wikis",$tw.wiki.tiddlers);
});
};
})();

View File

@ -23,6 +23,14 @@
"type": "application/javascript",
"module-type": "macro"
}
},
{
"file": "dropbox-main.js",
"fields": {
"title": "$:/plugins/dropbox/dropbox-main.js",
"type": "application/javascript",
"module-type": "dropbox-startup"
}
}
]
}

View File

@ -0,0 +1,11 @@
title: TiddlyWiki5 in the Sky with Dropbox
Welcome to TiddlyWiki5 in the Sky with Dropbox.
! Your ~TiddlyWikis
((( [tag[wiki]] ))(WikiTemplate))
! Create new ~TiddlyWiki
+

View File

@ -0,0 +1,10 @@
title: WikiTemplate
<div class="alert">
<div>
<<view title>>
</div>
<div>
<<view url link>>
</div>
</div>

View File

@ -1,3 +1,3 @@
title: $:/DefaultTiddlers
AllTiddlers
[[TiddlyWiki5 in the Sky with Dropbox]]

View File

@ -3,16 +3,6 @@ title: $:/templates/PageTemplate
<!-- The navigator catches navigation events and updates the story and history tiddlers -->
<<navigator story:"$:/StoryTiddlers" history:"$:/History" ><
<!-- Zooming chooser -->
{{navigation-panel{
<<chooser><
<<list all>>
>>
}}}
<!-- Zooming navigator -->
<<zoomigator>>
<!-- The top navigation bar -->
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
@ -27,48 +17,10 @@ Logged in as (($:/plugins/dropbox/UserName))
<<dropbox.logout>< Log me out >>
>>
((Bugger))
<!-- Navigation menu -->
* HelloThere
* [[Docs]]
*{{divider-vertical}}
<!-- Full screen button -->
<<button full-screen class:"btn btn-warning"><Full screen>>
<!-- View button -->
<<button popup:ViewDropDownState class:"btn btn-danger"><View <span class="caret"></span>>>
<!-- View dropdown -->
{{pull-right{
<<reveal state:[[$:/EditMode]] type:nomatch text:yes><
<<button modal param:[[$:/messages/EnterEditMode]] set:[[$:/EditMode]] setTo:yes class:"btn btn-success"><Edit>>
>>
<!-- Save changes is only visible in edit mode -->
<<reveal state:[[$:/EditMode]] type:match text:yes><
<<button save-wiki param:"$:/core/templates/tiddlywiki5.encrypted.template.html" class:"btn pull-right"><Save Changes (encrypted)>>
>>
<<reveal state:[[$:/EditMode]] type:match text:yes><
<<button save-wiki class:"btn pull-right"><Save Changes>>
>>
}}}
[[App|TiddlyWiki5 in the Sky with Dropbox]]
}}}
<!-- This navigator intercepts navigation events and sets the text of the specified tiddler to the target tiddler title -->
<<navigator set:[[$:/CurrentView]]><
<<reveal state:ViewDropDownState type:popup position:below><
<div class="open">
{{dropdown-menu tw-suppress-missing-tiddlylink{
* <<link to:classic>< <<reveal state:[[$:/CurrentView]] type:match text:classic>< <span class="tw-ticked-menu-item"></span> >> Classic>>
* <<link to:sideways>< <<reveal state:[[$:/CurrentView]] type:match text:sideways>< <span class="tw-ticked-menu-item"></span> >> Sideways>>
* <<link to:zoomin>< <<reveal state:[[$:/CurrentView]] type:match text:zoomin>< <span class="tw-ticked-menu-item"></span> >> Zoomin>>
}}}
</div>
>>
>>
</div>
</div>
</div>

View File

@ -14,6 +14,7 @@ type: text/x-tiddlywiki-html
<meta name="copyright" content="
<<serialize "$:/core/copyright.txt" text/plain>>
" />
<script src="//cdnjs.cloudflare.com/ajax/libs/dropbox.js/0.6.1/dropbox.min.js"></script>
<title><<tiddler "$:/core/wiki/title">></title>
<!----------- This is a Tiddlywiki file. The points of interest in the file are marked with this pattern ----------->
@ -22,7 +23,15 @@ type: text/x-tiddlywiki-html
</head>
<body>
<!----------- Static styles ----------->
<link rel="stylesheet" type="text/css" href="styles.css" />
<div id="styleArea">
<<serialize "[is[shadow]type[text/css]]" application/x-tiddler-css>>
</div>
<!----------- Static content for Google and browsers without JavaScript ----------->
<noscript>
<div id="splashArea">
<<serialize "$:/templates/StaticContent" text/html>>
</div>
</noscript>
<!----------- Miscellaneous shadow tiddlers ----------->
<div id="shadowArea" style="display:none;">
<<serialize "[is[shadow]] -[type[text/css]] -[type[application/javascript]has[module-type]] -[type[application/javascript]library[yes]] -[[$:/core/boot.js]] -[[$:/core/bootprefix.js]]" application/x-tiddler-html-div>>
@ -31,7 +40,22 @@ type: text/x-tiddlywiki-html
<div id="storeArea" style="display:none;">
<<serialize "$1" application/x-tiddler-html-div>>
</div>
<!----------- Library modules ----------->
<div id="libraryModules" style="display:none;">
<<serialize "[[$:/core/lib/jquery.min.js]]" application/x-tiddler-library>>
<<serialize "[is[shadow]type[application/javascript]library[yes]] -[[$:/core/lib/jquery.min.js]]" application/x-tiddler-library>>
</div>
<!----------- Boot kernel prologue ----------->
<div id="bootKernelPrefix" style="display:none;">
<<serialize "$:/core/bootprefix.js" application/javascript>>
</div>
<!----------- Plugin modules ----------->
<div id="modules" style="display:none;">
<<serialize "[is[shadow]type[application/javascript]has[module-type]]" application/x-tiddler-module>>
</div>
<!----------- Boot kernel ----------->
<div id="bootKernel" style="display:none;">
<<serialize "$:/core/boot.js" application/javascript>>
</div>
</body>
<script src="//cdnjs.cloudflare.com/ajax/libs/dropbox.js/0.6.1/dropbox.min.js"></script>
<script src="tw5dropbox.js"></script>
</html>

View File

@ -17,7 +17,8 @@ var apiKey = "m+qwjj8wFRA=|1TSoitGS9Nz2RTwv+jrUJnsAj0yy57NhQJ4TkZ/+Hw==";
// Tiddler titles
var titleIsLoggedIn = "$:/plugins/dropbox/IsLoggedIn",
titleUserName = "$:/plugins/dropbox/UserName";
titleUserName = "$:/plugins/dropbox/UserName",
titlePublicAppUrl = "$:/plugins/dropbox/PublicAppUrl";
$tw.plugins.dropbox = {
client: null // Dropbox.js client object
@ -38,22 +39,27 @@ $tw.plugins.dropbox.login = function() {
// Mark us as logged in
$tw.wiki.addTiddler({title: titleIsLoggedIn, text: "yes"});
// Get user information
$tw.plugins.dropbox.getUserInfo();
// Get tiddler file metadata
$tw.plugins.dropbox.loadTiddlerFiles("/My TiddlyWiki/tiddlers",function() {
console.log("Loaded all tiddlers",$tw.wiki.tiddlers);
$tw.plugins.dropbox.getUserInfo(function() {
// Invoke any dropbox-startup modules
var mods = $tw.modules.types["dropbox-startup"];
for(var m=0; m<mods.length; m++) {
mods[m].startup();
}
});
});
};
// Get user information
$tw.plugins.dropbox.getUserInfo = function() {
$tw.plugins.dropbox.getUserInfo = function(callback) {
$tw.plugins.dropbox.client.getUserInfo(function(error,userInfo) {
if(error) {
callback(error);
return $tw.plugins.dropbox.showError(error);
}
$tw.plugins.dropbox.userInfo = userInfo;
// Save the username
$tw.wiki.addTiddler({title: titleUserName, text: userInfo.name});
callback();
});
};
@ -69,6 +75,25 @@ $tw.plugins.dropbox.logout = function() {
});
};
// Load tiddlers representing each wiki in a folder
$tw.plugins.dropbox.loadWikiFiles = function(path,callback) {
// First get the list of tiddler files
$tw.plugins.dropbox.client.stat(path,{readDir: true},function(error,stat,stats) {
if(error) {
return $tw.plugins.dropbox.showError(error);
}
console.log(stats);
// Create a tiddler for each folder
for(var s=0; s<stats.length; s++) {
var stat = stats[s];
if(!stat.isFile && stat.isFolder) {
$tw.wiki.addTiddler({title: stat.name, text: "wiki", tags: ["wiki"], url: $tw.plugins.dropbox.userInfo.publicAppUrl + stat.path + "/index.html"});
}
}
callback();
});
};
// Load tiddler files from a folder
$tw.plugins.dropbox.loadTiddlerFiles = function(path,callback) {
// First get the list of tiddler files
@ -148,6 +173,7 @@ $tw.plugins.dropbox.loadTiddlerFile = function(path,mimeType,stats,callback) {
}
});
};
// Encode a binary file as returned by Dropbox into the base 64 equivalent
// Adapted from Jon Leighton, https://gist.github.com/958841
$tw.plugins.dropbox.base64EncodeString = function(data) {