1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-27 12:07:19 +00:00

Refactor utility for converting tiddlers to JSON

This commit is contained in:
Jermolene 2018-10-01 11:27:45 +01:00
parent 107b0c17c0
commit 83a245ed21
2 changed files with 17 additions and 13 deletions

View File

@ -26,19 +26,7 @@ exports.params = [
Run the macro
*/
exports.run = function(filter) {
var tiddlers = this.wiki.filterTiddlers(filter),
data = [];
for(var t=0;t<tiddlers.length; t++) {
var tiddler = this.wiki.getTiddler(tiddlers[t]);
if(tiddler) {
var fields = new Object();
for(var field in tiddler.fields) {
fields[field] = tiddler.getFieldString(field);
}
data.push(fields);
}
}
return JSON.stringify(data,null,$tw.config.preferences.jsonSpaces);
return this.wiki.getTiddlersAsJson(filter);
};
})();

View File

@ -623,6 +623,22 @@ exports.getTiddlerAsJson = function(title) {
}
};
exports.getTiddlersAsJson = function(filter) {
var tiddlers = this.filterTiddlers(filter),
data = [];
for(var t=0;t<tiddlers.length; t++) {
var tiddler = this.getTiddler(tiddlers[t]);
if(tiddler) {
var fields = new Object();
for(var field in tiddler.fields) {
fields[field] = tiddler.getFieldString(field);
}
data.push(fields);
}
}
return JSON.stringify(data,null,$tw.config.preferences.jsonSpaces);
};
/*
Get the content of a tiddler as a JavaScript object. How this is done depends on the type of the tiddler: