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-02 16:13:17 +00:00
|
|
|
var TiddlyWiki = function TiddlyWiki(shadowStore) {
|
2011-11-22 14:29:29 +00:00
|
|
|
this.tiddlers = {};
|
2011-12-02 16:13:17 +00:00
|
|
|
this.shadows = shadowStore === undefined ? new TiddlyWiki(null) : shadowStore;
|
2011-11-22 14:29:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
TiddlyWiki.prototype.clear = function() {
|
|
|
|
this.tiddlers = {};
|
2011-12-01 10:19:21 +00:00
|
|
|
};
|
2011-11-22 14:29:29 +00:00
|
|
|
|
2011-12-01 15:07:10 +00:00
|
|
|
TiddlyWiki.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-01 15:07:10 +00:00
|
|
|
TiddlyWiki.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-11-22 14:29:29 +00:00
|
|
|
TiddlyWiki.prototype.deleteTiddler = function(title) {
|
|
|
|
delete this.tiddlers[title];
|
2011-12-01 10:19:21 +00:00
|
|
|
};
|
2011-11-22 14:29:29 +00:00
|
|
|
|
2011-12-03 17:02:34 +00:00
|
|
|
TiddlyWiki.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-11-22 14:29:29 +00:00
|
|
|
TiddlyWiki.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
|
|
|
|
|
|
|
TiddlyWiki.prototype.forEachTiddler = function(callback) {
|
|
|
|
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-01 10:19:21 +00:00
|
|
|
exports.TiddlyWiki = TiddlyWiki;
|