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
This commit is contained in:
Jermolene
2017-03-17 14:19:43 +00:00
parent d65fd771e7
commit 779e62a30f
5 changed files with 72 additions and 11 deletions
+40
View File
@@ -0,0 +1,40 @@
/*\
title: $:/core/modules/macros/jsontiddler.js
type: application/javascript
module-type: macro
Macro to output a single tiddler to JSON
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
/*
Information about this macro
*/
exports.name = "jsontiddler";
exports.params = [
{name: "title"}
];
/*
Run the macro
*/
exports.run = function(title) {
title = title || this.getVariable("currentTiddler");
var tiddler = !!title && this.wiki.getTiddler(title),
fields = new Object();
if(tiddler) {
for(var field in tiddler.fields) {
fields[field] = tiddler.getFieldString(field);
}
}
return JSON.stringify(fields,null,$tw.config.preferences.jsonSpaces);
};
})();