2011-12-05 16:50:25 +00:00
|
|
|
/*global require: false, exports: false, console: false */
|
2011-11-30 17:27:00 +00:00
|
|
|
"use strict";
|
|
|
|
|
2011-12-05 16:50:25 +00:00
|
|
|
var Tiddler = require("./Tiddler.js").Tiddler,
|
|
|
|
util = require("util");
|
2011-11-22 14:29:29 +00:00
|
|
|
|
2011-12-06 18:29:53 +00:00
|
|
|
var WikiStore = function WikiStore(shadowStore) {
|
2011-11-22 14:29:29 +00:00
|
|
|
this.tiddlers = {};
|
2011-12-06 18:29:53 +00:00
|
|
|
this.shadows = shadowStore === undefined ? new WikiStore(null) : shadowStore;
|
2011-11-22 14:29:29 +00:00
|
|
|
};
|
|
|
|
|
2011-12-06 18:29:53 +00:00
|
|
|
WikiStore.prototype.clear = function() {
|
2011-11-22 14:29:29 +00:00
|
|
|
this.tiddlers = {};
|
2011-12-01 10:19:21 +00:00
|
|
|
};
|
2011-11-22 14:29:29 +00:00
|
|
|
|
2011-12-06 18:29:53 +00:00
|
|
|
WikiStore.prototype.getTiddler = function(title) {
|
2011-11-22 14:29:29 +00:00
|
|
|
var t = this.tiddlers[title];
|
2011-12-03 17:02:34 +00:00
|
|
|
if(t instanceof Tiddler) {
|
|
|
|
return t;
|
|
|
|
} else if(this.shadows) {
|
|
|
|
return this.shadows.getTiddler(title);
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
2011-12-01 10:19:21 +00:00
|
|
|
};
|
2011-11-22 14:29:29 +00:00
|
|
|
|
2011-12-06 18:29:53 +00:00
|
|
|
WikiStore.prototype.getTiddlerText = function(title) {
|
2011-12-03 17:02:34 +00:00
|
|
|
var t = this.getTiddler(title);
|
2011-12-01 15:07:10 +00:00
|
|
|
return t instanceof Tiddler ? t.fields.text : null;
|
|
|
|
};
|
|
|
|
|
2011-12-06 18:29:53 +00:00
|
|
|
WikiStore.prototype.deleteTiddler = function(title) {
|
2011-11-22 14:29:29 +00:00
|
|
|
delete this.tiddlers[title];
|
2011-12-01 10:19:21 +00:00
|
|
|
};
|
2011-11-22 14:29:29 +00:00
|
|
|
|
2011-12-06 18:29:53 +00:00
|
|
|
WikiStore.prototype.tiddlerExists = function(title) {
|
2011-12-01 15:07:10 +00:00
|
|
|
return this.tiddlers[title] instanceof Tiddler;
|
2011-12-02 14:40:18 +00:00
|
|
|
};
|
2011-12-01 15:07:10 +00:00
|
|
|
|
2011-12-06 18:29:53 +00:00
|
|
|
WikiStore.prototype.addTiddler = function(tiddler) {
|
2011-12-01 15:07:10 +00:00
|
|
|
this.tiddlers[tiddler.fields.title] = tiddler;
|
2011-12-01 10:19:21 +00:00
|
|
|
};
|
2011-11-22 14:29:29 +00:00
|
|
|
|
2011-12-06 18:29:53 +00:00
|
|
|
WikiStore.prototype.forEachTiddler = function(callback) {
|
2011-11-22 14:29:29 +00:00
|
|
|
var t;
|
|
|
|
for(t in this.tiddlers) {
|
|
|
|
var tiddler = this.tiddlers[t];
|
2011-11-27 09:46:02 +00:00
|
|
|
if(tiddler instanceof Tiddler)
|
2011-11-22 14:29:29 +00:00
|
|
|
callback.call(this,t,tiddler);
|
|
|
|
}
|
2011-12-01 10:19:21 +00:00
|
|
|
};
|
2011-11-22 14:29:29 +00:00
|
|
|
|
2011-12-06 18:29:53 +00:00
|
|
|
exports.WikiStore = WikiStore;
|