2012-01-07 17:33:42 +00:00
|
|
|
/*\
|
|
|
|
title: js/macros/tiddler.js
|
|
|
|
|
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
|
|
|
/*jslint node: true */
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var utils = require("../Utils.js");
|
|
|
|
|
|
|
|
exports.macro = {
|
|
|
|
name: "tiddler",
|
|
|
|
types: ["text/html","text/plain"],
|
|
|
|
cascadeParams: true, // Cascade names of named parameters to following anonymous parameters
|
|
|
|
params: {
|
|
|
|
target: {byName: "default", type: "tiddler", optional: false},
|
2012-01-07 20:09:01 +00:00
|
|
|
"with": {byName: true, type: "text", optional: true, dependentAll: true}
|
2012-01-07 17:33:42 +00:00
|
|
|
},
|
2012-01-15 12:16:28 +00:00
|
|
|
handler: function(type,tiddler,store,params) {
|
2012-01-07 20:09:01 +00:00
|
|
|
if(params["with"]) {
|
|
|
|
// Parameterised transclusion
|
|
|
|
var targetTiddler = store.getTiddler(params.target),
|
2012-01-17 13:01:55 +00:00
|
|
|
text = targetTiddler.text;
|
2012-01-07 20:09:01 +00:00
|
|
|
var withTokens = [params["with"]];
|
|
|
|
for(var t=0; t<withTokens.length; t++) {
|
|
|
|
var placeholderRegExp = new RegExp("\\$"+(t+1),"mg");
|
|
|
|
text = text.replace(placeholderRegExp,withTokens[t]);
|
|
|
|
}
|
2012-01-17 13:01:55 +00:00
|
|
|
return store.renderText(targetTiddler.type,text,type,tiddler.title);
|
2012-01-07 20:09:01 +00:00
|
|
|
} else {
|
|
|
|
// There's no parameterisation, so we can just render the target tiddler directly
|
2012-01-12 19:17:32 +00:00
|
|
|
return store.renderTiddler(type,params.target);
|
2012-01-07 20:09:01 +00:00
|
|
|
}
|
2012-01-07 17:33:42 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
})();
|