From bb10222b8d2b9890504c4066ca655e69fb204ec8 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Mon, 5 Nov 2012 19:00:54 +0000 Subject: [PATCH] Added fields macro and put it in the default view template --- core/modules/macros/fields.js | 67 +++++++++++++++++++++++++++++++++ core/templates/ViewTemplate.tid | 23 +++++++++-- 2 files changed, 87 insertions(+), 3 deletions(-) create mode 100644 core/modules/macros/fields.js diff --git a/core/modules/macros/fields.js b/core/modules/macros/fields.js new file mode 100644 index 000000000..9a2514cd2 --- /dev/null +++ b/core/modules/macros/fields.js @@ -0,0 +1,67 @@ +/*\ +title: $:/core/modules/macros/fields.js +type: application/javascript +module-type: macro + +Fields macro + +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +exports.info = { + name: "fields", + dependentOnContextTiddler: true, + params: { + } +}; + +exports.executeMacro = function() { + // Create the table + var attributes = { + "class": ["tw-fields-table"] + }; + if(this.classes) { + $tw.utils.pushTop(attributes["class"],this.classes); + } + var rows = [ + $tw.Tree.Element("tr",{},[ + $tw.Tree.Element("th",{},[$tw.Tree.Text("Field")]), + $tw.Tree.Element("th",{},[$tw.Tree.Text("Value")]) + ]) + ]; + // Get the value to display + var tiddler = this.wiki.getTiddler(this.tiddlerTitle); + if(tiddler) { + var fields = []; + for(var f in tiddler.fields) { + fields.push(f); + } + fields.sort(); + for(f=0; f - <> << <