diff --git a/core/modules/macros/jsontiddlers.js b/core/modules/macros/jsontiddlers.js index 195785315..5f061a54f 100644 --- a/core/modules/macros/jsontiddlers.js +++ b/core/modules/macros/jsontiddlers.js @@ -20,19 +20,14 @@ exports.name = "jsontiddlers"; exports.params = [ {name: "filter"}, - {name: "spaces"}, - {name: "escapeUnsafeScriptCharacters"} + {name: "spaces"} ]; /* Run the macro */ -exports.run = function(filter,spaces,escapeUnsafeScriptCharacters) { - var json = this.wiki.getTiddlersAsJson(filter,{ - spaces: $tw.utils.parseInt(spaces), - escapeUnsafeScriptCharacters: escapeUnsafeScriptCharacters === "yes" - }); - return json; +exports.run = function(filter,spaces) { + return this.wiki.getTiddlersAsJson(filter,$tw.utils.parseInt(spaces)); }; -})(); +})(); \ No newline at end of file diff --git a/core/modules/widgets/jsontiddler.js b/core/modules/widgets/jsontiddler.js new file mode 100644 index 000000000..12c5410d4 --- /dev/null +++ b/core/modules/widgets/jsontiddler.js @@ -0,0 +1,79 @@ +/*\ +title: $:/core/modules/widgets/jsontiddler.js +type: application/javascript +module-type: widget + +Render a tiddler as JSON text + +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +var Widget = require("$:/core/modules/widgets/widget.js").widget; + +var JSONTiddlerWidget = function(parseTreeNode,options) { + this.initialise(parseTreeNode,options); +}; + +/* +Inherit from the base widget class +*/ +JSONTiddlerWidget.prototype = new Widget(); + +/* +Render this widget into the DOM +*/ +JSONTiddlerWidget.prototype.render = function(parent,nextSibling) { + var self = this; + this.parentDomNode = parent; + this.computeAttributes(); + this.execute(); + var fields = {}; + if(this.attTiddler) { + var tiddler = this.wiki.getTiddler(this.attTiddler); + if(tiddler) { + fields = tiddler.getFieldStrings({exclude: this.attExclude.split(" ")}); + } + } + $tw.utils.each(this.attributes,function(attribute,name) { + if(name.charAt(0) === "$") { + fields[name.slice(1)] = attribute; + } + }); + var json = JSON.stringify(fields); + if(this.attEscapeUnsafeScriptChars) { + json = json.replace(/ 0 || (this.attTiddler && changedTiddlers[this.attTiddler])) { + this.refreshSelf(); + return true; + } else { + return false; + } +}; + +exports.jsontiddler = JSONTiddlerWidget; + +})(); \ No newline at end of file diff --git a/core/modules/wiki.js b/core/modules/wiki.js index c9e5fd5f5..7a6b99d05 100755 --- a/core/modules/wiki.js +++ b/core/modules/wiki.js @@ -700,40 +700,21 @@ exports.getTiddlerAsJson = function(title) { } }; -/* -Options: -spaces: number of spaces. The special value -1 results in a line break in between each tiddler -escapeUnsafeScriptCharacters: true to force escaping of characters that cannot be embedded in HTML -*/ -exports.getTiddlersAsJson = function(filter,options) { - options = options || {}; - if(typeof options === "string") { - options = {spaces: options}; - } - var titles = this.filterTiddlers(filter), - spaces = (options.spaces === undefined) ? $tw.config.preferences.jsonSpaces : options.spaces, - data = [], - t; - for(t=0;t`,`<$text text=<>/> +<$jsontiddler tiddler=<> exclude="text" escapeUnsafeScriptChars="yes"/> diff --git a/core/templates/html-json-tiddler.tid b/core/templates/html-json-tiddler.tid new file mode 100644 index 000000000..077b6b26f --- /dev/null +++ b/core/templates/html-json-tiddler.tid @@ -0,0 +1,4 @@ +title: $:/core/templates/html-json-tiddler + +<$list filter="[!match[1]]">`,`<$text text=<>/> +<$jsontiddler tiddler=<> escapeUnsafeScriptChars="yes"/> diff --git a/core/templates/store.area.template.html.tid b/core/templates/store.area.template.html.tid index 58fafa871..84dd0c432 100644 --- a/core/templates/store.area.template.html.tid +++ b/core/templates/store.area.template.html.tid @@ -5,9 +5,16 @@ title: $:/core/templates/store.area.template.html <$list filter="[[$:/isEncrypted]get[text]else[no]match[no]]"> <$list filter="[[storeAreaFormat]is[variable]getvariable[]else[json]match[json]]"> - `` + `` `` diff --git a/plugins/tiddlywiki/tiddlyweb/html-json-skinny-tiddler.tid b/plugins/tiddlywiki/tiddlyweb/html-json-skinny-tiddler.tid new file mode 100644 index 000000000..d4f96fde7 --- /dev/null +++ b/plugins/tiddlywiki/tiddlyweb/html-json-skinny-tiddler.tid @@ -0,0 +1,4 @@ +title: $:/core/templates/html-json-skinny-tiddler + +<$list filter="[compare:number:gteq[1]] ~[!match[1]]">`,`<$text text=<>/> +<$jsontiddler tiddler=<> exclude="text" escapeUnsafeScriptChars="yes" $revision=<> $bag="default" $_is_skinny=""/> diff --git a/plugins/tiddlywiki/tiddlyweb/html-json-tiddler.tid b/plugins/tiddlywiki/tiddlyweb/html-json-tiddler.tid new file mode 100644 index 000000000..bd7a0deec --- /dev/null +++ b/plugins/tiddlywiki/tiddlyweb/html-json-tiddler.tid @@ -0,0 +1,4 @@ +title: $:/core/templates/html-json-tiddler + +<$list filter="[!match[1]]">`,`<$text text=<>/> +<$jsontiddler tiddler=<> escapeUnsafeScriptChars="yes" $revision=<> $bag="default">/>