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

Update setTiddlerData() to preserve tiddler dictionaries

Previously, data tiddlers were always being saved in JSON format,
regardless of the original format.
This commit is contained in:
Jermolene 2014-02-23 12:33:00 +00:00
parent 823b4fa61b
commit 260080164f
2 changed files with 22 additions and 2 deletions

View File

@ -436,4 +436,15 @@ exports.base64Decode = function(string64) {
}
};
/*
Convert a hashmap into a tiddler dictionary format sequence of name:value pairs
*/
exports.makeTiddlerDictionary = function(data) {
var output = [];
for(var name in data) {
output.push(name + ": " + data[name]);
}
return output.join("\n");
};
})();

View File

@ -620,8 +620,17 @@ data: object that can be serialised to JSON
fields: optional hashmap of additional tiddler fields to be set
*/
exports.setTiddlerData = function(title,data,fields) {
var tiddler = this.getTiddler(title);
this.addTiddler(new $tw.Tiddler(tiddler,fields,{title: title, type: "application/json", text: JSON.stringify(data,null,$tw.config.preferences.jsonSpaces)},this.getModificationFields()));
var existingTiddler = this.getTiddler(title),
newFields = {
title: title
};
if(existingTiddler && existingTiddler.fields.type === "application/x-tiddler-dictionary") {
newFields.text = $tw.utils.makeTiddlerDictionary(data);
} else {
newFields.type = "application/json";
newFields.text = JSON.stringify(data,null,$tw.config.preferences.jsonSpaces);
}
this.addTiddler(new $tw.Tiddler(existingTiddler,fields,newFields,this.getModificationFields()));
};
/*