mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-10-07 11:20:44 +00:00
Extended Tiddler object to allow retrieval of fields as strings
This commit is contained in:
parent
5ea99f053e
commit
495ef1ada5
@ -51,7 +51,8 @@ var Tiddler = function(/* tiddler,fields */) {
|
|||||||
}
|
}
|
||||||
// Expose the tags as a getter
|
// Expose the tags as a getter
|
||||||
Object.defineProperty(this,"tags",{get: function() {return tags ? tags.slice(0) : [];}});
|
Object.defineProperty(this,"tags",{get: function() {return tags ? tags.slice(0) : [];}});
|
||||||
// Other methods that need access to the fields
|
|
||||||
|
// Get a copy of the fields hashmap
|
||||||
this.getFields = function() {
|
this.getFields = function() {
|
||||||
var r = {};
|
var r = {};
|
||||||
for(var f in fields) {
|
for(var f in fields) {
|
||||||
@ -62,6 +63,53 @@ var Tiddler = function(/* tiddler,fields */) {
|
|||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
};
|
};
|
||||||
|
// Return a field as a string
|
||||||
|
this.getFieldString = function(field) {
|
||||||
|
var result, t;
|
||||||
|
if(field === "tags") {
|
||||||
|
if(tags) {
|
||||||
|
result = [];
|
||||||
|
for(t=0; t<tags.length; t++) {
|
||||||
|
if(tags[t].indexOf(" ") !== -1) {
|
||||||
|
result.push("[[" + tags[t] + "]]");
|
||||||
|
} else {
|
||||||
|
result.push(tags[t]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result.join(" ");
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(fields.hasOwnProperty(field)) {
|
||||||
|
if(field === "created" || field === "modified") {
|
||||||
|
return utils.convertToYYYYMMDDHHMM(fields[field]);
|
||||||
|
} else {
|
||||||
|
return fields[field];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
// Get all the tiddler fields as an array of {name:string,value:string} objects
|
||||||
|
this.getFieldStrings = function() {
|
||||||
|
var result = [],
|
||||||
|
fieldOrder = "title creator modifier created modified tags type".split(" "),
|
||||||
|
t,v;
|
||||||
|
for(t=0; t<fieldOrder.length; t++) {
|
||||||
|
v = this.getFieldString(fieldOrder[t]);
|
||||||
|
if(v !== null) {
|
||||||
|
result.push({name: fieldOrder[t], value: v});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(t in fields) {
|
||||||
|
if(fieldOrder.indexOf(t) === -1 && t !== "text") {
|
||||||
|
result.push({name: t, value: fields[t]});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
Tiddler.prototype.hasTag = function(tag) {
|
Tiddler.prototype.hasTag = function(tag) {
|
||||||
|
Loading…
Reference in New Issue
Block a user