2012-01-07 17:33:42 +00:00
|
|
|
/*\
|
|
|
|
title: js/macros/view.js
|
|
|
|
|
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
|
|
|
/*jslint node: true */
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var utils = require("../Utils.js");
|
|
|
|
|
|
|
|
exports.macro = {
|
|
|
|
name: "view",
|
|
|
|
types: ["text/html","text/plain"],
|
|
|
|
params: {
|
|
|
|
field: {byPos: 0, type: "text", optional: false},
|
|
|
|
format: {byPos: 1, type: "text", optional: true},
|
|
|
|
template: {byPos: 2, type: "text", optional: true}
|
|
|
|
},
|
2012-01-15 12:16:28 +00:00
|
|
|
handler: function(type,tiddler,store,params) {
|
2012-01-07 17:33:42 +00:00
|
|
|
var v = tiddler.fields[params.field],
|
|
|
|
encoder = type === "text/html" ? utils.htmlEncode : function(x) {return x;};
|
|
|
|
if(v) {
|
|
|
|
switch(params.format) {
|
|
|
|
case "link":
|
2012-01-15 18:39:14 +00:00
|
|
|
return store.renderMacro("link",type,tiddler,{target: v},encoder(v));
|
2012-01-07 17:33:42 +00:00
|
|
|
case "wikified":
|
|
|
|
return store.renderTiddler(type,tiddler.fields.title);
|
|
|
|
case "date":
|
|
|
|
var template = params.template || "DD MMM YYYY";
|
|
|
|
return encoder(utils.formatDateString(v,template));
|
|
|
|
default: // "text"
|
|
|
|
return encoder(v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
})();
|
|
|
|
|