1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-10-31 15:16:18 +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.type = tiddlerFields.type || "text/vnd.tiddlywiki";
tiddlers.push(tiddlerFields);
});
var text = JSON.stringify(tiddlers);
@ -207,6 +208,7 @@ var Command = function(params,commander,callback) {
}
});
tiddlerFields["revision"] = state.wiki.getChangeCount(title);
tiddlerFields.type = tiddlerFields.type || "text/vnd.tiddlywiki";
response.writeHead(200, {"Content-Type": "application/json"});
response.end(JSON.stringify(tiddlerFields),"utf8");
} else {

View File

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

View File

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