From 0823beb85da8a91f3db724e8aaff3dd16d2d7dba Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Fri, 16 Dec 2011 10:48:36 +0000 Subject: [PATCH] Added template support to list macro --- js/WikiStore.js | 8 ++- js/WikiTextParser.js | 17 ------ js/WikiTextRenderer.js | 88 +++++++++++++++++------------ tiddlywiki5/tiddlers/HelloThere.tid | 2 - 4 files changed, 58 insertions(+), 57 deletions(-) diff --git a/js/WikiStore.js b/js/WikiStore.js index ab298b695..c4927e505 100755 --- a/js/WikiStore.js +++ b/js/WikiStore.js @@ -44,7 +44,13 @@ WikiStore.prototype.deleteTiddler = function(title) { }; WikiStore.prototype.tiddlerExists = function(title) { - return this.tiddlers[title] instanceof Tiddler; + var exists = this.tiddlers[title] instanceof Tiddler; + if(exists) { + return true; + } else if (this.shadows) { + return this.shadows.tiddlerExists(title); + } + return ; }; WikiStore.prototype.addTiddler = function(tiddler) { diff --git a/js/WikiTextParser.js b/js/WikiTextParser.js index 9640c041e..21039a6ef 100644 --- a/js/WikiTextParser.js +++ b/js/WikiTextParser.js @@ -3,23 +3,6 @@ title: js/WikiTextParser.js Parses a block of tiddlywiki-format wiki text into a parse tree object. -HTML elements are stored in the tree like this: - - {type: "div", attributes: { - attr1: value, - style: { - name: value, - name2: value2 - } - }, children: [ - {child}, - {child}, - ]} - -Text nodes are: - - {type: "text", value: "string of text node"} - \*/ (function(){ diff --git a/js/WikiTextRenderer.js b/js/WikiTextRenderer.js index 14b6b1bc3..111325776 100644 --- a/js/WikiTextRenderer.js +++ b/js/WikiTextRenderer.js @@ -66,6 +66,9 @@ WikiTextRenderer.prototype.renderAsHtml = function(treenode) { case "img": renderElement(tree[t],true); // Self closing elements break; + case "context": + renderSubTree(tree[t].children); + break; case "macro": renderSubTree(tree[t].output); break; @@ -75,7 +78,7 @@ WikiTextRenderer.prototype.renderAsHtml = function(treenode) { } } }; - this.executeMacros(treenode); + this.executeMacros(treenode,this.title); renderSubTree(treenode); return output.join(""); }; @@ -105,27 +108,28 @@ WikiTextRenderer.prototype.renderAsText = function(treenode) { } } }; - this.executeMacros(treenode); + this.executeMacros(treenode,this.title); renderSubTree(treenode); return output.join(""); }; -WikiTextRenderer.prototype.executeMacros = function(tree) { +WikiTextRenderer.prototype.executeMacros = function(tree,title) { for(var t=0; t>"; - // Get the tiddlers + // Get the template to use + template = template ? this.store.getTiddler(template) : null; + if(template) { + templateType = template.fields.type; + templateText = template.fields.text; + } + // Get the handler and the tiddlers var handler = WikiTextRenderer.macros.list.types[type]; handler = handler || WikiTextRenderer.macros.list.types.all; var tiddlers = handler.call(this); // Render them as a list var ul = {type: "ul", children: []}; for(var t=0; t 0) { + macroNode.output.push(ul); + this.executeMacros(macroNode.output,title); + } else if (emptyMessage) { + macroNode.output.push({type: "text", value: emptyMessage}); + } }, types: { all: function() { @@ -198,27 +212,27 @@ WikiTextRenderer.macros = { } }, slider: { - handler: function(macroNode) { + handler: function(macroNode,title) { } }, tabs: { - handler: function(macroNode) { + handler: function(macroNode,title) { } }, tag: { - handler: function(macroNode) { + handler: function(macroNode,title) { } }, tagging: { - handler: function(macroNode) { + handler: function(macroNode,title) { } }, tags: { - handler: function(macroNode) { + handler: function(macroNode,title) { } }, tiddler: { - handler: function(macroNode) { + handler: function(macroNode,title) { var args = new ArgParser(macroNode.params,{defaultName:"name",cascadeDefaults:true}), targetTitle = args.getValueByName("name",null), withTokens = args.getValuesByName("with",[]), @@ -234,15 +248,15 @@ WikiTextRenderer.macros = { macroNode.output.push(parseTree.children[t]); } // Execute any macros in the copy - this.executeMacros(macroNode.output); + this.executeMacros(macroNode.output,title); } }, timeline: { - handler: function(macroNode) { + handler: function(macroNode,title) { } }, today: { - handler: function(macroNode) { + handler: function(macroNode,title) { var now = new Date(), args = new ArgParser(macroNode.params,{noNames:true}), value = args.byPos[0] ? utils.formatDateString(now,args.byPos[0].v) : now.toLocaleString(); @@ -250,16 +264,16 @@ WikiTextRenderer.macros = { } }, version: { - handler: function(macroNode) { + handler: function(macroNode,title) { macroNode.output.push({type: "text", value: WikiTextRenderer.versionTiddlyWiki}); } }, view: { - handler: function(macroNode) { + handler: function(macroNode,title) { var args = new ArgParser(macroNode.params,{noNames:true}), field = args.byPos[0] ? args.byPos[0].v : null, format = args.byPos[1] ? args.byPos[1].v : "text", - tiddler = this.store.getTiddler(this.title), + tiddler = this.store.getTiddler(title), value = tiddler ? tiddler.fields[field] : null; if(tiddler && field && value) { switch(format) { @@ -283,7 +297,7 @@ WikiTextRenderer.macros = { macroNode.output.push(parseTree.children[t]); } // Execute any macros in the copy - this.executeMacros(macroNode.output); + this.executeMacros(macroNode.output,title); break; case "date": var template = args.byPos[2] ? args.byPos[2].v : "DD MMM YYYY"; diff --git a/tiddlywiki5/tiddlers/HelloThere.tid b/tiddlywiki5/tiddlers/HelloThere.tid index 9c3784d71..8b1ec1b1f 100644 --- a/tiddlywiki5/tiddlers/HelloThere.tid +++ b/tiddlywiki5/tiddlers/HelloThere.tid @@ -8,5 +8,3 @@ TiddlyWiki is a unique [[wiki|WikiWikiWeb]] that people [[love using|Raves]] to TiddlyWiki is written in [[HTML]], [[CSS]] and JavaScript to run on any reasonably modern [[browser|Browsers]] without needing any ServerSide logic. It allows anyone to create personal SelfContained hypertext documents that can be published to a WebServer, sent by email, stored in a DropBox or kept on a USB thumb drive to make a WikiOnAStick. Because it doesn't need to be installed and configured it makes a great GuerillaWiki. This is revision <> of TiddlyWiki, and is published under an OpenSourceLicense. Unlike most wikis, TiddlyWiki doesn't directly support group collaboration; it is a wiki in the sense of elevating linking be a part of the punctuation of writing. You can easily publish a TiddlyWiki you have created by placing the single file on a web server (for instance the homepage hosting provided by many ISPs). If you need full group collaboration features, there are several HostedOptions to choose from. - -<>