1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-23 18:17:20 +00:00

Added support for the view macro, and client side wikitext tiddler templates

This commit is contained in:
Jeremy Ruston 2011-12-14 15:45:42 +00:00
parent a1a9de8ec1
commit d96053192b
4 changed files with 45 additions and 9 deletions

View File

@ -14,7 +14,7 @@ var StoryNavigator = function(navigators) {
};
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) {
$("<article/>").html(tiddlerHtml).appendTo("body");
return false;

View File

@ -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)
*/
WikiStore.prototype.renderTiddler = function(type,title,asTitle) {
var parser = this.parseTiddler(title);
if(parser) {
var parser = this.parseTiddler(title),
asTitleExists = asTitle ? this.tiddlerExists(asTitle) : true;
if(parser && asTitleExists) {
return parser.render(type,parser.children,this,asTitle ? asTitle : title);
} else {
return null;

View File

@ -193,7 +193,7 @@ WikiTextRenderer.macros = {
today: {
handler: function(macroNode) {
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();
macroNode.output.push({type: "text", value: value});
}
@ -205,6 +205,41 @@ WikiTextRenderer.macros = {
},
view: {
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;
}
}
}
}
};

View File

@ -118,7 +118,7 @@ var rules = [
rowTypes: {"c":"caption", "h":"thead", "":"tbody", "f":"tfoot"},
handler: function(w)
{
var table = {type: "table", attributes: {className: "twtable"}, children: []};
var table = {type: "table", attributes: {"class": "twtable"}, children: []};
w.output.push(table);
var prevColumns = [];
var currRowType = null;
@ -130,7 +130,7 @@ var rules = [
while(lookaheadMatch && lookaheadMatch.index == w.nextMatch) {
var nextRowType = lookaheadMatch[2];
if(nextRowType == "k") {
table.attributes.className = lookaheadMatch[1];
table.attributes["class"] = lookaheadMatch[1];
w.nextMatch += lookaheadMatch[0].length+1;
} else {
if(nextRowType != currRowType) {
@ -150,7 +150,7 @@ var rules = [
w.subWikifyTerm(rowContainer.children,this.rowTermRegExp);
} else {
var theRow = {type: "tr", children: []};
setAttr(theRow,"className",rowCount%2 ? "oddRow" : "evenRow");
setAttr(theRow,"class",rowCount%2 ? "oddRow" : "evenRow");
rowContainer.children.push(theRow);
this.rowHandler(w,theRow.children,prevColumns);
rowCount++;
@ -607,7 +607,7 @@ var rules = [
w.output.push(e);
var styles = inlineCssHelper(w);
if(styles.length === 0)
setAttr(e,"className","marked");
setAttr(e,"class","marked");
else
applyCssHelper(e,styles);
w.subWikifyTerm(e.children,/(@@)/mg);
@ -619,7 +619,7 @@ var rules = [
if(lookaheadMatch) {
w.nextMatch = lookaheadRegExp.lastIndex;
e = {type: lookaheadMatch[2] == "\n" ? "div" : "span", children: []};
setAttr(e,"className",lookaheadMatch[1]);
setAttr(e,"class",lookaheadMatch[1]);
w.output.push(e);
w.subWikifyTerm(e.children,/(\}\}\})/mg);
}