mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-08-07 22:33:50 +00:00
Added support for the view macro, and client side wikitext tiddler templates
This commit is contained in:
parent
a1a9de8ec1
commit
d96053192b
@ -14,7 +14,7 @@ var StoryNavigator = function(navigators) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
StoryNavigator.prototype.navigateTo = function(title) {
|
StoryNavigator.prototype.navigateTo = function(title) {
|
||||||
var tiddlerHtml = this.navigators.store.renderTiddler("text/html",title);
|
var tiddlerHtml = this.navigators.store.renderTiddler("text/html","SimpleTemplate",title);
|
||||||
if(tiddlerHtml) {
|
if(tiddlerHtml) {
|
||||||
$("<article/>").html(tiddlerHtml).appendTo("body");
|
$("<article/>").html(tiddlerHtml).appendTo("body");
|
||||||
return false;
|
return false;
|
||||||
|
@ -101,8 +101,9 @@ WikiStore.prototype.parseTiddler = function(title) {
|
|||||||
Render a tiddler to a particular MIME type. Optionally render it with a different tiddler as the context. This option is used to render a tiddler through a template as store.renderTiddler("text/html",tiddler,template)
|
Render a tiddler to a particular MIME type. Optionally render it with a different tiddler as the context. This option is used to render a tiddler through a template as store.renderTiddler("text/html",tiddler,template)
|
||||||
*/
|
*/
|
||||||
WikiStore.prototype.renderTiddler = function(type,title,asTitle) {
|
WikiStore.prototype.renderTiddler = function(type,title,asTitle) {
|
||||||
var parser = this.parseTiddler(title);
|
var parser = this.parseTiddler(title),
|
||||||
if(parser) {
|
asTitleExists = asTitle ? this.tiddlerExists(asTitle) : true;
|
||||||
|
if(parser && asTitleExists) {
|
||||||
return parser.render(type,parser.children,this,asTitle ? asTitle : title);
|
return parser.render(type,parser.children,this,asTitle ? asTitle : title);
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
|
@ -193,7 +193,7 @@ WikiTextRenderer.macros = {
|
|||||||
today: {
|
today: {
|
||||||
handler: function(macroNode) {
|
handler: function(macroNode) {
|
||||||
var now = new Date(),
|
var now = new Date(),
|
||||||
args = new ArgParser(macroNode.params,{noNames:true,cascadeDefaults:true}),
|
args = new ArgParser(macroNode.params,{noNames:true}),
|
||||||
value = args.byPos[0] ? utils.formatDateString(now,args.byPos[0].v) : now.toLocaleString();
|
value = args.byPos[0] ? utils.formatDateString(now,args.byPos[0].v) : now.toLocaleString();
|
||||||
macroNode.output.push({type: "text", value: value});
|
macroNode.output.push({type: "text", value: value});
|
||||||
}
|
}
|
||||||
@ -205,6 +205,41 @@ WikiTextRenderer.macros = {
|
|||||||
},
|
},
|
||||||
view: {
|
view: {
|
||||||
handler: function(macroNode) {
|
handler: function(macroNode) {
|
||||||
|
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),
|
||||||
|
value = tiddler ? tiddler.fields[field] : null;
|
||||||
|
if(tiddler && field && value) {
|
||||||
|
switch(format) {
|
||||||
|
case "text":
|
||||||
|
macroNode.output.push({type: "text", value: value});
|
||||||
|
break;
|
||||||
|
case "link":
|
||||||
|
macroNode.output.push({
|
||||||
|
type: "a",
|
||||||
|
attributes: {
|
||||||
|
href: value
|
||||||
|
},
|
||||||
|
children: [
|
||||||
|
{type: "text", value: value}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "wikified":
|
||||||
|
var parseTree = this.parser.processor.textProcessors.parse("text/x-tiddlywiki",value);
|
||||||
|
for(var t=0; t<parseTree.children.length; t++) {
|
||||||
|
macroNode.output.push(parseTree.children[t]);
|
||||||
|
}
|
||||||
|
// Execute any macros in the copy
|
||||||
|
this.executeMacros(macroNode.output);
|
||||||
|
break;
|
||||||
|
case "date":
|
||||||
|
var template = args.byPos[2] ? args.byPos[2].v : "DD MMM YYYY";
|
||||||
|
macroNode.output.push({type: "text", value: utils.formatDateString(value,template)});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -118,7 +118,7 @@ var rules = [
|
|||||||
rowTypes: {"c":"caption", "h":"thead", "":"tbody", "f":"tfoot"},
|
rowTypes: {"c":"caption", "h":"thead", "":"tbody", "f":"tfoot"},
|
||||||
handler: function(w)
|
handler: function(w)
|
||||||
{
|
{
|
||||||
var table = {type: "table", attributes: {className: "twtable"}, children: []};
|
var table = {type: "table", attributes: {"class": "twtable"}, children: []};
|
||||||
w.output.push(table);
|
w.output.push(table);
|
||||||
var prevColumns = [];
|
var prevColumns = [];
|
||||||
var currRowType = null;
|
var currRowType = null;
|
||||||
@ -130,7 +130,7 @@ var rules = [
|
|||||||
while(lookaheadMatch && lookaheadMatch.index == w.nextMatch) {
|
while(lookaheadMatch && lookaheadMatch.index == w.nextMatch) {
|
||||||
var nextRowType = lookaheadMatch[2];
|
var nextRowType = lookaheadMatch[2];
|
||||||
if(nextRowType == "k") {
|
if(nextRowType == "k") {
|
||||||
table.attributes.className = lookaheadMatch[1];
|
table.attributes["class"] = lookaheadMatch[1];
|
||||||
w.nextMatch += lookaheadMatch[0].length+1;
|
w.nextMatch += lookaheadMatch[0].length+1;
|
||||||
} else {
|
} else {
|
||||||
if(nextRowType != currRowType) {
|
if(nextRowType != currRowType) {
|
||||||
@ -150,7 +150,7 @@ var rules = [
|
|||||||
w.subWikifyTerm(rowContainer.children,this.rowTermRegExp);
|
w.subWikifyTerm(rowContainer.children,this.rowTermRegExp);
|
||||||
} else {
|
} else {
|
||||||
var theRow = {type: "tr", children: []};
|
var theRow = {type: "tr", children: []};
|
||||||
setAttr(theRow,"className",rowCount%2 ? "oddRow" : "evenRow");
|
setAttr(theRow,"class",rowCount%2 ? "oddRow" : "evenRow");
|
||||||
rowContainer.children.push(theRow);
|
rowContainer.children.push(theRow);
|
||||||
this.rowHandler(w,theRow.children,prevColumns);
|
this.rowHandler(w,theRow.children,prevColumns);
|
||||||
rowCount++;
|
rowCount++;
|
||||||
@ -607,7 +607,7 @@ var rules = [
|
|||||||
w.output.push(e);
|
w.output.push(e);
|
||||||
var styles = inlineCssHelper(w);
|
var styles = inlineCssHelper(w);
|
||||||
if(styles.length === 0)
|
if(styles.length === 0)
|
||||||
setAttr(e,"className","marked");
|
setAttr(e,"class","marked");
|
||||||
else
|
else
|
||||||
applyCssHelper(e,styles);
|
applyCssHelper(e,styles);
|
||||||
w.subWikifyTerm(e.children,/(@@)/mg);
|
w.subWikifyTerm(e.children,/(@@)/mg);
|
||||||
@ -619,7 +619,7 @@ var rules = [
|
|||||||
if(lookaheadMatch) {
|
if(lookaheadMatch) {
|
||||||
w.nextMatch = lookaheadRegExp.lastIndex;
|
w.nextMatch = lookaheadRegExp.lastIndex;
|
||||||
e = {type: lookaheadMatch[2] == "\n" ? "div" : "span", children: []};
|
e = {type: lookaheadMatch[2] == "\n" ? "div" : "span", children: []};
|
||||||
setAttr(e,"className",lookaheadMatch[1]);
|
setAttr(e,"class",lookaheadMatch[1]);
|
||||||
w.output.push(e);
|
w.output.push(e);
|
||||||
w.subWikifyTerm(e.children,/(\}\}\})/mg);
|
w.subWikifyTerm(e.children,/(\}\}\})/mg);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user