mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-02-02 12:19:11 +00:00
Further simplification of the Renderer() class
This commit is contained in:
parent
0c4f877093
commit
36f61b4321
@ -9,7 +9,8 @@ Renderer objects
|
|||||||
/*jshint node: true, browser: true */
|
/*jshint node: true, browser: true */
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var utils = require("./Utils.js");
|
var utils = require("./Utils.js"),
|
||||||
|
Dependencies = require("./Dependencies.js").Dependencies;
|
||||||
|
|
||||||
var Node = function(children) {
|
var Node = function(children) {
|
||||||
if(this instanceof Node) {
|
if(this instanceof Node) {
|
||||||
@ -78,9 +79,9 @@ MacroNode.prototype.execute = function(parents,tiddler) {
|
|||||||
this.params = this.paramFn(tiddler,this.store,utils);
|
this.params = this.paramFn(tiddler,this.store,utils);
|
||||||
}
|
}
|
||||||
// Save the context tiddler
|
// Save the context tiddler
|
||||||
this.tiddlerTitle = tiddler.title;
|
this.tiddlerTitle = tiddler ? tiddler.title : null;
|
||||||
// Save a reference to the array of parents
|
// Save a reference to the array of parents
|
||||||
this.parents = parents;
|
this.parents = parents || [];
|
||||||
// Render the macro to get its content
|
// Render the macro to get its content
|
||||||
this.content = this.macro.execute(this,tiddler,this.store);
|
this.content = this.macro.execute(this,tiddler,this.store);
|
||||||
};
|
};
|
||||||
@ -397,51 +398,31 @@ var SliderNode = function(type,label,tooltip,isOpen,children) {
|
|||||||
Construct a renderer object to render a tiddler, optionally specifying a template it should be rendered through
|
Construct a renderer object to render a tiddler, optionally specifying a template it should be rendered through
|
||||||
*/
|
*/
|
||||||
var Renderer = function(tiddlerTitle,templateTitle,store) {
|
var Renderer = function(tiddlerTitle,templateTitle,store) {
|
||||||
var t;
|
|
||||||
// If there is no template specified, use the tiddler as its own template
|
|
||||||
templateTitle = templateTitle || tiddlerTitle;
|
|
||||||
// Save parameters
|
|
||||||
this.tiddlerTitle = tiddlerTitle;
|
|
||||||
this.templateTitle = templateTitle;
|
|
||||||
this.store = store;
|
this.store = store;
|
||||||
// Start the renderer with a copy of the parse tree for this tiddler template
|
// Start the renderer with the tiddler macro
|
||||||
var parseTree = store.parseTiddler(templateTitle).tree;
|
this.macro = new MacroNode(
|
||||||
this.steps = [];
|
"tiddler",
|
||||||
for(t=0; t<parseTree.length; t++) {
|
{target: tiddlerTitle, template: templateTitle},
|
||||||
this.steps.push(parseTree[t].clone());
|
null,
|
||||||
}
|
new Dependencies([],[tiddlerTitle,templateTitle]),
|
||||||
// Execute the macros in the root
|
store);
|
||||||
var tiddler = store.getTiddler(tiddlerTitle);
|
this.macro.execute();
|
||||||
for(t=0; t<this.steps.length; t++) {
|
|
||||||
this.steps[t].execute([templateTitle],tiddler);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Renderer.prototype.render = function(type) {
|
Renderer.prototype.render = function(type) {
|
||||||
var output = [];
|
return this.macro.render(type);
|
||||||
// Render the root nodes
|
|
||||||
for(var t=0; t<this.steps.length; t++) {
|
|
||||||
output.push(this.steps[t].render(type));
|
|
||||||
}
|
|
||||||
return output.join("");
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Renderer.prototype.renderInDom = function(domNode,type) {
|
Renderer.prototype.renderInDom = function(domNode,type) {
|
||||||
for(var t=0; t<this.steps.length; t++) {
|
this.macro.renderInDom(domNode,type);
|
||||||
this.steps[t].renderInDom(domNode,type);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Renderer.prototype.refresh = function(changes) {
|
Renderer.prototype.refresh = function(changes) {
|
||||||
for(var t=0; t<this.steps.length; t++) {
|
this.macro.refresh(changes);
|
||||||
this.steps[t].refresh(changes);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Renderer.prototype.refreshInDom = function(changes) {
|
Renderer.prototype.refreshInDom = function(changes) {
|
||||||
for(var t=0; t<this.steps.length; t++) {
|
this.macro.refreshInDom(changes);
|
||||||
this.steps[t].refreshInDom(changes);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Renderer.MacroNode = MacroNode;
|
Renderer.MacroNode = MacroNode;
|
||||||
|
Loading…
Reference in New Issue
Block a user