1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-23 18:17:20 +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 = {};
};
$tw.Wiki.prototype.addTiddler = function(tiddler) {
$tw.Wiki.prototype.addTiddler = function(tiddler,isShadow) {
if(!(tiddler instanceof $tw.Tiddler)) {
tiddler = new $tw.Tiddler(tiddler);
}
if(isShadow) {
tiddler.isShadow = true;
}
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++) {
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) {
fields[f] = srcFields[f];
}
if(!fields.type) {
// fields.type = type;
}
if(deserializer) {
return deserializer.call(this,text,fields);
} else {
@ -502,27 +502,15 @@ $tw.plugins.registerPlugin($tw.config.root + "/kernel/tiddlerdeserializer/dom","
$tw.plugins.applyMethods("tiddlerdeserializer",$tw.Wiki.tiddlerDeserializerPlugins);
// Load the JavaScript system tiddlers from the DOM
$tw.wiki.addTiddlers(
$tw.wiki.deserializeTiddlers("(DOM)",document.getElementById("pluginModules"))
);
$tw.wiki.addTiddlers(
$tw.wiki.deserializeTiddlers("(DOM)",document.getElementById("bootKernelPrefix"))
);
$tw.wiki.addTiddlers(
$tw.wiki.deserializeTiddlers("(DOM)",document.getElementById("bootKernel"))
);
$tw.wiki.addTiddlers($tw.wiki.deserializeTiddlers("(DOM)",document.getElementById("pluginModules")),true);
$tw.wiki.addTiddlers($tw.wiki.deserializeTiddlers("(DOM)",document.getElementById("bootKernelPrefix")),true);
$tw.wiki.addTiddlers($tw.wiki.deserializeTiddlers("(DOM)",document.getElementById("bootKernel")),true);
// Load the stylesheet tiddlers from the DOM
$tw.wiki.addTiddlers(
$tw.wiki.deserializeTiddlers("(DOM)",document.getElementById("styleArea"))
);
$tw.wiki.addTiddlers($tw.wiki.deserializeTiddlers("(DOM)",document.getElementById("styleArea")),true);
// 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
$tw.wiki.addTiddlers(
$tw.wiki.deserializeTiddlers("(DOM)",document.getElementById("shadowArea"))
);
$tw.wiki.addTiddlers($tw.wiki.deserializeTiddlers("(DOM)",document.getElementById("shadowArea")),true);
// 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)
*/
$tw.loadTiddlersFromFile = function(file,fields) {
$tw.loadTiddlersFromFile = function(file,fields,isShadow) {
var ext = path.extname(file),
extensionInfo = $tw.config.fileExtensions[ext],
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])];
}
}
$tw.wiki.addTiddlers(tiddlers);
$tw.wiki.addTiddlers(tiddlers,isShadow);
};
/*
Load all the plugins from the plugins directory
*/
$tw.loadTiddlersFromFolder = function(filepath,basetitle,excludeRegExp) {
$tw.loadTiddlersFromFolder = function(filepath,basetitle,excludeRegExp,isShadow) {
basetitle = basetitle || "$:/plugins";
excludeRegExp = excludeRegExp || /^\.DS_Store$|.meta$/;
if(path.existsSync(filepath)) {
@ -572,19 +560,19 @@ $tw.loadTiddlersFromFolder = function(filepath,basetitle,excludeRegExp) {
// If so, process the files it describes
var pluginInfo = JSON.parse(fs.readFileSync(filepath + "/tiddlywiki.plugin").toString("utf8"));
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 {
// If not, read all the files in the directory
for(var f=0; f<files.length; f++) {
var file = files[f];
if(!excludeRegExp.test(file)) {
$tw.loadTiddlersFromFolder(filepath + "/" + file,basetitle + "/" + file,excludeRegExp);
$tw.loadTiddlersFromFolder(filepath + "/" + file,basetitle + "/" + file,excludeRegExp,isShadow);
}
}
}
} 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
$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
$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
// 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
$tw.loadTiddlersFromFolder(path.resolve($tw.boot.wikiPath,$tw.config.wikiTiddlersSubDir));

View File

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

View File

@ -40,7 +40,7 @@ exports.startup = function() {
$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)
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
$tw.wiki.initMacros();

View File

@ -103,11 +103,14 @@ exports.tiddlerExists = function(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
if(!(tiddler instanceof $tw.Tiddler)) {
tiddler = new $tw.Tiddler(tiddler);
}
if(isShadow) {
tiddler.isShadow = true;
}
var title = tiddler.fields.title;
this.tiddlers[title] = tiddler;
this.clearCache(title);
@ -136,8 +139,10 @@ exports.getTiddlers = function(sortField,excludeTag) {
sortField = sortField || "title";
var tiddlers = [], t, titles = [];
for(t in this.tiddlers) {
if(!this.tiddlers[t].isShadow) {
tiddlers.push(this.tiddlers[t]);
}
}
tiddlers.sort(function(a,b) {
var aa = a.fields[sortField] || 0,
bb = b.fields[sortField] || 0;
@ -206,7 +211,14 @@ exports.getOrphanTitles = 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

View File

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