From 9a71117853bcee64aff2e1513b8a0c899458f2e9 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Mon, 28 Jan 2013 19:27:22 +0000 Subject: [PATCH] Prettify JSON --- core/boot.js | 2 +- core/modules/config.js | 1 + core/modules/wiki.js | 2 +- plugins/tiddlywiki/dropbox/dropbox.js | 2 +- plugins/tiddlywiki/tiddlyweb/tiddlyweb.js | 2 +- 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/core/boot.js b/core/boot.js index 9a7ccd3b8..df6ee3049 100644 --- a/core/boot.js +++ b/core/boot.js @@ -992,7 +992,7 @@ $tw.loadBundleFolder = function(filepath,excludeRegExp) { title: bundleInfo.title, type: "application/json", bundle: "yes", - text: JSON.stringify(bundleInfo) + text: JSON.stringify(bundleInfo,null,4) } : null; }; diff --git a/core/modules/config.js b/core/modules/config.js index ec1fc5cd2..df1853f78 100644 --- a/core/modules/config.js +++ b/core/modules/config.js @@ -16,6 +16,7 @@ exports.preferences = {}; exports.preferences.animationDuration = 400; exports.preferences.animationDurationMs = exports.preferences.animationDuration + "ms"; +exports.preferences.jsonSpaces = 4; exports.dateFormats = { months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November","December"], diff --git a/core/modules/wiki.js b/core/modules/wiki.js index 2fb82387c..10e4c5fe2 100644 --- a/core/modules/wiki.js +++ b/core/modules/wiki.js @@ -334,7 +334,7 @@ Set a tiddlers content to a JavaScript object. Currently this is done by setting */ exports.setTiddlerData = function(title,data) { var tiddler = this.getTiddler(title); - this.addTiddler(new $tw.Tiddler(tiddler,{title: title, type: "application/json", text: JSON.stringify(data)})); + this.addTiddler(new $tw.Tiddler(tiddler,{title: title, type: "application/json", text: JSON.stringify(data,null,$tw.config.preferences.jsonSpaces)})); }; /* diff --git a/plugins/tiddlywiki/dropbox/dropbox.js b/plugins/tiddlywiki/dropbox/dropbox.js index b7429c651..97380ed13 100644 --- a/plugins/tiddlywiki/dropbox/dropbox.js +++ b/plugins/tiddlywiki/dropbox/dropbox.js @@ -395,7 +395,7 @@ $tw.plugins.dropbox.saveTiddlerIndex = function(path,callback) { } }); // Save everything to a tiddler - $tw.wiki.addTiddler({title: $tw.plugins.dropbox.titleTiddlerIndex, type: "application/json", text: JSON.stringify(index)},true); + $tw.wiki.addTiddler({title: $tw.plugins.dropbox.titleTiddlerIndex, type: "application/json", text: JSON.stringify(index,null,$tw.config.preferences.jsonSpaces)},true); // Generate the index file var file = $tw.wiki.renderTiddler("text/plain",$tw.plugins.dropbox.titleAppIndexTemplate); // Save the index to Dropbox diff --git a/plugins/tiddlywiki/tiddlyweb/tiddlyweb.js b/plugins/tiddlywiki/tiddlyweb/tiddlyweb.js index 2ece83f28..191c28862 100644 --- a/plugins/tiddlywiki/tiddlyweb/tiddlyweb.js +++ b/plugins/tiddlywiki/tiddlyweb/tiddlyweb.js @@ -512,7 +512,7 @@ TiddlyWebSyncer.prototype.convertTiddlerToTiddlyWebFormat = function(title) { if(result.type === "text/x-tiddlywiki") { result.type = null; } - return JSON.stringify(result); + return JSON.stringify(result,null,$tw.config.preferences.jsonSpaces); }; /*