mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2026-04-17 20:31:31 +00:00
Write tiddlers with string fields
Otherwise date fields will get saved as JS date objects, which are not properly defined in JSON.
This commit is contained in:
33
boot/boot.js
33
boot/boot.js
@@ -1097,6 +1097,39 @@ $tw.Tiddler.prototype.isEqual = function(tiddler,excludeFields) {
|
||||
return differences.length === 0;
|
||||
};
|
||||
|
||||
$tw.Tiddler.prototype.getFieldString = function(field,defaultValue) {
|
||||
var value = this.fields[field];
|
||||
// Check for a missing field
|
||||
if(value === undefined || value === null) {
|
||||
return defaultValue || "";
|
||||
}
|
||||
// Stringify the field with the associated tiddler field module (if any)
|
||||
var fieldModule = $tw.Tiddler.fieldModules[field];
|
||||
if(fieldModule && fieldModule.stringify) {
|
||||
return fieldModule.stringify.call(this,value);
|
||||
} else {
|
||||
return value.toString();
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Get all the fields as a hashmap of strings. Options:
|
||||
exclude: an array of field names to exclude
|
||||
*/
|
||||
$tw.Tiddler.prototype.getFieldStrings = function(options) {
|
||||
options = options || {};
|
||||
var exclude = options.exclude || [];
|
||||
var fields = {};
|
||||
for(var field in this.fields) {
|
||||
if($tw.utils.hop(this.fields,field)) {
|
||||
if(exclude.indexOf(field) === -1) {
|
||||
fields[field] = this.getFieldString(field);
|
||||
}
|
||||
}
|
||||
}
|
||||
return fields;
|
||||
};
|
||||
|
||||
/*
|
||||
Register and install the built in tiddler field modules
|
||||
*/
|
||||
|
||||
@@ -24,21 +24,6 @@ exports.isDraft = function() {
|
||||
return this.hasField("draft.of");
|
||||
};
|
||||
|
||||
exports.getFieldString = function(field,defaultValue) {
|
||||
var value = this.fields[field];
|
||||
// Check for a missing field
|
||||
if(value === undefined || value === null) {
|
||||
return defaultValue || "";
|
||||
}
|
||||
// Stringify the field with the associated tiddler field module (if any)
|
||||
var fieldModule = $tw.Tiddler.fieldModules[field];
|
||||
if(fieldModule && fieldModule.stringify) {
|
||||
return fieldModule.stringify.call(this,value);
|
||||
} else {
|
||||
return value.toString();
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Get the value of a field as a list
|
||||
*/
|
||||
@@ -51,24 +36,6 @@ exports.getFieldList = function(field) {
|
||||
return $tw.utils.parseStringArray(value);
|
||||
};
|
||||
|
||||
/*
|
||||
Get all the fields as a hashmap of strings. Options:
|
||||
exclude: an array of field names to exclude
|
||||
*/
|
||||
exports.getFieldStrings = function(options) {
|
||||
options = options || {};
|
||||
var exclude = options.exclude || [];
|
||||
var fields = {};
|
||||
for(var field in this.fields) {
|
||||
if($tw.utils.hop(this.fields,field)) {
|
||||
if(exclude.indexOf(field) === -1) {
|
||||
fields[field] = this.getFieldString(field);
|
||||
}
|
||||
}
|
||||
}
|
||||
return fields;
|
||||
};
|
||||
|
||||
/*
|
||||
Get all the fields as a name:value block. Options:
|
||||
exclude: an array of field names to exclude
|
||||
|
||||
@@ -99,7 +99,7 @@ $tw.Wiki = function(options) {
|
||||
var title = tiddler.fields.title;
|
||||
if(title) {
|
||||
// Save the new tiddler
|
||||
self.sqlFunctions.sqlSaveTiddler(tiddler.fields);
|
||||
self.sqlFunctions.sqlSaveTiddler(tiddler.getFieldStrings());
|
||||
// Update caches
|
||||
this.clearCache(title);
|
||||
this.clearGlobalCache();
|
||||
|
||||
Reference in New Issue
Block a user