mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2026-11-17 04:14:27 +00:00
Revert "Passed "store" to the other parser constructors"
This reverts commit 017be8f4ff.
This commit is contained in:
1 parent
017be8f4ff
commit
c100b434f9
7 files changed
+68
-58
No files matched your search
@@ -26,8 +26,8 @@ var App = function() {
|
||||
this.store = new WikiStore();
|
||||
// Register the parsers
|
||||
this.store.registerParser("text/x-tiddlywiki",new WikiTextParser({store: this.store}));
|
||||
this.store.registerParser("application/json",new JSONParser({store: this.store}));
|
||||
var imageParser = new ImageParser({store: this.store});
|
||||
this.store.registerParser("application/json",new JSONParser());
|
||||
var imageParser = new ImageParser();
|
||||
this.store.registerParser("image/svg+xml",imageParser);
|
||||
this.store.registerParser("image/jpg",imageParser);
|
||||
this.store.registerParser("image/jpeg",imageParser);
|
||||
|
||||
+1
-12
@@ -42,7 +42,7 @@ var utils = require("./Utils.js");
|
||||
Constructs an HTMLParseTree from a tree of nodes. A single node or an array of nodes can be passed.
|
||||
|
||||
As a shortcut, the constructor can be called as an ordinary function without the new keyword, in which case
|
||||
it by default returns the `text/html` rendering of the tree.
|
||||
it automatically returns the `text/html` rendering of the tree.
|
||||
*/
|
||||
var HTML = function(tree,type) {
|
||||
if(this instanceof HTML) {
|
||||
@@ -110,17 +110,6 @@ HTML.macro = function(name,params,children,dependencies) {
|
||||
return m;
|
||||
};
|
||||
|
||||
/*
|
||||
Static method to construct a label
|
||||
*/
|
||||
HTML.label = function(type,value,classes) {
|
||||
classes = (classes || []).slice(0);
|
||||
classes.push("label");
|
||||
return HTML.elem("span",{
|
||||
"class": classes
|
||||
},value);
|
||||
};
|
||||
|
||||
/*
|
||||
Static method to construct a split label
|
||||
*/
|
||||
|
||||
+31
-12
@@ -9,22 +9,41 @@ Compiles images into JavaScript functions that render them in HTML
|
||||
/*jslint node: true */
|
||||
"use strict";
|
||||
|
||||
var WikiTextParseTree = require("./WikiTextParseTree.js").WikiTextParseTree,
|
||||
HTML = require("./HTML.js").HTML,
|
||||
utils = require("./Utils.js");
|
||||
var utils = require("./Utils.js");
|
||||
|
||||
var ImageParser = function(options) {
|
||||
this.store = options.store;
|
||||
var ImageRenderer = function(handlerCode) {
|
||||
/*jslint evil: true */
|
||||
this.handler = eval(handlerCode);
|
||||
};
|
||||
|
||||
ImageRenderer.prototype.render = function(tiddler,store) {
|
||||
return this.handler(tiddler,store,utils);
|
||||
};
|
||||
|
||||
// The parse tree is degenerate
|
||||
var ImageParseTree = function(type,text) {
|
||||
this.type = type;
|
||||
this.text = text;
|
||||
this.dependencies = {};
|
||||
};
|
||||
|
||||
ImageParseTree.prototype.compile = function(type) {
|
||||
if(type === "text/html") {
|
||||
if(this.type === "image/svg+xml") {
|
||||
return new ImageRenderer("(function (tiddler,store,utils) {return '<img src=\"data:" + this.type + "," + utils.stringify(encodeURIComponent(this.text)) + "\">';})");
|
||||
} else {
|
||||
return new ImageRenderer("(function (tiddler,store,utils) {return '<img src=\"data:" + this.type + ";base64," + this.text + "\">';})");
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
var ImageParser = function() {
|
||||
};
|
||||
|
||||
ImageParser.prototype.parse = function(type,text) {
|
||||
var src;
|
||||
if(this.type === "image/svg+xml") {
|
||||
src = "data:" + type + "," + encodeURIComponent(text);
|
||||
} else {
|
||||
src = "data:" + type + ";base64," + text;
|
||||
}
|
||||
return new WikiTextParseTree([HTML.elem("img",{src: src})],{},this.store);
|
||||
return new ImageParseTree(type,text);
|
||||
};
|
||||
|
||||
exports.ImageParser = ImageParser;
|
||||
|
||||
+33
-29
@@ -9,43 +9,47 @@ Compiles JSON objects into JavaScript functions that render them in HTML and pla
|
||||
/*jslint node: true */
|
||||
"use strict";
|
||||
|
||||
var WikiTextParseTree = require("./WikiTextParseTree.js").WikiTextParseTree,
|
||||
HTML = require("./HTML.js").HTML,
|
||||
utils = require("./Utils.js");
|
||||
var utils = require("./Utils.js");
|
||||
|
||||
var renderObject = function(obj) {
|
||||
var children = [],t;
|
||||
if(obj instanceof Array) {
|
||||
for(t=0; t<obj.length; t++) {
|
||||
children.push(HTML.elem("li",{
|
||||
"class": ["jsonArrayMember"]
|
||||
},[renderObject(obj[t])]));
|
||||
}
|
||||
return HTML.elem("ul",{
|
||||
"class": ["jsonArray"]
|
||||
},children);
|
||||
} else if(typeof obj === "object") {
|
||||
for(t in obj) {
|
||||
children.push(HTML.elem("li",{
|
||||
"class": ["jsonObjectMember"]
|
||||
},[HTML.splitLabel("JSON",[HTML.text(t)],[renderObject(obj[t])])]));
|
||||
}
|
||||
return HTML.elem("ul",{
|
||||
"class": ["jsonObject"]
|
||||
},children);
|
||||
} else {
|
||||
return HTML.label("JSON" + (typeof obj),[HTML.text(JSON.stringify(obj))],["jsonValue"]);
|
||||
}
|
||||
var JSONRenderer = function(handlerCode) {
|
||||
/*jslint evil: true */
|
||||
this.handler = eval(handlerCode);
|
||||
};
|
||||
|
||||
var JSONParser = function(options) {
|
||||
this.store = options.store;
|
||||
JSONRenderer.prototype.render = function(tiddler,store) {
|
||||
return this.handler(tiddler,store,utils);
|
||||
};
|
||||
|
||||
JSONRenderer.prototype.toString = function(type) {
|
||||
var output = [];
|
||||
utils.renderObject(output,type,this.handler.toString(),[]);
|
||||
return output.join("");
|
||||
};
|
||||
|
||||
// The parse tree is degenerate
|
||||
var JSONParseTree = function(tree) {
|
||||
this.tree = tree;
|
||||
this.dependencies = {};
|
||||
};
|
||||
|
||||
JSONParseTree.prototype.compile = function(type) {
|
||||
return new JSONRenderer("(function (tiddler,store,utils) {var output=[]; utils.renderObject(output,'" + type + "'," + JSON.stringify(this.tree) + ",[]);return output.join('');})");
|
||||
};
|
||||
|
||||
JSONParseTree.prototype.toString = function(type) {
|
||||
var output = [];
|
||||
utils.renderObject(output,type,this.tree,[]);
|
||||
return output.join("");
|
||||
};
|
||||
|
||||
var JSONParser = function() {
|
||||
};
|
||||
|
||||
JSONParser.prototype.parse = function(type,text) {
|
||||
return new WikiTextParseTree([renderObject(JSON.parse(text))],{},this.store);
|
||||
return new JSONParseTree(JSON.parse(text));
|
||||
};
|
||||
|
||||
|
||||
exports.JSONParser = JSONParser;
|
||||
|
||||
})();
|
||||
@@ -33,7 +33,6 @@ exports.macro = {
|
||||
} else {
|
||||
return store.renderText("text/x-tiddlywiki",v,type,tiddler.title);
|
||||
}
|
||||
break;
|
||||
case "date":
|
||||
var template = params.template || "DD MMM YYYY";
|
||||
return encoder(utils.formatDateString(v,template));
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<div data-tw-render-tiddler='ReadMe'><h1>Welcome to <span data-tw-macro='link' data-tw-render-step='1'><a href='TiddlyWiki5' class='tw-tiddlylink tw-tiddlylink-internal tw-tiddlylink-missing'>TiddlyWiki5</a></span></h1><div data-tw-macro='tiddler' data-tw-render-step='2'><div data-tw-render-tiddler='HelloThere'>Welcome to <span data-tw-macro='link' data-tw-render-step='1'><a href='TiddlyWiki5' class='tw-tiddlylink tw-tiddlylink-internal tw-tiddlylink-missing'>TiddlyWiki5</a></span>, a reboot of <span data-tw-macro='link' data-tw-render-step='2'><a href='TiddlyWiki' class='tw-tiddlylink tw-tiddlylink-internal tw-tiddlylink-resolves'>TiddlyWiki</a></span>, the venerable, reusable non-linear personal web notebook first released in 2004. It is a complete interactive wiki that can run from a single HTML file or as a powerful <span data-tw-macro='link' data-tw-render-step='3'><a href='What%20is%20node.js%3F' class='tw-tiddlylink tw-tiddlylink-internal tw-tiddlylink-missing'>node.js application</a></span>.<br><br>Some useful tiddlers for feature testing:<br><ul><li> <span data-tw-macro='link' data-tw-render-step='4'><a href='ClockTiddler' class='tw-tiddlylink tw-tiddlylink-internal tw-tiddlylink-missing'>ClockTiddler</a></span> showing automatic refreshing of tiddlers</li><li> <span data-tw-macro='link' data-tw-render-step='5'><a href='ImageTests' class='tw-tiddlylink tw-tiddlylink-internal tw-tiddlylink-resolves'>ImageTests</a></span> showing different ways of embedding images</li><li> <span data-tw-macro='link' data-tw-render-step='6'><a href='SampleData' class='tw-tiddlylink tw-tiddlylink-internal tw-tiddlylink-resolves'>SampleData</a></span> showing how JSON tiddlers are handled</li><li> <span data-tw-macro='link' data-tw-render-step='7'><a href='VideoTests' class='tw-tiddlylink tw-tiddlylink-internal tw-tiddlylink-resolves'>VideoTests</a></span> showing how different online video formats can be embedded</li></ul><br>Technical documentation includes:<br><ul><li> <span data-tw-macro='link' data-tw-render-step='8'><a href='Testing' class='tw-tiddlylink tw-tiddlylink-internal tw-tiddlylink-resolves'>Testing</a></span> regimen</li><li> Details of the <span data-tw-macro='link' data-tw-render-step='9'><a href='CommandLineInterface' class='tw-tiddlylink tw-tiddlylink-internal tw-tiddlylink-resolves'>CommandLineInterface</a></span></li><li> Overview of <span data-tw-macro='link' data-tw-render-step='10'><a href='TiddlyWikiArchitecture' class='tw-tiddlylink tw-tiddlylink-internal tw-tiddlylink-resolves'>TiddlyWikiArchitecture</a></span></li><ul><li> <span data-tw-macro='link' data-tw-render-step='11'><a href='TiddlyWikiInternals' class='tw-tiddlylink tw-tiddlylink-internal tw-tiddlylink-resolves'>TiddlyWikiInternals</a></span></li><li> <span data-tw-macro='link' data-tw-render-step='12'><a href='MacroInternals' class='tw-tiddlylink tw-tiddlylink-internal tw-tiddlylink-resolves'>MacroInternals</a></span></li></ul><li> Information about <span data-tw-macro='link' data-tw-render-step='13'><a href='TiddlerFiles' class='tw-tiddlylink tw-tiddlylink-internal tw-tiddlylink-resolves'>TiddlerFiles</a></span> and <span data-tw-macro='link' data-tw-render-step='14'><a href='RecipeFiles' class='tw-tiddlylink tw-tiddlylink-internal tw-tiddlylink-resolves'>RecipeFiles</a></span></li><li> <span data-tw-macro='link' data-tw-render-step='15'><a href='NewWikiTextFeatures' class='tw-tiddlylink tw-tiddlylink-internal tw-tiddlylink-resolves'>NewWikiTextFeatures</a></span></li></ul><br><span data-tw-macro='link' data-tw-render-step='16'><a href='TiddlyWiki5' class='tw-tiddlylink tw-tiddlylink-internal tw-tiddlylink-missing'>TiddlyWiki5</a></span> is currently in early beta, which is to say that it is useful but incomplete. You can get involved in the development on <span data-tw-macro='link' data-tw-render-step='17'><a href='GitHub' class='tw-tiddlylink tw-tiddlylink-internal tw-tiddlylink-missing'>GitHub</a></span> and the discussions on Google Groups:<br><br><span data-tw-macro='link' data-tw-render-step='18'><a href='https://github.com/Jermolene/TiddlyWiki5' class='tw-tiddlylink tw-tiddlylink-external'>https://github.com/Jermolene/TiddlyWiki5</a></span><br><span data-tw-macro='link' data-tw-render-step='19'><a href='http://groups.google.com/group/TiddlyWikiDev' class='tw-tiddlylink tw-tiddlylink-external'>http://groups.google.com/group/TiddlyWikiDev</a></span><br><br><blockquote>Bug: this link doesn't work:<br><div data-tw-macro='view' data-tw-render-step='20'><a href='HelloThere' class='tw-tiddlylink tw-tiddlylink-internal tw-tiddlylink-resolves'>HelloThere</a></div><br></blockquote></div></div><br><h1>Usage</h1><div data-tw-macro='tiddler' data-tw-render-step='3'><div data-tw-render-tiddler='CommandLineInterface'><span data-tw-macro='link' data-tw-render-step='1'><a href='TiddlyWiki5' class='tw-tiddlylink tw-tiddlylink-internal tw-tiddlylink-missing'>TiddlyWiki5</a></span> can be used on the command line to perform an extensive set ofLine truncated
|
||||
<div data-tw-render-tiddler='ReadMe'><h1>Welcome to <span data-tw-macro='link' data-tw-render-step='1'><a href='TiddlyWiki5' class='tw-tiddlylink tw-tiddlylink-internal tw-tiddlylink-missing'>TiddlyWiki5</a></span></h1><div data-tw-macro='tiddler' data-tw-render-step='2'><div data-tw-render-tiddler='HelloThere'>Welcome to <span data-tw-macro='link' data-tw-render-step='1'><a href='TiddlyWiki5' class='tw-tiddlylink tw-tiddlylink-internal tw-tiddlylink-missing'>TiddlyWiki5</a></span>, a reboot of <span data-tw-macro='link' data-tw-render-step='2'><a href='TiddlyWiki' class='tw-tiddlylink tw-tiddlylink-internal tw-tiddlylink-resolves'>TiddlyWiki</a></span>, the venerable, reusable non-linear personal web notebook first released in 2004. It is a complete interactive wiki that can run from a single HTML file or as a powerful <span data-tw-macro='link' data-tw-render-step='3'><a href='What%20is%20node.js%3F' class='tw-tiddlylink tw-tiddlylink-internal tw-tiddlylink-missing'>node.js application</a></span>.<br><br>Some useful tiddlers for feature testing:<br><ul><li> <span data-tw-macro='link' data-tw-render-step='4'><a href='ClockTiddler' class='tw-tiddlylink tw-tiddlylink-internal tw-tiddlylink-missing'>ClockTiddler</a></span> showing automatic refreshing of tiddlers</li><li> <span data-tw-macro='link' data-tw-render-step='5'><a href='ImageTests' class='tw-tiddlylink tw-tiddlylink-internal tw-tiddlylink-resolves'>ImageTests</a></span> showing different ways of embedding images</li><li> <span data-tw-macro='link' data-tw-render-step='6'><a href='SampleData' class='tw-tiddlylink tw-tiddlylink-internal tw-tiddlylink-resolves'>SampleData</a></span> showing how JSON tiddlers are handled</li><li> <span data-tw-macro='link' data-tw-render-step='7'><a href='VideoTests' class='tw-tiddlylink tw-tiddlylink-internal tw-tiddlylink-resolves'>VideoTests</a></span> showing how different online video formats can be embedded</li></ul><br>Technical documentation includes:<br><ul><li> <span data-tw-macro='link' data-tw-render-step='8'><a href='Testing' class='tw-tiddlylink tw-tiddlylink-internal tw-tiddlylink-resolves'>Testing</a></span> regimen</li><li> Details of the <span data-tw-macro='link' data-tw-render-step='9'><a href='CommandLineInterface' class='tw-tiddlylink tw-tiddlylink-internal tw-tiddlylink-resolves'>CommandLineInterface</a></span></li><li> Overview of <span data-tw-macro='link' data-tw-render-step='10'><a href='TiddlyWikiArchitecture' class='tw-tiddlylink tw-tiddlylink-internal tw-tiddlylink-resolves'>TiddlyWikiArchitecture</a></span></li><ul><li> <span data-tw-macro='link' data-tw-render-step='11'><a href='MacroInternals' class='tw-tiddlylink tw-tiddlylink-internal tw-tiddlylink-resolves'>MacroInternals</a></span></li></ul><li> Information about <span data-tw-macro='link' data-tw-render-step='12'><a href='TiddlerFiles' class='tw-tiddlylink tw-tiddlylink-internal tw-tiddlylink-resolves'>TiddlerFiles</a></span> and <span data-tw-macro='link' data-tw-render-step='13'><a href='RecipeFiles' class='tw-tiddlylink tw-tiddlylink-internal tw-tiddlylink-resolves'>RecipeFiles</a></span></li><li> <span data-tw-macro='link' data-tw-render-step='14'><a href='NewWikiTextFeatures' class='tw-tiddlylink tw-tiddlylink-internal tw-tiddlylink-resolves'>NewWikiTextFeatures</a></span></li></ul><br><span data-tw-macro='link' data-tw-render-step='15'><a href='TiddlyWiki5' class='tw-tiddlylink tw-tiddlylink-internal tw-tiddlylink-missing'>TiddlyWiki5</a></span> is currently in early beta, which is to say that it is useful but incomplete. You can get involved in the development on <span data-tw-macro='link' data-tw-render-step='16'><a href='GitHub' class='tw-tiddlylink tw-tiddlylink-internal tw-tiddlylink-missing'>GitHub</a></span> and the discussions on Google Groups:<br><br><span data-tw-macro='link' data-tw-render-step='17'><a href='https://github.com/Jermolene/TiddlyWiki5' class='tw-tiddlylink tw-tiddlylink-external'>https://github.com/Jermolene/TiddlyWiki5</a></span><br><span data-tw-macro='link' data-tw-render-step='18'><a href='http://groups.google.com/group/TiddlyWikiDev' class='tw-tiddlylink tw-tiddlylink-external'>http://groups.google.com/group/TiddlyWikiDev</a></span><br><br><blockquote>Bug: this link doesn't work:<br><div data-tw-macro='view' data-tw-render-step='19'><a href='HelloThere' class='tw-tiddlylink tw-tiddlylink-internal tw-tiddlylink-resolves'>HelloThere</a></div><br></blockquote></div></div><br><h1>Usage</h1><div data-tw-macro='tiddler' data-tw-render-step='3'><div data-tw-render-tiddler='CommandLineInterface'><span data-tw-macro='link' data-tw-render-step='1'><a href='TiddlyWiki5' class='tw-tiddlylink tw-tiddlylink-internal tw-tiddlylink-missing'>TiddlyWiki5</a></span> can be used on the command line to perform an extensive set of operations based on <span data-tw-macro='link' data-tw-render-step='2'><a href='RecipeFiles' class='tw-tiddlylink tw-tiddlylink-internal tw-tiddlylink-resolves'>RecipeFiles</a></span>, <spaLine truncated
|
||||
node tiddlywiki.js <options>
|
||||
</code><br>The command line options are processed sequentially from left to right. Processing pauses during long operations, like loading a <span data-tw-macro='link' data-tw-render-step='5'><a href='RecipeFiles' class='tw-tiddlylink tw-tiddlylink-internal tw-tiddlylink-resolves'>recipe file</a></span> and all the subrecipes and <span data-tw-macro='link' data-tw-render-step='6'><a href='TiddlerFiles' class='tw-tiddlylink tw-tiddlylink-internal tw-tiddlylink-resolves'>tiddlers</a></span> that it references, and then resumes with the next command line option in sequence. The following options are available:<br><table class='twtable'><tbody><tr class='evenRow'><td align='left'><code>--recipe <filepath></code></td><td align='left'>Loads a specfied <code>.recipe</code> file</td></tr><tr class='oddRow'><td align='left'><code>--load <filepath></code></td><td align='left'>Load additional tiddlers from 2.x.x <span data-tw-macro='link' data-tw-render-step='7'><a href='TiddlyWiki' class='tw-tiddlylink tw-tiddlylink-internal tw-tiddlylink-resolves'>TiddlyWiki</a></span> files (<code>.html</code>), <code>.tiddler</code>, <code>.tid</code>, <code>.json</code> or other files</td></tr><tr class='evenRow'><td align='left'><code>--savewiki <dirpath></code></td><td align='left'>Saves all the loaded tiddlers as a single file <span data-tw-macro='link' data-tw-render-step='8'><a href='TiddlyWiki' class='tw-tiddlylink tw-tiddlylink-internal tw-tiddlylink-resolves'>TiddlyWiki</a></span> called <code>index.html</code> and an RSS feed called <code>index.xml</code> in a new directory of the specified name</td></tr><tr class='oddRow'><td align='left'><code>--savetiddler <title> <filename> [<type>]</code></td><td align='left'>Save an individual tiddler as a specified MIME type, defaults to <code>text/html</code></td></tr><tr class='evenRow'><td align='left'><code>--savetiddlers <outdir></code></td><td align='left'>Saves all the loaded tiddlers as <code>.tid</code> files in the specified directory</td></tr><tr class='oddRow'><td align='left'><code>--servewiki <port></code></td><td align='left'>Serve the cooked <span data-tw-macro='link' data-tw-render-step='9'><a href='TiddlyWiki' class='tw-tiddlylink tw-tiddlylink-internal tw-tiddlylink-resolves'>TiddlyWiki</a></span> over HTTP at <code>/</code></td></tr><tr class='evenRow'><td align='left'><code>--servetiddlers <port></code></td><td align='left'>Serve individual tiddlers over HTTP at <code>/tiddlertitle</code></td></tr><tr class='oddRow'><td align='left'><code>--wikitest <dir></code></td><td align='left'>Run wikification tests against the tiddlers in the given directory</td></tr><tr class='evenRow'><td align='left'><code>--dumpstore</code></td><td align='left'>Dump the <span data-tw-macro='link' data-tw-render-step='10'><a href='TiddlyWiki' class='tw-tiddlylink tw-tiddlylink-internal tw-tiddlylink-resolves'>TiddlyWiki</a></span> store in JSON format</td></tr><tr class='oddRow'><td align='left'><code>--dumprecipe</code></td><td align='left'>Dump the current recipe in JSON format</td></tr><tr class='evenRow'><td align='left'><code>--verbose</code></td><td align='left'>verbose output, useful for debugging</td></tr></tbody></table><h2> Examples</h2>This example loads the tiddlers from a <span data-tw-macro='link' data-tw-render-step='11'><a href='TiddlyWiki' class='tw-tiddlylink tw-tiddlylink-internal tw-tiddlylink-resolves'>TiddlyWiki</a></span> HTML file and makes them available over HTTP:<br><code>
|
||||
node tiddlywiki.js --load mywiki.html --servewiki 127.0.0.1:8000
|
||||
|
||||
@@ -13,7 +13,6 @@ Technical documentation includes:
|
||||
* [[Testing]] regimen
|
||||
* Details of the CommandLineInterface
|
||||
* Overview of TiddlyWikiArchitecture
|
||||
** TiddlyWikiInternals
|
||||
** MacroInternals
|
||||
* Information about TiddlerFiles and RecipeFiles
|
||||
* NewWikiTextFeatures
|
||||
|
||||
Reference in new issue
Block a user