1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-24 10:37:20 +00:00
TiddlyWiki5/tw2/source/tiddlywiki/js/LoaderSaver.js
Jeremy Ruston a1c8ac624f Added first pass at support for building TiddlyWiki 2.6.x with TW5
There are still some whitespace and attribute ordering issues, but the
result runs correctly.
2012-05-29 22:02:38 +01:00

60 lines
1.7 KiB
JavaScript
Executable File

//--
//-- LoaderBase and SaverBase
//--
//# LoaderBase: A (abstract) storage loader that loads the tiddlers from a list of HTML elements.
//# The format of the elements is defined by subclasses of this loader through the internalizeTiddler implementation.
//# Subclasses must implement:
//# function getTitle(store,node)
//# function internalizeTiddler(store,tiddler,title,node)
//#
//# store must implement:
//# function createTiddler(title)
function LoaderBase() {}
LoaderBase.prototype.loadTiddler = function(store,node,tiddlers)
{
var title = this.getTitle(store,node);
if(safeMode && store.isShadowTiddler(title))
return;
if(title) {
var tiddler = store.createTiddler(title);
this.internalizeTiddler(store,tiddler,title,node);
tiddlers.push(tiddler);
}
};
LoaderBase.prototype.loadTiddlers = function(store,nodes)
{
var t,tiddlers = [];
for(t = 0; t < nodes.length; t++) {
try {
this.loadTiddler(store,nodes[t],tiddlers);
} catch(ex) {
showException(ex,config.messages.tiddlerLoadError.format([this.getTitle(store,nodes[t])]));
}
}
return tiddlers;
};
//# SaverBase: a (abstract) storage saver that externalizes all tiddlers into a string,
//# with every tiddler individually externalized (using this.externalizeTiddler) and joined with newlines
//# Subclasses must implement:
//# function externalizeTiddler(store,tiddler)
//#
//# store must implement:
//# function getTiddlers(sortByFieldName)
function SaverBase() {}
SaverBase.prototype.externalize = function(store)
{
var results = [];
var t,tiddlers = store.getTiddlers("title");
for(t = 0; t < tiddlers.length; t++) {
if(!tiddlers[t].doNotSave())
results.push(this.externalizeTiddler(store, tiddlers[t]));
}
return results.join("\n");
};