1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-27 20:10:03 +00:00

Added 'isShadow' flag for system tiddlers

Shadow tiddlers are omitted from lists by default
This commit is contained in:
Jeremy Ruston 2012-06-06 13:21:20 +01:00
parent fa08941a75
commit 22b836e4ac
5 changed files with 48 additions and 54 deletions

View File

@ -321,16 +321,19 @@ $tw.Wiki = function() {
this.tiddlers = {}; this.tiddlers = {};
}; };
$tw.Wiki.prototype.addTiddler = function(tiddler) { $tw.Wiki.prototype.addTiddler = function(tiddler,isShadow) {
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) { $tw.Wiki.prototype.addTiddlers = function(tiddlers,isShadow) {
for(var t=0; t<tiddlers.length; t++) { for(var t=0; t<tiddlers.length; t++) {
this.addTiddler(tiddlers[t]); this.addTiddler(tiddlers[t],isShadow);
} }
}; };
@ -367,9 +370,6 @@ $tw.Wiki.prototype.deserializeTiddlers = function(type,text,srcFields) {
for(var f in srcFields) { for(var f in srcFields) {
fields[f] = srcFields[f]; fields[f] = srcFields[f];
} }
if(!fields.type) {
// fields.type = type;
}
if(deserializer) { if(deserializer) {
return deserializer.call(this,text,fields); return deserializer.call(this,text,fields);
} else { } else {
@ -502,27 +502,15 @@ $tw.plugins.registerPlugin($tw.config.root + "/kernel/tiddlerdeserializer/dom","
$tw.plugins.applyMethods("tiddlerdeserializer",$tw.Wiki.tiddlerDeserializerPlugins); $tw.plugins.applyMethods("tiddlerdeserializer",$tw.Wiki.tiddlerDeserializerPlugins);
// Load the JavaScript system tiddlers from the DOM // Load the JavaScript system tiddlers from the DOM
$tw.wiki.addTiddlers( $tw.wiki.addTiddlers($tw.wiki.deserializeTiddlers("(DOM)",document.getElementById("pluginModules")),true);
$tw.wiki.deserializeTiddlers("(DOM)",document.getElementById("pluginModules")) $tw.wiki.addTiddlers($tw.wiki.deserializeTiddlers("(DOM)",document.getElementById("bootKernelPrefix")),true);
); $tw.wiki.addTiddlers($tw.wiki.deserializeTiddlers("(DOM)",document.getElementById("bootKernel")),true);
$tw.wiki.addTiddlers(
$tw.wiki.deserializeTiddlers("(DOM)",document.getElementById("bootKernelPrefix"))
);
$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.addTiddlers($tw.wiki.deserializeTiddlers("(DOM)",document.getElementById("styleArea")),true);
$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.addTiddlers($tw.wiki.deserializeTiddlers("(DOM)",document.getElementById("storeArea")));
$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.addTiddlers($tw.wiki.deserializeTiddlers("(DOM)",document.getElementById("shadowArea")),true);
$tw.wiki.deserializeTiddlers("(DOM)",document.getElementById("shadowArea"))
);
// End of if($tw.browser) // End of if($tw.browser)
} }
@ -542,7 +530,7 @@ $tw.boot.wikiPath = process.cwd();
/* /*
Load the tiddlers contained in a particular file (and optionally the accompanying .meta file) Load the tiddlers contained in a particular file (and optionally the accompanying .meta file)
*/ */
$tw.loadTiddlersFromFile = function(file,fields) { $tw.loadTiddlersFromFile = function(file,fields,isShadow) {
var ext = path.extname(file), var ext = path.extname(file),
extensionInfo = $tw.config.fileExtensions[ext], extensionInfo = $tw.config.fileExtensions[ext],
data = fs.readFileSync(file).toString(extensionInfo ? extensionInfo.encoding : "utf8"), data = fs.readFileSync(file).toString(extensionInfo ? extensionInfo.encoding : "utf8"),
@ -554,13 +542,13 @@ $tw.loadTiddlersFromFile = function(file,fields) {
tiddlers = [$tw.utils.parseFields(metadata,tiddlers[0])]; tiddlers = [$tw.utils.parseFields(metadata,tiddlers[0])];
} }
} }
$tw.wiki.addTiddlers(tiddlers); $tw.wiki.addTiddlers(tiddlers,isShadow);
}; };
/* /*
Load all the plugins from the plugins directory Load all the plugins from the plugins directory
*/ */
$tw.loadTiddlersFromFolder = function(filepath,basetitle,excludeRegExp) { $tw.loadTiddlersFromFolder = function(filepath,basetitle,excludeRegExp,isShadow) {
basetitle = basetitle || "$:/plugins"; basetitle = basetitle || "$:/plugins";
excludeRegExp = excludeRegExp || /^\.DS_Store$|.meta$/; excludeRegExp = excludeRegExp || /^\.DS_Store$|.meta$/;
if(path.existsSync(filepath)) { if(path.existsSync(filepath)) {
@ -572,19 +560,19 @@ $tw.loadTiddlersFromFolder = function(filepath,basetitle,excludeRegExp) {
// If so, process the files it describes // If so, process the files it describes
var pluginInfo = JSON.parse(fs.readFileSync(filepath + "/tiddlywiki.plugin").toString("utf8")); var pluginInfo = JSON.parse(fs.readFileSync(filepath + "/tiddlywiki.plugin").toString("utf8"));
for(var p=0; p<pluginInfo.tiddlers.length; p++) { for(var p=0; p<pluginInfo.tiddlers.length; p++) {
$tw.loadTiddlersFromFile(path.resolve(filepath,pluginInfo.tiddlers[p].file),pluginInfo.tiddlers[p].fields); $tw.loadTiddlersFromFile(path.resolve(filepath,pluginInfo.tiddlers[p].file),pluginInfo.tiddlers[p].fields,isShadow);
} }
} else { } else {
// If not, read all the files in the directory // If not, read all the files in the directory
for(var f=0; f<files.length; f++) { for(var f=0; f<files.length; f++) {
var file = files[f]; var file = files[f];
if(!excludeRegExp.test(file)) { if(!excludeRegExp.test(file)) {
$tw.loadTiddlersFromFolder(filepath + "/" + file,basetitle + "/" + file,excludeRegExp); $tw.loadTiddlersFromFolder(filepath + "/" + file,basetitle + "/" + file,excludeRegExp,isShadow);
} }
} }
} }
} else if(stat.isFile()) { } else if(stat.isFile()) {
$tw.loadTiddlersFromFile(filepath,{title: basetitle}); $tw.loadTiddlersFromFile(filepath,{title: basetitle},isShadow);
} }
} }
}; };
@ -629,14 +617,14 @@ $tw.modules.execute = function(moduleName,moduleRoot) {
}; };
// Load plugins from the plugins directory // Load plugins from the plugins directory
$tw.loadTiddlersFromFolder(path.resolve($tw.boot.bootPath,$tw.config.bootModuleSubDir)); $tw.loadTiddlersFromFolder(path.resolve($tw.boot.bootPath,$tw.config.bootModuleSubDir),null,null,true);
// 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)); $tw.loadTiddlersFromFolder(path.resolve($tw.boot.wikiPath,$tw.config.wikiPluginsSubDir),null,null,true);
// 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)); $tw.loadTiddlersFromFolder(path.resolve($tw.boot.wikiPath,$tw.config.wikiShadowsSubDir),null,null,true);
// 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

@ -96,23 +96,17 @@ exports.operators = {
}, },
"is": { "is": {
selector: function(operator) { selector: function(operator) {
if(operator.operand === "tiddler") { var op = operator.prefix === "!" ? "!" : "";
if(operator.prefix === "!") { if(operator.operand === "shadow") {
return "subResults = [];"; return "for(var title in source) {if(" + op + "this.getTiddler(title).isShadow) {$tw.utils.pushTop(subResults,title);}}";
} else {
return "for(var title in source) {$tw.utils.pushTop(subResults,title);}";
}
} else { } else {
throw "Unknown operand for 'is' filter operator"; throw "Unknown operand for 'is' filter operator";
} }
}, },
filter: function(operator) { filter: function(operator) {
if(operator.operand === "tiddler") { var op = operator.prefix === "!" ? "" : "!";
if(operator.prefix === "!") { if(operator.operand === "shadow") {
return "subResults = [];"; return "for(var r=subResults.length-1; r>=0; r--) {if(" + op + "this.getTiddler(subResults[r]).isShadow) {subResults.splice(r,1);}}"
} else {
return "";
}
} else { } else {
throw "Unknown operand for 'is' filter operator"; throw "Unknown operand for 'is' filter operator";
} }

View File

@ -40,7 +40,7 @@ exports.startup = function() {
$tw.version = $tw.utils.extractVersionInfo(); $tw.version = $tw.utils.extractVersionInfo();
// Load up the shadow tiddlers in the root of the core directory (we couldn't do before because we didn't have the serializers installed) // Load up the shadow tiddlers in the root of the core directory (we couldn't do before because we didn't have the serializers installed)
if(!$tw.browser) { if(!$tw.browser) {
$tw.loadTiddlersFromFolder($tw.boot.bootPath,"$:/core",/^\.DS_Store$|.meta$|^modules$/); $tw.loadTiddlersFromFolder($tw.boot.bootPath,"$:/core",/^\.DS_Store$|.meta$|^modules$/,true);
} }
// Set up the wiki store // Set up the wiki store
$tw.wiki.initMacros(); $tw.wiki.initMacros();

View File

@ -103,11 +103,14 @@ exports.tiddlerExists = function(title) {
return !!this.tiddlers[title]; return !!this.tiddlers[title];
}; };
exports.addTiddler = function(tiddler) { exports.addTiddler = function(tiddler,isShadow) {
// 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);
} }
if(isShadow) {
tiddler.isShadow = true;
}
var title = tiddler.fields.title; var title = tiddler.fields.title;
this.tiddlers[title] = tiddler; this.tiddlers[title] = tiddler;
this.clearCache(title); this.clearCache(title);
@ -136,8 +139,10 @@ 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(!this.tiddlers[t].isShadow) {
tiddlers.push(this.tiddlers[t]); tiddlers.push(this.tiddlers[t]);
} }
}
tiddlers.sort(function(a,b) { tiddlers.sort(function(a,b) {
var aa = a.fields[sortField] || 0, var aa = a.fields[sortField] || 0,
bb = b.fields[sortField] || 0; bb = b.fields[sortField] || 0;
@ -206,7 +211,14 @@ exports.getOrphanTitles = function() {
}; };
exports.getShadowTitles = function() { exports.getShadowTitles = function() {
return []; var titles = [];
for(var title in this.tiddlers) {
if(this.tiddlers[title].isShadow) {
titles.push(title);
}
}
titles.sort();
return titles;
}; };
// Return the named cache object for a tiddler. If the cache doesn't exist then the initializer function is invoked to create it // Return the named cache object for a tiddler. If the cache doesn't exist then the initializer function is invoked to create it

View File

@ -17,7 +17,7 @@ type: text/x-tiddlywiki-html
<title><<include "$:/wiki/title" text/plain>></title> <title><<include "$:/wiki/title" text/plain>></title>
<!----------- This is a Tiddlywiki file. The points of interest in the file are marked with this pattern -----------> <!----------- This is a Tiddlywiki file. The points of interest in the file are marked with this pattern ----------->
<div id="styleArea"> <div id="styleArea">
<<include "[type[text/css]]" application/x-tiddler-css>> <<include "[is[shadow]type[text/css]]" application/x-tiddler-css>>
</div> </div>
<!----------- Raw markup -----------> <!----------- Raw markup ----------->
<<include "[tag[$:/shadow/rawMarkup]]" text/plain>> <<include "[tag[$:/shadow/rawMarkup]]" text/plain>>
@ -31,11 +31,11 @@ type: text/x-tiddlywiki-html
</noscript> </noscript>
<!----------- Miscellaneous shadow tiddlers -----------> <!----------- Miscellaneous shadow tiddlers ----------->
<div id="shadowArea" style="display:none;"> <div id="shadowArea" style="display:none;">
<<include "[!type[text/css]] -[type[application/javascript]has[module-type]] -[[$:/core/boot.js]] -[[$:/core/bootprefix.js]]" application/x-tiddler-html-div>> <<include "[is[shadow]] -[type[text/css]] -[type[application/javascript]has[module-type]] -[[$:/core/boot.js]] -[[$:/core/bootprefix.js]]" application/x-tiddler-html-div>>
</div> </div>
<!----------- Ordinary tiddlers -----------> <!----------- Ordinary tiddlers ----------->
<div id="storeArea" style="display:none;"> <div id="storeArea" style="display:none;">
<<include "[is[tiddler]]" application/x-tiddler-html-div>> <<include "[!is[shadow]]" application/x-tiddler-html-div>>
</div> </div>
<!----------- Boot kernel prologue -----------> <!----------- Boot kernel prologue ----------->
<div id="bootKernelPrefix" style="display:none;"> <div id="bootKernelPrefix" style="display:none;">
@ -43,7 +43,7 @@ type: text/x-tiddlywiki-html
</div> </div>
<!----------- Plugin modules -----------> <!----------- Plugin modules ----------->
<div id="pluginModules" style="display:none;"> <div id="pluginModules" style="display:none;">
<<include "[type[application/javascript]has[module-type]]" application/x-tiddler-module>> <<include "[is[shadow]type[application/javascript]has[module-type]]" application/x-tiddler-module>>
</div> </div>
<!----------- Boot kernel -----------> <!----------- Boot kernel ----------->
<div id="bootKernel" style="display:none;"> <div id="bootKernel" style="display:none;">