2012-01-07 17:33:42 +00:00
|
|
|
/*\
|
|
|
|
title: js/macros/view.js
|
|
|
|
|
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
|
|
|
/*jslint node: true */
|
|
|
|
"use strict";
|
|
|
|
|
2012-02-16 20:38:10 +00:00
|
|
|
var Renderer = require("../Renderer.js").Renderer,
|
2012-02-17 14:11:25 +00:00
|
|
|
Dependencies = require("../Dependencies.js").Dependencies,
|
2012-02-16 20:38:10 +00:00
|
|
|
utils = require("../Utils.js");
|
2012-01-07 17:33:42 +00:00
|
|
|
|
|
|
|
exports.macro = {
|
|
|
|
name: "view",
|
|
|
|
types: ["text/html","text/plain"],
|
|
|
|
params: {
|
2012-02-17 17:32:32 +00:00
|
|
|
field: {byPos: 0, type: "text"},
|
|
|
|
format: {byPos: 1, type: "text"},
|
|
|
|
template: {byPos: 2, type: "text"}
|
2012-01-07 17:33:42 +00:00
|
|
|
},
|
2012-02-16 20:38:10 +00:00
|
|
|
execute: function(macroNode,tiddler,store) {
|
2012-01-23 16:42:12 +00:00
|
|
|
if(!tiddler) {
|
2012-02-16 20:38:10 +00:00
|
|
|
return Renderer.TextNode("{{** Missing tiddler **}}");
|
2012-01-23 16:42:12 +00:00
|
|
|
} else {
|
2012-02-16 20:38:10 +00:00
|
|
|
var v = tiddler[macroNode.params.field],
|
|
|
|
content,
|
|
|
|
t,
|
2012-02-19 17:20:16 +00:00
|
|
|
contentClone = [],
|
|
|
|
parents = macroNode.parents;
|
2012-01-23 16:42:12 +00:00
|
|
|
if(v !== undefined) {
|
2012-02-16 20:38:10 +00:00
|
|
|
switch(macroNode.params.format) {
|
2012-01-23 16:42:12 +00:00
|
|
|
case "link":
|
2012-02-17 14:11:25 +00:00
|
|
|
var dependencies = new Dependencies();
|
|
|
|
dependencies.addDependency(v,false);
|
2012-02-16 20:38:10 +00:00
|
|
|
var link = Renderer.MacroNode("link",
|
|
|
|
{target: v},
|
|
|
|
[Renderer.TextNode(v)],
|
|
|
|
dependencies,
|
|
|
|
store);
|
2012-02-19 17:20:16 +00:00
|
|
|
link.execute(parents,tiddler);
|
2012-02-16 20:38:10 +00:00
|
|
|
return [link];
|
2012-01-23 16:42:12 +00:00
|
|
|
case "wikified":
|
2012-02-16 20:38:10 +00:00
|
|
|
if(macroNode.params.field === "text") {
|
2012-02-19 17:20:16 +00:00
|
|
|
if(parents.indexOf(tiddler.title) === -1) {
|
|
|
|
content = store.parseTiddler(tiddler.title).tree;
|
|
|
|
} else {
|
|
|
|
content = [Renderer.TextNode("{{** Tiddler recursion error in <<view>> macro **}}")];
|
|
|
|
}
|
|
|
|
parents = parents.slice(0);
|
|
|
|
parents.push(tiddler.title);
|
2012-02-11 18:19:34 +00:00
|
|
|
} else {
|
2012-02-16 20:38:10 +00:00
|
|
|
content = store.parseText("text/x-tiddlywiki",v).tree;
|
2012-02-11 18:19:34 +00:00
|
|
|
}
|
2012-02-16 20:38:10 +00:00
|
|
|
for(t=0; t<content.length; t++) {
|
|
|
|
contentClone.push(content[t].clone());
|
|
|
|
}
|
|
|
|
for(t=0; t<contentClone.length; t++) {
|
2012-02-19 17:20:16 +00:00
|
|
|
contentClone[t].execute(parents,tiddler);
|
2012-02-16 20:38:10 +00:00
|
|
|
}
|
|
|
|
return contentClone;
|
2012-01-23 16:42:12 +00:00
|
|
|
case "date":
|
2012-02-16 20:38:10 +00:00
|
|
|
var template = macroNode.params.template || "DD MMM YYYY";
|
|
|
|
return [Renderer.TextNode(utils.formatDateString(v,template))];
|
2012-01-23 16:42:12 +00:00
|
|
|
default: // "text"
|
2012-02-16 20:38:10 +00:00
|
|
|
return [Renderer.TextNode(v)];
|
2012-01-23 16:42:12 +00:00
|
|
|
}
|
2012-01-07 17:33:42 +00:00
|
|
|
}
|
|
|
|
}
|
2012-02-17 14:11:25 +00:00
|
|
|
return [];
|
2012-01-07 17:33:42 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
})();
|
|
|
|
|