mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-27 03:57:21 +00:00
Added sortField and excludeTag to WikiStore.forEachTiddler
This commit is contained in:
parent
a223f4300a
commit
820bd02f8f
17
js/Recipe.js
17
js/Recipe.js
@ -283,7 +283,7 @@ Recipe.prototype.cookRss = function()
|
||||
},
|
||||
tiddlerToRssItem = function(tiddler,uri) {
|
||||
var s = "<title" + ">" + utils.htmlEncode(tiddler.fields.title) + "</title" + ">\n";
|
||||
s += "<description>" + utils.htmlEncode(me.store.renderTiddler("text/plain",tiddler.fields.title)) + "</description>\n";
|
||||
s += "<description>" + utils.htmlEncode(me.store.renderTiddler("text/html",tiddler.fields.title)) + "</description>\n";
|
||||
var i;
|
||||
if(tiddler.fields.tags) {
|
||||
for(i=0; i<tiddler.fields.tags.length; i++) {
|
||||
@ -298,24 +298,11 @@ Recipe.prototype.cookRss = function()
|
||||
},
|
||||
getRssTiddlers = function(sortField,excludeTag) {
|
||||
var r = [];
|
||||
me.store.forEachTiddler(function(title,tiddler) {
|
||||
me.store.forEachTiddler(sortField,excludeTag,function(title,tiddler) {
|
||||
if(!tiddler.hasTag(excludeTag)) {
|
||||
r.push(tiddler);
|
||||
}
|
||||
});
|
||||
r.sort(function(a,b) {
|
||||
var aa = a.fields[sortField] || 0,
|
||||
bb = b.fields[sortField] || 0;
|
||||
if(aa < bb) {
|
||||
return -1;
|
||||
} else {
|
||||
if(aa > bb) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
});
|
||||
return r;
|
||||
};
|
||||
// Assemble the header
|
||||
|
@ -45,12 +45,40 @@ WikiStore.prototype.addTiddler = function(tiddler) {
|
||||
this.tiddlers[tiddler.fields.title] = tiddler;
|
||||
};
|
||||
|
||||
WikiStore.prototype.forEachTiddler = function(callback) {
|
||||
var t;
|
||||
for(t in this.tiddlers) {
|
||||
var tiddler = this.tiddlers[t];
|
||||
if(tiddler instanceof Tiddler)
|
||||
callback.call(this,t,tiddler);
|
||||
WikiStore.prototype.forEachTiddler = function(/* [sortField,[excludeTag,]]callback */) {
|
||||
var a = 0,
|
||||
sortField = arguments.length > 1 ? arguments[a++] : null,
|
||||
excludeTag = arguments.length > 2 ? arguments[a++] : null,
|
||||
callback = arguments[a++],
|
||||
t,tiddlers = [],tiddler;
|
||||
if(sortField) {
|
||||
for(t in this.tiddlers) {
|
||||
tiddlers.push(this.tiddlers[t]);
|
||||
}
|
||||
tiddlers.sort(function (a,b) {
|
||||
var aa = a.fields[sortField] || 0,
|
||||
bb = b.fields[sortField] || 0;
|
||||
if(aa < bb) {
|
||||
return -1;
|
||||
} else {
|
||||
if(aa > bb) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
});
|
||||
for(t=0; t<tiddlers.length; t++) {
|
||||
if(!tiddlers[t].hasTag(excludeTag)) {
|
||||
callback.call(this,tiddlers[t].fields.title,tiddlers[t]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for(t in this.tiddlers) {
|
||||
tiddler = this.tiddlers[t];
|
||||
if(tiddler instanceof Tiddler && !tiddler.hasTag(excludeTag))
|
||||
callback.call(this,t,tiddler);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -315,9 +315,9 @@ Returns a boolean indicating whether a particular tiddler exists.
|
||||
|
||||
Adds the specified tiddler object to the store. The tiddler can be specified as a Tiddler() object or a hashmap of tiddler fields.
|
||||
|
||||
#### store.forEachTiddler(callback)
|
||||
#### store.forEachTiddler([sortField,[excludeTag,]]callback)
|
||||
|
||||
Invokes a callback for each tiddler in the store. The callback is called with the title of the tiddler and a reference to the tiddler itself. For example:
|
||||
Invokes a callback for each tiddler in the store, optionally sorting by a specified field and excluding tiddlers with a specified tag. The callback is called with the title of the tiddler and a reference to the tiddler itself. For example:
|
||||
|
||||
store.forEachTiddler(function(title,tiddler) {
|
||||
console.log(title);
|
||||
|
Loading…
Reference in New Issue
Block a user