1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-10-27 21:57:39 +00:00

Fixes for TiddlyWeb

This commit is contained in:
Jeremy Ruston
2013-11-08 20:18:26 +00:00
parent 60b992e1c7
commit ec481415f9
3 changed files with 13 additions and 10 deletions

View File

@@ -180,6 +180,7 @@ var Command = function(params,commander,callback) {
} }
}); });
tiddlerFields["revision"] = state.wiki.getChangeCount(title); tiddlerFields["revision"] = state.wiki.getChangeCount(title);
tiddlerFields.type = tiddlerFields.type || "text/vnd.tiddlywiki";
tiddlers.push(tiddlerFields); tiddlers.push(tiddlerFields);
}); });
var text = JSON.stringify(tiddlers); var text = JSON.stringify(tiddlers);
@@ -207,6 +208,7 @@ var Command = function(params,commander,callback) {
} }
}); });
tiddlerFields["revision"] = state.wiki.getChangeCount(title); tiddlerFields["revision"] = state.wiki.getChangeCount(title);
tiddlerFields.type = tiddlerFields.type || "text/vnd.tiddlywiki";
response.writeHead(200, {"Content-Type": "application/json"}); response.writeHead(200, {"Content-Type": "application/json"});
response.end(JSON.stringify(tiddlerFields),"utf8"); response.end(JSON.stringify(tiddlerFields),"utf8");
} else { } else {

View File

@@ -690,6 +690,9 @@ exports.parseTiddler = function(title,options) {
exports.parseTextReference = function(title,field,index,options) { exports.parseTextReference = function(title,field,index,options) {
if(field === "text" || (!field && !index)) { if(field === "text" || (!field && !index)) {
// Force the tiddler to be lazily loaded
this.getTiddlerText(title);
// Parse it
return this.parseTiddler(title,options); return this.parseTiddler(title,options);
} else { } else {
var tiddler,text; var tiddler,text;

View File

@@ -130,6 +130,7 @@ TiddlyWebAdaptor.prototype.getCsrfToken = function() {
Get an array of skinny tiddler fields from the server Get an array of skinny tiddler fields from the server
*/ */
TiddlyWebAdaptor.prototype.getSkinnyTiddlers = function(callback) { TiddlyWebAdaptor.prototype.getSkinnyTiddlers = function(callback) {
var self = this;
$tw.utils.httpRequest({ $tw.utils.httpRequest({
url: this.host + "recipes/" + this.recipe + "/tiddlers.json", url: this.host + "recipes/" + this.recipe + "/tiddlers.json",
callback: function(err,data) { callback: function(err,data) {
@@ -140,10 +141,7 @@ TiddlyWebAdaptor.prototype.getSkinnyTiddlers = function(callback) {
// Process the tiddlers to make sure the revision is a string // Process the tiddlers to make sure the revision is a string
var tiddlers = JSON.parse(data); var tiddlers = JSON.parse(data);
for(var t=0; t<tiddlers.length; t++) { for(var t=0; t<tiddlers.length; t++) {
var tiddlerFields = tiddlers[t]; var tiddlerFields = self.convertTiddlerFromTiddlyWebFormat(tiddlers[t]);
if(typeof tiddlerFields.revision === "number") {
tiddlerFields.revision = tiddlerFields.revision.toString();
}
} }
// Invoke the callback with the skinny tiddlers // Invoke the callback with the skinny tiddlers
callback(null,tiddlers); callback(null,tiddlers);
@@ -189,7 +187,7 @@ TiddlyWebAdaptor.prototype.loadTiddler = function(title,callback) {
return callback(err); return callback(err);
} }
// Invoke the callback // Invoke the callback
callback(null,self.convertTiddlerFromTiddlyWebFormat(data)); callback(null,self.convertTiddlerFromTiddlyWebFormat(JSON.parse(data)));
} }
}); });
}; };
@@ -237,19 +235,19 @@ TiddlyWebAdaptor.prototype.convertTiddlerToTiddlyWebFormat = function(tiddler) {
} }
}); });
} }
// Convert the type "text/x-tiddlywiki" into null // Default the content type and convert the type "text/x-tiddlywiki" into null
if(result.type === "text/x-tiddlywiki") { if(result.type === "text/x-tiddlywiki") {
result.type = null; result.type = null;
} };
result.type = result.type || "text/vnd.tiddlywiki";
return JSON.stringify(result,null,$tw.config.preferences.jsonSpaces); return JSON.stringify(result,null,$tw.config.preferences.jsonSpaces);
}; };
/* /*
Convert a field set in TiddlyWeb format into ordinary TiddlyWiki5 format Convert a field set in TiddlyWeb format into ordinary TiddlyWiki5 format
*/ */
TiddlyWebAdaptor.prototype.convertTiddlerFromTiddlyWebFormat = function(data) { TiddlyWebAdaptor.prototype.convertTiddlerFromTiddlyWebFormat = function(tiddlerFields) {
var tiddlerFields = JSON.parse(data), var self = this,
self = this,
result = {}; result = {};
// Transfer the fields, pulling down the `fields` hashmap // Transfer the fields, pulling down the `fields` hashmap
$tw.utils.each(tiddlerFields,function(element,title,object) { $tw.utils.each(tiddlerFields,function(element,title,object) {