2012-04-30 11:23:03 +00:00
|
|
|
/*\
|
2012-05-03 20:47:16 +00:00
|
|
|
title: $:/core/modules/macros/view.js
|
2012-04-30 11:23:03 +00:00
|
|
|
type: application/javascript
|
|
|
|
module-type: macro
|
|
|
|
|
2012-05-19 17:23:14 +00:00
|
|
|
View macro
|
|
|
|
|
2012-04-30 11:23:03 +00:00
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
2012-05-04 17:49:04 +00:00
|
|
|
/*jslint node: true, browser: true */
|
|
|
|
/*global $tw: false */
|
2012-04-30 11:23:03 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
exports.info = {
|
|
|
|
name: "view",
|
|
|
|
dependentOnContextTiddler: true,
|
|
|
|
params: {
|
|
|
|
field: {byPos: 0, type: "text"},
|
|
|
|
format: {byPos: 1, type: "text"},
|
|
|
|
template: {byPos: 2, type: "text"}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.executeMacro = function() {
|
|
|
|
var tiddler = this.wiki.getTiddler(this.tiddlerTitle),
|
|
|
|
field = this.hasParameter("field") ? this.params.field : "title",
|
2012-10-18 17:27:27 +00:00
|
|
|
value;
|
|
|
|
// Get the value to display
|
2012-04-30 11:23:03 +00:00
|
|
|
if(tiddler) {
|
|
|
|
value = tiddler.fields[field];
|
2012-10-18 17:27:27 +00:00
|
|
|
} else { // Use a special value if the tiddler is missing
|
2012-04-30 11:23:03 +00:00
|
|
|
switch(field) {
|
|
|
|
case "text":
|
2012-10-10 09:45:58 +00:00
|
|
|
value = "";
|
2012-04-30 11:23:03 +00:00
|
|
|
break;
|
|
|
|
case "title":
|
|
|
|
value = this.tiddlerTitle;
|
|
|
|
break;
|
|
|
|
case "modified":
|
|
|
|
case "created":
|
|
|
|
value = new Date();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
value = "Missing tiddler '" + this.tiddlerTitle + "'";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-10-18 17:27:27 +00:00
|
|
|
// Figure out which viewer to use
|
|
|
|
// TODO: Tiddler field modules should be able to specify a field type from which the viewer is derived
|
|
|
|
if(tiddler && this.params.format) {
|
2012-10-23 15:40:22 +00:00
|
|
|
var viewer = this.wiki.macros.view.fieldviewers[this.params.format];
|
2012-04-30 11:23:03 +00:00
|
|
|
}
|
2012-10-18 17:27:27 +00:00
|
|
|
if(!viewer) {
|
2012-10-23 15:40:22 +00:00
|
|
|
viewer = this.wiki.macros.view.fieldviewers["text"];
|
2012-10-18 17:27:27 +00:00
|
|
|
}
|
|
|
|
// Call the viewer to generate the content
|
|
|
|
return viewer(tiddler,field,value,this);
|
2012-04-30 11:23:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
})();
|