From 779e62a30fc5e61cee893eabc0f268e7fb959639 Mon Sep 17 00:00:00 2001 From: Jermolene Date: Fri, 17 Mar 2017 14:19:43 +0000 Subject: [PATCH] Add support for JSON files containing a single tiddler At the moment, we support JSON files containing an array of tiddlers. With this change the core will import files containing a single tiddler. Also adding templates for saving individual tiddlers in JSON format --- boot/boot.js | 4 +- core/modules/deserializers.js | 19 ++++----- core/modules/macros/jsontiddler.js | 40 +++++++++++++++++++ core/templates/json-tiddler.tid | 7 ++++ .../tiddlers/macros/jsontiddler Macro.tid | 13 ++++++ 5 files changed, 72 insertions(+), 11 deletions(-) create mode 100644 core/modules/macros/jsontiddler.js create mode 100644 core/templates/json-tiddler.tid create mode 100644 editions/tw5.com/tiddlers/macros/jsontiddler Macro.tid diff --git a/boot/boot.js b/boot/boot.js index 8a16a4077..43d625edc 100644 --- a/boot/boot.js +++ b/boot/boot.js @@ -1320,8 +1320,8 @@ $tw.modules.define("$:/boot/tiddlerdeserializer/html","tiddlerdeserializer",{ }); $tw.modules.define("$:/boot/tiddlerdeserializer/json","tiddlerdeserializer",{ "application/json": function(text,fields) { - var tiddlers = JSON.parse(text); - return tiddlers; + var data = JSON.parse(text); + return $tw.utils.isArray(data) ? data : [data]; } }); diff --git a/core/modules/deserializers.js b/core/modules/deserializers.js index 16f5a373f..3139a2611 100644 --- a/core/modules/deserializers.js +++ b/core/modules/deserializers.js @@ -82,17 +82,18 @@ exports["application/json"] = function(text,fields) { text: "" }] } - if($tw.utils.isArray(incoming)) { - for(var t=0; t<$text text=<>/> \ No newline at end of file diff --git a/editions/tw5.com/tiddlers/macros/jsontiddler Macro.tid b/editions/tw5.com/tiddlers/macros/jsontiddler Macro.tid new file mode 100644 index 000000000..4c49a5485 --- /dev/null +++ b/editions/tw5.com/tiddlers/macros/jsontiddler Macro.tid @@ -0,0 +1,13 @@ +caption: jsontiddlers +created: 20170317140130417 +modified: 20170317140226040 +tags: Macros [[Core Macros]] +title: jsontiddler Macro +type: text/vnd.tiddlywiki + +The <<.def jsontiddler>> [[macro|Macros]] returns the fields of a single tiddler in [[JSON|JavaScript Object Notation]] form. + +!! Parameters + +;title +: The title of a tiddler