From e02a484591267bf7f5c6314b428d492dd5c36864 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Wed, 28 Dec 2011 17:16:56 +0000 Subject: [PATCH] Removed TextProcessors() and TiddlerConverters() classes --- js/Main.js | 34 ++++------------- js/Recipe.js | 12 +++--- js/TextProcessors.js | 34 ----------------- js/TiddlerConverters.js | 54 --------------------------- js/TiddlerInput.js | 16 ++++---- js/TiddlerOutput.js | 6 +-- js/WikiStore.js | 68 +++++++++++++++++++++++++++++++--- js/WikiTextProcessor.js | 1 - js/WikiTextRenderer.js | 10 ++--- tiddlywiki.js | 28 ++++---------- tiddlywiki5/tiddlywiki5.recipe | 2 - wikitest.js | 16 +++----- 12 files changed, 103 insertions(+), 178 deletions(-) delete mode 100644 js/TextProcessors.js delete mode 100644 js/TiddlerConverters.js diff --git a/js/Main.js b/js/Main.js index 95f003b3f..6a9e8a7d7 100644 --- a/js/Main.js +++ b/js/Main.js @@ -13,31 +13,24 @@ var WikiStore = require("./WikiStore.js").WikiStore, Tiddler = require("./Tiddler.js").Tiddler, tiddlerInput = require("./TiddlerInput.js"), tiddlerOutput = require("./TiddlerOutput.js"), - TextProcessors = require("./TextProcessors.js").TextProcessors, WikiTextProcessor = require("./WikiTextProcessor.js").WikiTextProcessor, - TiddlerConverters = require("./TiddlerConverters.js").TiddlerConverters, Navigators = require("./Navigators.js").Navigators, StoryNavigator = require("./StoryNavigator.js").StoryNavigator; -var textProcessors = new TextProcessors(), - tiddlerConverters = new TiddlerConverters(), - store = new WikiStore({ - textProcessors: textProcessors - }), +var store = new WikiStore(), t; // Register the wikitext processor -textProcessors.registerTextProcessor("text/x-tiddlywiki",new WikiTextProcessor({ - textProcessors: textProcessors +store.registerTextProcessor("text/x-tiddlywiki",new WikiTextProcessor({ + store: store })); // Register the standard tiddler serializers and deserializers -tiddlerInput.register(tiddlerConverters); -tiddlerOutput.register(tiddlerConverters); +tiddlerInput.register(store); +tiddlerOutput.register(store); // Add the shadow tiddlers that are built into TiddlyWiki var shadowShadowStore = new WikiStore({ - textProcessors: textProcessors, shadowStore: null }), shadowShadows = [ @@ -46,25 +39,12 @@ var shadowShadowStore = new WikiStore({ {title: "MarkupPostHead", text: ""}, {title: "MarkupPreBody", text: ""}, {title: "MarkupPostBody", text: ""}, - {title: "TabTimeline", text: "<>"}, - {title: "TabAll", text: "<>"}, - {title: "TabTags", text: "<>"}, - {title: "TabMoreMissing", text: "<>"}, - {title: "TabMoreOrphans", text: "<>"}, - {title: "TabMoreShadowed", text: "<>"}, - {title: "AdvancedOptions", text: "<>"}, - {title: "PluginManager", text: "<>"}, - {title: "SystemSettings", text: ""}, - {title: "ToolbarCommands", text: "|~ViewToolbar|closeTiddler closeOthers +editTiddler > fields syncing permalink references jump|\n|~EditToolbar|+saveTiddler -cancelTiddler deleteTiddler|"}, {title: "WindowTitle", text: "<> - <>"}, {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: '<><><><><><><>'}, - {title: "SideBarTabs", text: '<>'}, - {title: "TabMore", text: '<>'} + {title: "SiteUrl", text: ""} ]; store.shadows.shadows = shadowShadowStore; for(t=0; t 0) { - fields = this.tiddlerConverters.deserialize("application/x-tiddler",fieldLines.join("\n"),{})[0]; + fields = this.store.deserializeTiddlers("application/x-tiddler",fieldLines.join("\n"),{})[0]; } recipe.push({marker: match.marker, filepath: match.value, contextPath: contextPath, fields: fields}); } @@ -192,7 +190,7 @@ Recipe.prototype.readTiddlerFile = function(filepath,contextPath,callback) { var fields = { title: data.path }; - var tiddlers = me.tiddlerConverters.deserialize(data.extname,data.text,fields); + var tiddlers = me.store.deserializeTiddlers(data.extname,data.text,fields); // Check for the .meta file if(data.extname !== ".json" && tiddlers.length === 1) { var metafile = filepath + ".meta"; @@ -204,7 +202,7 @@ Recipe.prototype.readTiddlerFile = function(filepath,contextPath,callback) { if(!err) { var text = data.text.split("\n\n")[0]; if(text) { - fields = me.tiddlerConverters.deserialize("application/x-tiddler",text,fields)[0]; + fields = me.store.deserializeTiddlers("application/x-tiddler",text,fields)[0]; } } callback(null,[fields]); @@ -272,7 +270,7 @@ Recipe.tiddlerOutputter = { // Ordinary tiddlers are output as a
for(var t=0; t=last; t--) { var tiddler = tiddlers[t], - theGroupParseTree = this.parser.processor.textProcessors.parse(groupTemplateType,groupTemplateText), + theGroupParseTree = this.store.parseText(groupTemplateType,groupTemplateText), theGroup = theGroupParseTree.render("text/plain",theGroupParseTree.children,this.store,tiddler); if(theGroup !== "") { if(ul === undefined || theGroup !== lastGroup) { @@ -226,7 +226,7 @@ WikiTextRenderer.macros = { children: [] }]}; ul.children.push(item); - item.children[0].children = this.parser.processor.textProcessors.parse(templateType,templateText).children; + item.children[0].children = this.store.parseText(templateType,templateText).children; } } this.executeMacros(macroNode.output,title); @@ -260,7 +260,7 @@ WikiTextRenderer.macros = { children: [] } ] }; - li.children[0].children = this.parser.processor.textProcessors.parse(templateType,templateText).children; + li.children[0].children = this.store.parseText(templateType,templateText).children; ul.children.push(li); } if(ul.children.length > 0) { @@ -325,7 +325,7 @@ WikiTextRenderer.macros = { var placeholderRegExp = new RegExp("\\$"+(t+1),"mg"); text = text.replace(placeholderRegExp,withTokens[t]); } - macroNode.output = this.parser.processor.textProcessors.parse(tiddler.fields.type,text).children; + macroNode.output = this.store.parseText(tiddler.fields.type,text).children; // Execute any macros in the copy this.executeMacros(macroNode.output,title); } @@ -367,7 +367,7 @@ WikiTextRenderer.macros = { }); break; case "wikified": - macroNode.output = this.parser.processor.textProcessors.parse("text/x-tiddlywiki",value).children; + macroNode.output = this.store.parseText("text/x-tiddlywiki",value).children; // Execute any macros in the copy this.executeMacros(macroNode.output,title); break; diff --git a/tiddlywiki.js b/tiddlywiki.js index 6ae8e90ef..ee58ca5f1 100644 --- a/tiddlywiki.js +++ b/tiddlywiki.js @@ -12,9 +12,7 @@ var WikiStore = require("./js/WikiStore.js").WikiStore, Recipe = require("./js/Recipe.js").Recipe, tiddlerInput = require("./js/TiddlerInput.js"), tiddlerOutput = require("./js/TiddlerOutput.js"), - TextProcessors = require("./js/TextProcessors.js").TextProcessors, WikiTextProcessor = require("./js/WikiTextProcessor.js").WikiTextProcessor, - TiddlerConverters = require("./js/TiddlerConverters.js").TiddlerConverters, util = require("util"), fs = require("fs"), url = require("url"), @@ -45,27 +43,21 @@ var parseOptions = function(args,defaultSwitch) { return result; }; -var textProcessors = new TextProcessors(), - tiddlerConverters = new TiddlerConverters(), - switches = parseOptions(Array.prototype.slice.call(process.argv,2),"dummy"), - store = new WikiStore({ - textProcessors: textProcessors - }), +var switches = parseOptions(Array.prototype.slice.call(process.argv,2),"dummy"), + store = new WikiStore(), recipe = null, lastRecipeFilepath = null, currSwitch = 0; - -textProcessors.registerTextProcessor("text/x-tiddlywiki",new WikiTextProcessor({ - textProcessors: textProcessors +store.registerTextProcessor("text/x-tiddlywiki",new WikiTextProcessor({ + store: store })); // Register the standard tiddler serializers and deserializers -tiddlerInput.register(tiddlerConverters); -tiddlerOutput.register(tiddlerConverters); +tiddlerInput.register(store); +tiddlerOutput.register(store); // Add the shadow tiddlers that are built into TiddlyWiki var shadowShadowStore = new WikiStore({ - textProcessors: textProcessors, shadowStore: null }), shadowShadows = [ @@ -114,9 +106,7 @@ var commandLineSwitches = { lastRecipeFilepath = args[0]; recipe = new Recipe({ filepath: args[0], - store: store, - tiddlerConverters: tiddlerConverters, - textProcessors: textProcessors + store: store },function() { callback(null); }); @@ -196,9 +186,7 @@ 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({ - textProcessors: textProcessors - }); + store = new WikiStore(); recipe = new Recipe(store,lastRecipeFilepath,function() { response.end(recipe.cook(), "utf8"); }); diff --git a/tiddlywiki5/tiddlywiki5.recipe b/tiddlywiki5/tiddlywiki5.recipe index c75f38d15..d9da3d54b 100644 --- a/tiddlywiki5/tiddlywiki5.recipe +++ b/tiddlywiki5/tiddlywiki5.recipe @@ -11,11 +11,9 @@ jsmodule: ../js/ArgParser.js jsmodule: ../js/FileRetriever.js jsmodule: ../js/Utils.js jsmodule: ../js/Tiddler.js -jsmodule: ../js/TiddlerConverters.js jsmodule: ../js/TiddlerInput.js jsmodule: ../js/TiddlerOutput.js jsmodule: ../js/WikiStore.js -jsmodule: ../js/TextProcessors.js jsmodule: ../js/WikiTextProcessor.js jsmodule: ../js/WikiTextParser.js jsmodule: ../js/WikiTextRules.js diff --git a/wikitest.js b/wikitest.js index b472d0d68..85a623129 100644 --- a/wikitest.js +++ b/wikitest.js @@ -16,9 +16,7 @@ verifying that the output matches `.html` and `.txt`. var Tiddler = require("./js/Tiddler.js").Tiddler, WikiStore = require("./js/WikiStore.js").WikiStore, - TextProcessors = require("./js/TextProcessors.js").TextProcessors, WikiTextProcessor = require("./js/WikiTextProcessor.js").WikiTextProcessor, - TiddlerConverters = require("./js/TiddlerConverters.js").TiddlerConverters, tiddlerInput = require("./js/TiddlerInput.js"), utils = require("./js/Utils.js"), util = require("util"), @@ -26,24 +24,20 @@ var Tiddler = require("./js/Tiddler.js").Tiddler, path = require("path"); var testdirectory = process.argv[2], - textProcessors = new TextProcessors(), - tiddlerConverters = new TiddlerConverters(), - store = new WikiStore({ - textProcessors: textProcessors - }), + store = new WikiStore(), files = fs.readdirSync(testdirectory), titles = [], f,t,extname,basename; -textProcessors.registerTextProcessor("text/x-tiddlywiki",new WikiTextProcessor({ - textProcessors: textProcessors +store.registerTextProcessor("text/x-tiddlywiki",new WikiTextProcessor({ + store: store })); -tiddlerInput.register(tiddlerConverters); +tiddlerInput.register(store); for(f=0; f 1) { throw "Cannot use .JSON files"; }