mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-27 03:57:21 +00:00
Refactored wikitest.js and tiddlywiki.js to use App.js
This commit is contained in:
parent
75e6bdef2b
commit
cc59a1b91d
15
js/App.js
15
js/App.js
@ -41,12 +41,25 @@ var App = function() {
|
|||||||
{title: "MarkupPostHead", text: ""},
|
{title: "MarkupPostHead", text: ""},
|
||||||
{title: "MarkupPreBody", text: ""},
|
{title: "MarkupPreBody", text: ""},
|
||||||
{title: "MarkupPostBody", text: ""},
|
{title: "MarkupPostBody", text: ""},
|
||||||
|
{title: "TabTimeline", text: "<<timeline>>"},
|
||||||
|
{title: "TabAll", text: "<<list all>>"},
|
||||||
|
{title: "TabTags", text: "<<allTags excludeLists>>"},
|
||||||
|
{title: "TabMoreMissing", text: "<<list missing>>"},
|
||||||
|
{title: "TabMoreOrphans", text: "<<list orphans>>"},
|
||||||
|
{title: "TabMoreShadowed", text: "<<list shadowed>>"},
|
||||||
|
{title: "AdvancedOptions", text: "<<options>>"},
|
||||||
|
{title: "PluginManager", text: "<<plugins>>"},
|
||||||
|
{title: "SystemSettings", text: ""},
|
||||||
|
{title: "ToolbarCommands", text: "|~ViewToolbar|closeTiddler closeOthers +editTiddler > fields syncing permalink references jump|\n|~EditToolbar|+saveTiddler -cancelTiddler deleteTiddler|"},
|
||||||
{title: "WindowTitle", text: "<<tiddler SiteTitle>> - <<tiddler SiteSubtitle>>"},
|
{title: "WindowTitle", text: "<<tiddler SiteTitle>> - <<tiddler SiteSubtitle>>"},
|
||||||
{title: "DefaultTiddlers", text: "[[GettingStarted]]"},
|
{title: "DefaultTiddlers", text: "[[GettingStarted]]"},
|
||||||
{title: "MainMenu", text: "[[GettingStarted]]"},
|
{title: "MainMenu", text: "[[GettingStarted]]"},
|
||||||
{title: "SiteTitle", text: "My TiddlyWiki"},
|
{title: "SiteTitle", text: "My TiddlyWiki"},
|
||||||
{title: "SiteSubtitle", text: "a reusable non-linear personal web notebook"},
|
{title: "SiteSubtitle", text: "a reusable non-linear personal web notebook"},
|
||||||
{title: "SiteUrl", text: ""}
|
{title: "SiteUrl", text: ""},
|
||||||
|
{title: "SideBarOptions", text: '<<search>><<closeAll>><<permaview>><<newTiddler>><<newJournal "DD MMM YYYY" "journal">><<saveChanges>><<slider chkSliderOptionsPanel OptionsPanel "options \u00bb" "Change TiddlyWiki advanced options">>'},
|
||||||
|
{title: "SideBarTabs", text: '<<tabs txtMainTab "Timeline" "Timeline" TabTimeline "All" "All tiddlers" TabAll "Tags" "All tags" TabTags "More" "More lists" TabMore>>'},
|
||||||
|
{title: "TabMore", text: '<<tabs txtMoreTab "Missing" "Missing tiddlers" TabMoreMissing "Orphans" "Orphaned tiddlers" TabMoreOrphans "Shadowed" "Shadowed tiddlers" TabMoreShadowed>>'}
|
||||||
];
|
];
|
||||||
this.store.shadows.shadows = shadowShadowStore;
|
this.store.shadows.shadows = shadowShadowStore;
|
||||||
for(t=0; t<shadowShadows.length; t++) {
|
for(t=0; t<shadowShadows.length; t++) {
|
||||||
|
@ -2,6 +2,6 @@ title: SeventhTiddler
|
|||||||
|
|
||||||
<<echo {{2+2}}>>
|
<<echo {{2+2}}>>
|
||||||
|
|
||||||
<<echo {{title}}>>
|
<<echo {{"title"}}>>
|
||||||
|
|
||||||
<<echo {{window}}>>
|
<<echo {{"window"}}>>
|
||||||
|
@ -7,7 +7,8 @@ TiddlyWiki command line interface
|
|||||||
/*jslint node: true */
|
/*jslint node: true */
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var WikiStore = require("./js/WikiStore.js").WikiStore,
|
var App = require("./js/App.js").App,
|
||||||
|
WikiStore = require("./js/WikiStore.js").WikiStore,
|
||||||
Tiddler = require("./js/Tiddler.js").Tiddler,
|
Tiddler = require("./js/Tiddler.js").Tiddler,
|
||||||
Recipe = require("./js/Recipe.js").Recipe,
|
Recipe = require("./js/Recipe.js").Recipe,
|
||||||
tiddlerInput = require("./js/TiddlerInput.js"),
|
tiddlerInput = require("./js/TiddlerInput.js"),
|
||||||
@ -20,6 +21,8 @@ var WikiStore = require("./js/WikiStore.js").WikiStore,
|
|||||||
aync = require("async"),
|
aync = require("async"),
|
||||||
http = require("http");
|
http = require("http");
|
||||||
|
|
||||||
|
var app = new App();
|
||||||
|
|
||||||
var parseOptions = function(args,defaultSwitch) {
|
var parseOptions = function(args,defaultSwitch) {
|
||||||
var result = [],
|
var result = [],
|
||||||
a = 0,
|
a = 0,
|
||||||
@ -44,58 +47,10 @@ var parseOptions = function(args,defaultSwitch) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var switches = parseOptions(Array.prototype.slice.call(process.argv,2),"dummy"),
|
var switches = parseOptions(Array.prototype.slice.call(process.argv,2),"dummy"),
|
||||||
store = new WikiStore(),
|
|
||||||
recipe = null,
|
recipe = null,
|
||||||
lastRecipeFilepath = null,
|
lastRecipeFilepath = null,
|
||||||
currSwitch = 0;
|
currSwitch = 0;
|
||||||
|
|
||||||
store.registerTextProcessor("text/x-tiddlywiki",new WikiTextProcessor({
|
|
||||||
store: store
|
|
||||||
}));
|
|
||||||
// Register the standard tiddler serializers and deserializers
|
|
||||||
tiddlerInput.register(store);
|
|
||||||
tiddlerOutput.register(store);
|
|
||||||
|
|
||||||
// Frightful temporary hack, but setup the sandbox for evaluated macro parameters
|
|
||||||
var Sandbox = require("./js/Sandbox.js").Sandbox;
|
|
||||||
store.sandbox = new Sandbox(fs.readFileSync("parsers/javascript.pegjs","utf8"));
|
|
||||||
|
|
||||||
store.installMacros();
|
|
||||||
|
|
||||||
// Add the shadow tiddlers that are built into TiddlyWiki
|
|
||||||
var shadowShadowStore = new WikiStore({
|
|
||||||
shadowStore: null
|
|
||||||
}),
|
|
||||||
shadowShadows = [
|
|
||||||
{title: "StyleSheet", text: ""},
|
|
||||||
{title: "MarkupPreHead", text: ""},
|
|
||||||
{title: "MarkupPostHead", text: ""},
|
|
||||||
{title: "MarkupPreBody", text: ""},
|
|
||||||
{title: "MarkupPostBody", text: ""},
|
|
||||||
{title: "TabTimeline", text: "<<timeline>>"},
|
|
||||||
{title: "TabAll", text: "<<list all>>"},
|
|
||||||
{title: "TabTags", text: "<<allTags excludeLists>>"},
|
|
||||||
{title: "TabMoreMissing", text: "<<list missing>>"},
|
|
||||||
{title: "TabMoreOrphans", text: "<<list orphans>>"},
|
|
||||||
{title: "TabMoreShadowed", text: "<<list shadowed>>"},
|
|
||||||
{title: "AdvancedOptions", text: "<<options>>"},
|
|
||||||
{title: "PluginManager", text: "<<plugins>>"},
|
|
||||||
{title: "SystemSettings", text: ""},
|
|
||||||
{title: "ToolbarCommands", text: "|~ViewToolbar|closeTiddler closeOthers +editTiddler > fields syncing permalink references jump|\n|~EditToolbar|+saveTiddler -cancelTiddler deleteTiddler|"},
|
|
||||||
{title: "WindowTitle", text: "<<tiddler SiteTitle>> - <<tiddler SiteSubtitle>>"},
|
|
||||||
{title: "DefaultTiddlers", text: "[[GettingStarted]]"},
|
|
||||||
{title: "MainMenu", text: "[[GettingStarted]]"},
|
|
||||||
{title: "SiteTitle", text: "My TiddlyWiki"},
|
|
||||||
{title: "SiteSubtitle", text: "a reusable non-linear personal web notebook"},
|
|
||||||
{title: "SiteUrl", text: ""},
|
|
||||||
{title: "SideBarOptions", text: '<<search>><<closeAll>><<permaview>><<newTiddler>><<newJournal "DD MMM YYYY" "journal">><<saveChanges>><<slider chkSliderOptionsPanel OptionsPanel "options \u00bb" "Change TiddlyWiki advanced options">>'},
|
|
||||||
{title: "SideBarTabs", text: '<<tabs txtMainTab "Timeline" "Timeline" TabTimeline "All" "All tiddlers" TabAll "Tags" "All tags" TabTags "More" "More lists" TabMore>>'},
|
|
||||||
{title: "TabMore", text: '<<tabs txtMoreTab "Missing" "Missing tiddlers" TabMoreMissing "Orphans" "Orphaned tiddlers" TabMoreOrphans "Shadowed" "Shadowed tiddlers" TabMoreShadowed>>'}
|
|
||||||
];
|
|
||||||
store.shadows.shadows = shadowShadowStore;
|
|
||||||
for(var t=0; t<shadowShadows.length; t++) {
|
|
||||||
shadowShadowStore.addTiddler(new Tiddler(shadowShadows[t]));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Each command line switch is represented by a function that takes a string array of arguments and a callback to
|
Each command line switch is represented by a function that takes a string array of arguments and a callback to
|
||||||
@ -112,7 +67,7 @@ var commandLineSwitches = {
|
|||||||
lastRecipeFilepath = args[0];
|
lastRecipeFilepath = args[0];
|
||||||
recipe = new Recipe({
|
recipe = new Recipe({
|
||||||
filepath: args[0],
|
filepath: args[0],
|
||||||
store: store
|
store: app.store
|
||||||
},function(err) {
|
},function(err) {
|
||||||
callback(err);
|
callback(err);
|
||||||
});
|
});
|
||||||
@ -122,7 +77,7 @@ var commandLineSwitches = {
|
|||||||
dumpstore: {
|
dumpstore: {
|
||||||
args: {min: 0, max: 0},
|
args: {min: 0, max: 0},
|
||||||
handler: function(args,callback) {
|
handler: function(args,callback) {
|
||||||
console.log("Store is:\n%s",util.inspect(store,false,10));
|
console.log("Store is:\n%s",util.inspect(app.store,false,10));
|
||||||
process.nextTick(function() {callback(null);});
|
process.nextTick(function() {callback(null);});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -145,7 +100,7 @@ var commandLineSwitches = {
|
|||||||
type = extname === ".html" ? "application/x-tiddlywiki" : extname;
|
type = extname === ".html" ? "application/x-tiddlywiki" : extname;
|
||||||
var tiddlers = tiddlerInput.parseTiddlerFile(data,type,fields);
|
var tiddlers = tiddlerInput.parseTiddlerFile(data,type,fields);
|
||||||
for(var t=0; t<tiddlers.length; t++) {
|
for(var t=0; t<tiddlers.length; t++) {
|
||||||
store.addTiddler(new Tiddler(tiddlers[t]));
|
app.store.addTiddler(new Tiddler(tiddlers[t]));
|
||||||
}
|
}
|
||||||
callback(null);
|
callback(null);
|
||||||
}
|
}
|
||||||
@ -173,7 +128,7 @@ var commandLineSwitches = {
|
|||||||
args: {min: 1, max: 1},
|
args: {min: 1, max: 1},
|
||||||
handler: function(args,callback) {
|
handler: function(args,callback) {
|
||||||
var recipe = [];
|
var recipe = [];
|
||||||
store.forEachTiddler(function(title,tiddler) {
|
app.store.forEachTiddler(function(title,tiddler) {
|
||||||
var filename = encodeURIComponent(tiddler.fields.title.replace(/ /g,"_")) + ".tid";
|
var filename = encodeURIComponent(tiddler.fields.title.replace(/ /g,"_")) + ".tid";
|
||||||
fs.writeFileSync(path.resolve(args[0],filename),tiddlerOutput.outputTiddler(tiddler),"utf8");
|
fs.writeFileSync(path.resolve(args[0],filename),tiddlerOutput.outputTiddler(tiddler),"utf8");
|
||||||
recipe.push("tiddler: " + filename + "\n");
|
recipe.push("tiddler: " + filename + "\n");
|
||||||
@ -192,8 +147,8 @@ var commandLineSwitches = {
|
|||||||
// Dumbly, this implementation wastes the recipe processing that happened on the --recipe switch
|
// Dumbly, this implementation wastes the recipe processing that happened on the --recipe switch
|
||||||
http.createServer(function(request, response) {
|
http.createServer(function(request, response) {
|
||||||
response.writeHead(200, {"Content-Type": "text/html"});
|
response.writeHead(200, {"Content-Type": "text/html"});
|
||||||
store = new WikiStore();
|
var store = new WikiStore();
|
||||||
recipe = new Recipe(store,lastRecipeFilepath,function() {
|
var recipe = new Recipe(store,lastRecipeFilepath,function() {
|
||||||
response.end(recipe.cook(), "utf8");
|
response.end(recipe.cook(), "utf8");
|
||||||
});
|
});
|
||||||
}).listen(port);
|
}).listen(port);
|
||||||
@ -205,10 +160,10 @@ var commandLineSwitches = {
|
|||||||
var port = args.length > 0 ? args[0] : 8000;
|
var port = args.length > 0 ? args[0] : 8000;
|
||||||
http.createServer(function (request, response) {
|
http.createServer(function (request, response) {
|
||||||
var title = decodeURIComponent(url.parse(request.url).pathname.substr(1)),
|
var title = decodeURIComponent(url.parse(request.url).pathname.substr(1)),
|
||||||
tiddler = store.getTiddler(title);
|
tiddler = app.store.getTiddler(title);
|
||||||
if(tiddler) {
|
if(tiddler) {
|
||||||
response.writeHead(200, {"Content-Type": "text/html"});
|
response.writeHead(200, {"Content-Type": "text/html"});
|
||||||
response.end(store.renderTiddler("text/html",title),"utf8");
|
response.end(app.store.renderTiddler("text/html",title),"utf8");
|
||||||
} else {
|
} else {
|
||||||
response.writeHead(404);
|
response.writeHead(404);
|
||||||
response.end();
|
response.end();
|
||||||
|
25
wikitest.js
25
wikitest.js
@ -14,7 +14,8 @@ verifying that the output matches `<tiddlername>.html` and `<tiddlername>.txt`.
|
|||||||
/*jslint node: true */
|
/*jslint node: true */
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var Tiddler = require("./js/Tiddler.js").Tiddler,
|
var App = require("./js/App.js").App,
|
||||||
|
Tiddler = require("./js/Tiddler.js").Tiddler,
|
||||||
WikiStore = require("./js/WikiStore.js").WikiStore,
|
WikiStore = require("./js/WikiStore.js").WikiStore,
|
||||||
WikiTextProcessor = require("./js/WikiTextProcessor.js").WikiTextProcessor,
|
WikiTextProcessor = require("./js/WikiTextProcessor.js").WikiTextProcessor,
|
||||||
tiddlerInput = require("./js/TiddlerInput.js"),
|
tiddlerInput = require("./js/TiddlerInput.js"),
|
||||||
@ -23,29 +24,21 @@ var Tiddler = require("./js/Tiddler.js").Tiddler,
|
|||||||
fs = require("fs"),
|
fs = require("fs"),
|
||||||
path = require("path");
|
path = require("path");
|
||||||
|
|
||||||
|
var app = new App();
|
||||||
|
|
||||||
var testdirectory = process.argv[2],
|
var testdirectory = process.argv[2],
|
||||||
store = new WikiStore(),
|
|
||||||
files = fs.readdirSync(testdirectory),
|
files = fs.readdirSync(testdirectory),
|
||||||
titles = [],
|
titles = [],
|
||||||
f,t,extname,basename;
|
f,t,extname,basename;
|
||||||
|
|
||||||
store.registerTextProcessor("text/x-tiddlywiki",new WikiTextProcessor({
|
|
||||||
store: store
|
|
||||||
}));
|
|
||||||
tiddlerInput.register(store);
|
|
||||||
|
|
||||||
// Frightful temporary hack, but setup the sandbox for evaluated macro parameters
|
|
||||||
var Sandbox = require("./js/Sandbox.js").Sandbox;
|
|
||||||
store.sandbox = new Sandbox(fs.readFileSync("parsers/javascript.pegjs","utf8"));
|
|
||||||
|
|
||||||
for(f=0; f<files.length; f++) {
|
for(f=0; f<files.length; f++) {
|
||||||
extname = path.extname(files[f]);
|
extname = path.extname(files[f]);
|
||||||
if(extname === ".tid") {
|
if(extname === ".tid") {
|
||||||
var tiddlers = store.deserializeTiddlers(extname,fs.readFileSync(path.resolve(testdirectory,files[f]),"utf8"));
|
var tiddlers = app.store.deserializeTiddlers(extname,fs.readFileSync(path.resolve(testdirectory,files[f]),"utf8"));
|
||||||
if(tiddlers.length > 1) {
|
if(tiddlers.length > 1) {
|
||||||
throw "Cannot use .JSON files";
|
throw "Cannot use .JSON files";
|
||||||
}
|
}
|
||||||
store.addTiddler(new Tiddler(tiddlers[0]));
|
app.store.addTiddler(new Tiddler(tiddlers[0]));
|
||||||
titles.push(tiddlers[0].title);
|
titles.push(tiddlers[0].title);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -53,9 +46,9 @@ for(f=0; f<files.length; f++) {
|
|||||||
for(t=0; t<titles.length; t++) {
|
for(t=0; t<titles.length; t++) {
|
||||||
var htmlTarget = fs.readFileSync(path.resolve(testdirectory,titles[t] + ".html"),"utf8"),
|
var htmlTarget = fs.readFileSync(path.resolve(testdirectory,titles[t] + ".html"),"utf8"),
|
||||||
plainTarget = fs.readFileSync(path.resolve(testdirectory,titles[t] + ".txt"),"utf8"),
|
plainTarget = fs.readFileSync(path.resolve(testdirectory,titles[t] + ".txt"),"utf8"),
|
||||||
tiddler = store.getTiddler(titles[t]),
|
tiddler = app.store.getTiddler(titles[t]),
|
||||||
htmlRender = store.renderTiddler("text/html",titles[t]),
|
htmlRender = app.store.renderTiddler("text/html",titles[t]),
|
||||||
plainRender = store.renderTiddler("text/plain",titles[t]);
|
plainRender = app.store.renderTiddler("text/plain",titles[t]);
|
||||||
if(htmlTarget !== htmlRender) {
|
if(htmlTarget !== htmlRender) {
|
||||||
console.error("Tiddler %s html error\nTarget: %s\nFound: %s\n",titles[t],htmlTarget,htmlRender);
|
console.error("Tiddler %s html error\nTarget: %s\nFound: %s\n",titles[t],htmlTarget,htmlRender);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user