1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-12-17 05:30:27 +00:00

Further refactoring to the plugin mechanism

This commit is contained in:
Jeremy Ruston 2012-08-31 16:36:57 +01:00
parent 7a15b6f97a
commit b2369df65a
3 changed files with 39 additions and 10 deletions

View File

@ -632,55 +632,68 @@ if(!$tw.browser) {
/*
Load the tiddlers contained in a particular file (and optionally extract fields from the accompanying .meta file)
*/
$tw.loadTiddlersFromFile = function(file,fields,isShadow) {
var ext = path.extname(file),
$tw.extractTiddlersFromFile = function(filepath,fields) {
var ext = path.extname(filepath),
extensionInfo = $tw.config.fileExtensionInfo[ext],
typeInfo = extensionInfo ? $tw.config.contentTypeInfo[extensionInfo.type] : null,
data = fs.readFileSync(file).toString(typeInfo ? typeInfo.encoding : "utf8"),
data = fs.readFileSync(filepath).toString(typeInfo ? typeInfo.encoding : "utf8"),
tiddlers = $tw.wiki.deserializeTiddlers(ext,data,fields),
metafile = file + ".meta";
metafile = filepath + ".meta";
if(ext !== ".json" && tiddlers.length === 1 && fs.existsSync(metafile)) {
var metadata = fs.readFileSync(metafile).toString("utf8");
if(metadata) {
tiddlers = [$tw.utils.parseFields(metadata,tiddlers[0])];
}
}
$tw.wiki.addTiddlers(tiddlers,isShadow);
return tiddlers;
};
/*
Load all the tiddlers from a directory
*/
$tw.loadTiddlersFromFolder = function(filepath,basetitle,excludeRegExp,isShadow) {
$tw.extractTiddlersFromFolder = function(filepath,basetitle,excludeRegExp) {
basetitle = basetitle || "$:/plugins";
excludeRegExp = excludeRegExp || /^\.DS_Store$|.meta$/;
var tiddlers = [];
if(fs.existsSync(filepath)) {
var stat = fs.statSync(filepath);
if(stat.isDirectory()) {
var files = fs.readdirSync(filepath);
// Look for a tiddlywiki.plugin file
if(files.indexOf("tiddlywiki.plugin") !== -1) {
var pluginInfo = JSON.parse(fs.readFileSync(filepath + "/tiddlywiki.plugin").toString("utf8"));
tiddlers.push(new $tw.Tiddler({title: pluginInfo.title, type: "application/json", plugin: "yes", text: JSON.stringify(pluginInfo)}));
// Look for a tiddlywiki.files file
if(files.indexOf("tiddlywiki.files") !== -1) {
} else if(files.indexOf("tiddlywiki.files") !== -1) {
// If so, process the files it describes
var filesInfo = JSON.parse(fs.readFileSync(filepath + "/tiddlywiki.files").toString("utf8"));
for(var p=0; p<filesInfo.tiddlers.length; p++) {
var tidInfo = filesInfo.tiddlers[p],
typeInfo = $tw.config.contentTypeInfo[tidInfo.fields.type || "text/plain"],
text = fs.readFileSync(path.resolve(filepath,tidInfo.file)).toString(typeInfo ? typeInfo.encoding : "utf8");
$tw.wiki.addTiddler(new $tw.Tiddler({text: text},tidInfo.fields),isShadow);
tiddlers.push(new $tw.Tiddler({text: text},tidInfo.fields));
}
} 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,isShadow);
tiddlers.push.apply(tiddlers,$tw.extractTiddlersFromFolder(filepath + "/" + file,basetitle + "/" + file,excludeRegExp));
}
}
}
} else if(stat.isFile()) {
$tw.loadTiddlersFromFile(filepath,{title: basetitle},isShadow);
tiddlers.push.apply(tiddlers,$tw.extractTiddlersFromFile(filepath,{title: basetitle}));
}
}
return tiddlers;
};
/*
Load all the tiddlers from a directory
*/
$tw.loadTiddlersFromFolder = function(filepath,basetitle,excludeRegExp,isShadow) {
$tw.wiki.addTiddlers($tw.extractTiddlersFromFolder(filepath,basetitle,excludeRegExp),isShadow);
};
/*

View File

@ -0,0 +1,14 @@
{
"title": "$:/plugins/tiddlywiki/zoomigator",
"description": "Enables touch devices to swipe in from the right to zoom out to a birds eye view for navigating within the page",
"author": "JeremyRuston",
"version": "0.0.0",
"coreVersion": ">=5.0.0",
"source": "http://tiddlywiki.com/core/plugins/zoomigator",
"tiddlers": {
"Test1": {"text": "Some text"},
"Test2": {"text": "Some more text"},
"Test3": {"text": "console.log(require('$:/plugins/tiddlywiki/zoomigator/Test4').string);", "type": "application/javascript", "module-type": "custom"},
"Test4": {"text": "exports.string = 'Plugin I am still in You!';", "type": "application/javascript", "module-type": "custom"}
}
}

View File

@ -11,7 +11,9 @@ title: $:/templates/PageTemplate
}}}
<!-- Zooming navigator -->
<!--
<<zoomigator>>
-->
<!-- The top navigation bar -->
<div class="navbar navbar-fixed-top">