1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-12-24 17:10:29 +00:00

New implementation for shadow tiddlers

Now shadow tiddlers are any tiddler whose title starts with "$:/"
This commit is contained in:
Jeremy Ruston 2012-11-11 14:31:45 +00:00
parent d7d6e59865
commit 9612aac296
4 changed files with 34 additions and 30 deletions

View File

@ -409,19 +409,16 @@ $tw.Wiki = function() {
this.tiddlers = {}; this.tiddlers = {};
}; };
$tw.Wiki.prototype.addTiddler = function(tiddler,isShadow) { $tw.Wiki.prototype.addTiddler = function(tiddler) {
if(!(tiddler instanceof $tw.Tiddler)) { if(!(tiddler instanceof $tw.Tiddler)) {
tiddler = new $tw.Tiddler(tiddler); tiddler = new $tw.Tiddler(tiddler);
} }
if(isShadow) {
tiddler.isShadow = true;
}
this.tiddlers[tiddler.fields.title] = tiddler; this.tiddlers[tiddler.fields.title] = tiddler;
}; };
$tw.Wiki.prototype.addTiddlers = function(tiddlers,isShadow) { $tw.Wiki.prototype.addTiddlers = function(tiddlers) {
for(var t=0; t<tiddlers.length; t++) { for(var t=0; t<tiddlers.length; t++) {
this.addTiddler(tiddlers[t],isShadow); this.addTiddler(tiddlers[t]);
} }
}; };
@ -706,19 +703,19 @@ $tw.modules.registerModuleExports("$:/boot/tiddlerdeserializer/dom","tiddlerdese
$tw.modules.applyMethods("tiddlerdeserializer",$tw.Wiki.tiddlerDeserializerModules); $tw.modules.applyMethods("tiddlerdeserializer",$tw.Wiki.tiddlerDeserializerModules);
// Load the JavaScript system tiddlers from the DOM // Load the JavaScript system tiddlers from the DOM
$tw.wiki.addTiddlers($tw.wiki.deserializeTiddlers("(DOM)",document.getElementById("libraryModules")),true); $tw.wiki.addTiddlers($tw.wiki.deserializeTiddlers("(DOM)",document.getElementById("libraryModules")));
$tw.wiki.addTiddlers($tw.wiki.deserializeTiddlers("(DOM)",document.getElementById("modules")),true); $tw.wiki.addTiddlers($tw.wiki.deserializeTiddlers("(DOM)",document.getElementById("modules")));
$tw.wiki.addTiddlers($tw.wiki.deserializeTiddlers("(DOM)",document.getElementById("bootKernelPrefix")),true); $tw.wiki.addTiddlers($tw.wiki.deserializeTiddlers("(DOM)",document.getElementById("bootKernelPrefix")));
$tw.wiki.addTiddlers($tw.wiki.deserializeTiddlers("(DOM)",document.getElementById("bootKernel")),true); $tw.wiki.addTiddlers($tw.wiki.deserializeTiddlers("(DOM)",document.getElementById("bootKernel")));
// Load the stylesheet tiddlers from the DOM // Load the stylesheet tiddlers from the DOM
$tw.wiki.addTiddlers($tw.wiki.deserializeTiddlers("(DOM)",document.getElementById("styleArea")),true); $tw.wiki.addTiddlers($tw.wiki.deserializeTiddlers("(DOM)",document.getElementById("styleArea")));
// Load the main store tiddlers from the DOM // Load the main store tiddlers from the DOM
$tw.wiki.addTiddlers($tw.wiki.deserializeTiddlers("(DOM)",document.getElementById("storeArea"))); $tw.wiki.addTiddlers($tw.wiki.deserializeTiddlers("(DOM)",document.getElementById("storeArea")));
// Load the shadow tiddlers from the DOM // Load the shadow tiddlers from the DOM
$tw.wiki.addTiddlers($tw.wiki.deserializeTiddlers("(DOM)",document.getElementById("shadowArea")),true); $tw.wiki.addTiddlers($tw.wiki.deserializeTiddlers("(DOM)",document.getElementById("shadowArea")));
// Load any preloaded tiddlers // Load any preloaded tiddlers
if($tw.preloadTiddlers) { if($tw.preloadTiddlers) {
$tw.wiki.addTiddlers($tw.preloadTiddlers,true); $tw.wiki.addTiddlers($tw.preloadTiddlers);
} }
// End of if($tw.browser) // End of if($tw.browser)
@ -814,8 +811,8 @@ $tw.extractTiddlersFromPath = function(filepath,basetitle,excludeRegExp) {
/* /*
Load all the tiddlers from a directory Load all the tiddlers from a directory
*/ */
$tw.loadTiddlersFromFolder = function(filepath,basetitle,excludeRegExp,isShadow) { $tw.loadTiddlersFromFolder = function(filepath,basetitle,excludeRegExp) {
$tw.wiki.addTiddlers($tw.extractTiddlersFromPath(filepath,basetitle,excludeRegExp),isShadow); $tw.wiki.addTiddlers($tw.extractTiddlersFromPath(filepath,basetitle,excludeRegExp));
}; };
/* /*
@ -858,17 +855,17 @@ $tw.modules.execute = function(moduleName,moduleRoot) {
}; };
// Load modules from the modules directory // Load modules from the modules directory
$tw.loadTiddlersFromFolder(path.resolve($tw.boot.bootPath,$tw.config.bootModuleSubDir),null,null,true); $tw.loadTiddlersFromFolder(path.resolve($tw.boot.bootPath,$tw.config.bootModuleSubDir));
// Load up the shadow tiddlers in the root of the core directory // Load up the shadow tiddlers in the root of the core directory
$tw.loadTiddlersFromFolder($tw.boot.bootPath,"$:/core",/^\.DS_Store$|.meta$|^modules$/,true); $tw.loadTiddlersFromFolder($tw.boot.bootPath,"$:/core",/^\.DS_Store$|.meta$|^modules$/);
// Load any plugins in the wiki plugins directory // Load any plugins in the wiki plugins directory
$tw.loadTiddlersFromFolder(path.resolve($tw.boot.wikiPath,$tw.config.wikiPluginsSubDir),null,null,true); $tw.loadTiddlersFromFolder(path.resolve($tw.boot.wikiPath,$tw.config.wikiPluginsSubDir));
// HACK: to be replaced when we re-establish sync plugins // HACK: to be replaced when we re-establish sync plugins
// Load shadow tiddlers from wiki shadows directory // Load shadow tiddlers from wiki shadows directory
$tw.loadTiddlersFromFolder(path.resolve($tw.boot.wikiPath,$tw.config.wikiShadowsSubDir),null,null,true); $tw.loadTiddlersFromFolder(path.resolve($tw.boot.wikiPath,$tw.config.wikiShadowsSubDir));
// Load tiddlers from wiki tiddlers directory // Load tiddlers from wiki tiddlers directory
$tw.loadTiddlersFromFolder(path.resolve($tw.boot.wikiPath,$tw.config.wikiTiddlersSubDir)); $tw.loadTiddlersFromFolder(path.resolve($tw.boot.wikiPath,$tw.config.wikiTiddlersSubDir));

View File

@ -106,7 +106,7 @@ exports.operators = {
} }
break; break;
case "shadow": case "shadow":
return "for(title in source) {if(" + op + "this.getTiddler(title).isShadow) {$tw.utils.pushTop(subResults,title);}}"; return "for(title in source) {if(" + op + "this.getTiddler(title).isShadow()) {$tw.utils.pushTop(subResults,title);}}";
default: default:
throw "Unknown operand for 'is' filter operator"; throw "Unknown operand for 'is' filter operator";
} }
@ -122,7 +122,7 @@ exports.operators = {
} }
break; break;
case "shadow": case "shadow":
return "for(r=subResults.length-1; r>=0; r--) {if(" + op + "this.getTiddler(subResults[r]).isShadow) {subResults.splice(r,1);}}"; return "for(r=subResults.length-1; r>=0; r--) {if(" + op + "this.getTiddler(subResults[r]).isShadow()) {subResults.splice(r,1);}}";
default: default:
throw "Unknown operand for 'is' filter operator"; throw "Unknown operand for 'is' filter operator";
} }

View File

@ -20,6 +20,17 @@ exports.hasField = function(field) {
return $tw.utils.hop(this.fields,field); return $tw.utils.hop(this.fields,field);
}; };
exports.isShadow = function() {
if(!$tw.utils.hop(this,"shadowFlag")) {
this.shadowFlag = this.fields.title.indexOf("$:/") === 0;
}
return this.shadowFlag;
};
exports.isTemporary = function() {
return this.fields.title.indexOf("$:/temp/") === 0;
};
exports.getFieldString = function(field) { exports.getFieldString = function(field) {
var value = this.fields[field]; var value = this.fields[field];
// Check for a missing field // Check for a missing field

View File

@ -43,13 +43,13 @@ exports.getTextReference = function(textRef,defaultText,currTiddlerTitle) {
} }
}; };
exports.setTextReference = function(textRef,value,currTiddlerTitle,isShadow) { exports.setTextReference = function(textRef,value,currTiddlerTitle) {
var tr = this.parseTextReference(textRef), var tr = this.parseTextReference(textRef),
title,tiddler,fields; title,tiddler,fields;
// Check if it is a reference to a tiddler // Check if it is a reference to a tiddler
if(tr.title && !tr.field) { if(tr.title && !tr.field) {
tiddler = this.getTiddler(tr.title); tiddler = this.getTiddler(tr.title);
this.addTiddler(new $tw.Tiddler(tiddler,{title: tr.title,text: value}),isShadow); this.addTiddler(new $tw.Tiddler(tiddler,{title: tr.title,text: value}));
// Else check for a field reference // Else check for a field reference
} else if(tr.field) { } else if(tr.field) {
title = tr.title || currTiddlerTitle; title = tr.title || currTiddlerTitle;
@ -179,7 +179,7 @@ exports.tiddlerExists = function(title) {
return !!this.tiddlers[title]; return !!this.tiddlers[title];
}; };
exports.addTiddler = function(tiddler,isShadow) { exports.addTiddler = function(tiddler) {
// Check if we're passed a fields hashmap instead of a tiddler // Check if we're passed a fields hashmap instead of a tiddler
if(!(tiddler instanceof $tw.Tiddler)) { if(!(tiddler instanceof $tw.Tiddler)) {
tiddler = new $tw.Tiddler(tiddler); tiddler = new $tw.Tiddler(tiddler);
@ -187,10 +187,6 @@ exports.addTiddler = function(tiddler,isShadow) {
// Get the title, and the current tiddler with that title // Get the title, and the current tiddler with that title
var title = tiddler.fields.title, var title = tiddler.fields.title,
prevTiddler = this.tiddlers[title]; prevTiddler = this.tiddlers[title];
// Make it be a shadow if indicated or if it is already a shadow
if(isShadow || (prevTiddler && prevTiddler.isShadow)) {
tiddler.isShadow = true;
}
// Save the tiddler // Save the tiddler
this.tiddlers[title] = tiddler; this.tiddlers[title] = tiddler;
this.clearCache(title); this.clearCache(title);
@ -216,7 +212,7 @@ exports.getTiddlers = function(sortField,excludeTag) {
sortField = sortField || "title"; sortField = sortField || "title";
var tiddlers = [], t, titles = []; var tiddlers = [], t, titles = [];
for(t in this.tiddlers) { for(t in this.tiddlers) {
if($tw.utils.hop(this.tiddlers,t) && !this.tiddlers[t].isShadow) { if($tw.utils.hop(this.tiddlers,t) && !this.tiddlers[t].isShadow()) {
tiddlers.push(this.tiddlers[t]); tiddlers.push(this.tiddlers[t]);
} }
} }
@ -301,7 +297,7 @@ exports.getOrphanTitles = function() {
exports.getShadowTitles = function() { exports.getShadowTitles = function() {
var titles = []; var titles = [];
for(var title in this.tiddlers) { for(var title in this.tiddlers) {
if(this.tiddlers[title].isShadow) { if(this.tiddlers[title].isShadow()) {
titles.push(title); titles.push(title);
} }
} }