1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-07-15 16:34:23 +00:00
TiddlyWiki5/js/TiddlyWiki.js
Jeremy Ruston 620add5579 Integrated the TiddlyWiki wikifier
A large refactoring to tidy up the interface of the TiddlyWiki wikifier
code, and package it as a wiki text parser.
2011-12-05 16:50:25 +00:00

54 lines
1.2 KiB
JavaScript
Executable File

/*global require: false, exports: false, console: false */
"use strict";
var Tiddler = require("./Tiddler.js").Tiddler,
util = require("util");
var TiddlyWiki = function TiddlyWiki(shadowStore) {
this.tiddlers = {};
this.shadows = shadowStore === undefined ? new TiddlyWiki(null) : shadowStore;
};
TiddlyWiki.prototype.clear = function() {
this.tiddlers = {};
};
TiddlyWiki.prototype.getTiddler = function(title) {
var t = this.tiddlers[title];
if(t instanceof Tiddler) {
return t;
} else if(this.shadows) {
return this.shadows.getTiddler(title);
} else {
return null;
}
};
TiddlyWiki.prototype.getTiddlerText = function(title) {
var t = this.getTiddler(title);
return t instanceof Tiddler ? t.fields.text : null;
};
TiddlyWiki.prototype.deleteTiddler = function(title) {
delete this.tiddlers[title];
};
TiddlyWiki.prototype.tiddlerExists = function(title) {
return this.tiddlers[title] instanceof Tiddler;
};
TiddlyWiki.prototype.addTiddler = function(tiddler) {
this.tiddlers[tiddler.fields.title] = tiddler;
};
TiddlyWiki.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);
}
};
exports.TiddlyWiki = TiddlyWiki;