mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-12-27 18:40:28 +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: "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: "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;
|
||||
for(t=0; t<shadowShadows.length; t++) {
|
||||
|
@ -2,6 +2,6 @@ title: SeventhTiddler
|
||||
|
||||
<<echo {{2+2}}>>
|
||||
|
||||
<<echo {{title}}>>
|
||||
<<echo {{"title"}}>>
|
||||
|
||||
<<echo {{window}}>>
|
||||
<<echo {{"window"}}>>
|
||||
|
@ -7,7 +7,8 @@ TiddlyWiki command line interface
|
||||
/*jslint node: true */
|
||||
"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,
|
||||
Recipe = require("./js/Recipe.js").Recipe,
|
||||
tiddlerInput = require("./js/TiddlerInput.js"),
|
||||
@ -20,6 +21,8 @@ var WikiStore = require("./js/WikiStore.js").WikiStore,
|
||||
aync = require("async"),
|
||||
http = require("http");
|
||||
|
||||
var app = new App();
|
||||
|
||||
var parseOptions = function(args,defaultSwitch) {
|
||||
var result = [],
|
||||
a = 0,
|
||||
@ -44,58 +47,10 @@ var parseOptions = function(args,defaultSwitch) {
|
||||
};
|
||||
|
||||
var switches = parseOptions(Array.prototype.slice.call(process.argv,2),"dummy"),
|
||||
store = new WikiStore(),
|
||||
recipe = null,
|
||||
lastRecipeFilepath = null,
|
||||
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
|
||||
@ -112,7 +67,7 @@ var commandLineSwitches = {
|
||||
lastRecipeFilepath = args[0];
|
||||
recipe = new Recipe({
|
||||
filepath: args[0],
|
||||
store: store
|
||||
store: app.store
|
||||
},function(err) {
|
||||
callback(err);
|
||||
});
|
||||
@ -122,7 +77,7 @@ var commandLineSwitches = {
|
||||
dumpstore: {
|
||||
args: {min: 0, max: 0},
|
||||
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);});
|
||||
}
|
||||
},
|
||||
@ -145,7 +100,7 @@ var commandLineSwitches = {
|
||||
type = extname === ".html" ? "application/x-tiddlywiki" : extname;
|
||||
var tiddlers = tiddlerInput.parseTiddlerFile(data,type,fields);
|
||||
for(var t=0; t<tiddlers.length; t++) {
|
||||
store.addTiddler(new Tiddler(tiddlers[t]));
|
||||
app.store.addTiddler(new Tiddler(tiddlers[t]));
|
||||
}
|
||||
callback(null);
|
||||
}
|
||||
@ -173,7 +128,7 @@ var commandLineSwitches = {
|
||||
args: {min: 1, max: 1},
|
||||
handler: function(args,callback) {
|
||||
var recipe = [];
|
||||
store.forEachTiddler(function(title,tiddler) {
|
||||
app.store.forEachTiddler(function(title,tiddler) {
|
||||
var filename = encodeURIComponent(tiddler.fields.title.replace(/ /g,"_")) + ".tid";
|
||||
fs.writeFileSync(path.resolve(args[0],filename),tiddlerOutput.outputTiddler(tiddler),"utf8");
|
||||
recipe.push("tiddler: " + filename + "\n");
|
||||
@ -192,8 +147,8 @@ var commandLineSwitches = {
|
||||
// Dumbly, this implementation wastes the recipe processing that happened on the --recipe switch
|
||||
http.createServer(function(request, response) {
|
||||
response.writeHead(200, {"Content-Type": "text/html"});
|
||||
store = new WikiStore();
|
||||
recipe = new Recipe(store,lastRecipeFilepath,function() {
|
||||
var store = new WikiStore();
|
||||
var recipe = new Recipe(store,lastRecipeFilepath,function() {
|
||||
response.end(recipe.cook(), "utf8");
|
||||
});
|
||||
}).listen(port);
|
||||
@ -205,10 +160,10 @@ var commandLineSwitches = {
|
||||
var port = args.length > 0 ? args[0] : 8000;
|
||||
http.createServer(function (request, response) {
|
||||
var title = decodeURIComponent(url.parse(request.url).pathname.substr(1)),
|
||||
tiddler = store.getTiddler(title);
|
||||
tiddler = app.store.getTiddler(title);
|
||||
if(tiddler) {
|
||||
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 {
|
||||
response.writeHead(404);
|
||||
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 */
|
||||
"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,
|
||||
WikiTextProcessor = require("./js/WikiTextProcessor.js").WikiTextProcessor,
|
||||
tiddlerInput = require("./js/TiddlerInput.js"),
|
||||
@ -23,29 +24,21 @@ var Tiddler = require("./js/Tiddler.js").Tiddler,
|
||||
fs = require("fs"),
|
||||
path = require("path");
|
||||
|
||||
var app = new App();
|
||||
|
||||
var testdirectory = process.argv[2],
|
||||
store = new WikiStore(),
|
||||
files = fs.readdirSync(testdirectory),
|
||||
titles = [],
|
||||
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++) {
|
||||
extname = path.extname(files[f]);
|
||||
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) {
|
||||
throw "Cannot use .JSON files";
|
||||
}
|
||||
store.addTiddler(new Tiddler(tiddlers[0]));
|
||||
app.store.addTiddler(new Tiddler(tiddlers[0]));
|
||||
titles.push(tiddlers[0].title);
|
||||
}
|
||||
}
|
||||
@ -53,9 +46,9 @@ for(f=0; f<files.length; f++) {
|
||||
for(t=0; t<titles.length; t++) {
|
||||
var htmlTarget = fs.readFileSync(path.resolve(testdirectory,titles[t] + ".html"),"utf8"),
|
||||
plainTarget = fs.readFileSync(path.resolve(testdirectory,titles[t] + ".txt"),"utf8"),
|
||||
tiddler = store.getTiddler(titles[t]),
|
||||
htmlRender = store.renderTiddler("text/html",titles[t]),
|
||||
plainRender = store.renderTiddler("text/plain",titles[t]);
|
||||
tiddler = app.store.getTiddler(titles[t]),
|
||||
htmlRender = app.store.renderTiddler("text/html",titles[t]),
|
||||
plainRender = app.store.renderTiddler("text/plain",titles[t]);
|
||||
if(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