mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-09-05 20:38:01 +00:00
Update TW2 edition
Move the plugins into the core, add a template for the externaljs distribution of TW
This commit is contained in:
@@ -1,7 +0,0 @@
|
||||
{
|
||||
"title": "$:/plugins/tiddlywiki2/loadrecipe",
|
||||
"description": "Loads tiddlers from an old-style TiddlyWiki 2.x.x recipe file",
|
||||
"author": "JeremyRuston",
|
||||
"version": "0.0.0",
|
||||
"coreVersion": ">=5.0.0"
|
||||
}
|
@@ -1,71 +0,0 @@
|
||||
/*\
|
||||
title: $:/plugins/tiddlywiki2/loadrecipe/recipe.js
|
||||
type: application/javascript
|
||||
module-type: tiddlerdeserializer
|
||||
|
||||
Module to deserialize tiddlers from an old school TiddlyWiki recipe file.
|
||||
|
||||
The idea is to process the recipe file recursively, loading tiddlers into the main store using synchronous file operations. The tiddlers have their titles prefixed with the associated marker in curly brackets ("{shadow}", "{tiddler}" etc).
|
||||
|
||||
\*/
|
||||
(function(){
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
exports["application/vnd.tiddlywiki2-recipe"] = function(text,fields) {
|
||||
var self = this,
|
||||
path = require("path"),
|
||||
fs = require("fs"),
|
||||
tiddlers = [],
|
||||
parseRecipe = function(text) {
|
||||
var recipe = [];
|
||||
text.toString().split(/\r?\n/mg).forEach(function(line) {
|
||||
var p = line.indexOf(":");
|
||||
if(p !== -1) {
|
||||
recipe.push({
|
||||
name: line.substr(0,p).trim(),
|
||||
value: line.substr(p+1).trim()
|
||||
});
|
||||
}
|
||||
});
|
||||
return recipe;
|
||||
},
|
||||
loadTiddlersFromFile = function(sourcePath,prefix) {
|
||||
var ext = path.extname(sourcePath),
|
||||
extensionInfo = $tw.config.fileExtensionInfo[ext],
|
||||
typeInfo = extensionInfo ? $tw.config.contentTypeInfo[extensionInfo.type] : null,
|
||||
data = fs.readFileSync(sourcePath).toString(typeInfo ? typeInfo.encoding : "utf8"),
|
||||
fields = {title: sourcePath},
|
||||
tids = self.deserializeTiddlers(ext,data,fields),
|
||||
metafile = sourcePath + ".meta";
|
||||
if(ext !== ".json" && tids.length === 1 && fs.existsSync(metafile)) {
|
||||
var metadata = fs.readFileSync(metafile).toString("utf8");
|
||||
if(metadata) {
|
||||
tids = [$tw.utils.parseFields(metadata,tids[0])];
|
||||
}
|
||||
}
|
||||
tids.forEach(function(tid) {
|
||||
tid.title = prefix + tid.title;
|
||||
});
|
||||
tiddlers.push.apply(tiddlers,tids);
|
||||
},
|
||||
processRecipe = function(sourcePath,text) {
|
||||
var recipe = parseRecipe(text);
|
||||
for(var t=0; t<recipe.length; t++) {
|
||||
if(recipe[t].name === "recipe") {
|
||||
var recipeFile = path.resolve(path.dirname(sourcePath),recipe[t].value);
|
||||
processRecipe(recipeFile,fs.readFileSync(recipeFile));
|
||||
} else {
|
||||
var tiddlerFile = path.resolve(path.dirname(sourcePath),recipe[t].value);
|
||||
loadTiddlersFromFile(tiddlerFile,"{" + recipe[t].name + "}");
|
||||
}
|
||||
}
|
||||
},
|
||||
sourcePath = fields.title; // Bit of a hack to take advantage of the default title being the path to the tiddler file
|
||||
processRecipe(sourcePath,text);
|
||||
return tiddlers;
|
||||
};
|
||||
|
||||
})();
|
@@ -1,7 +0,0 @@
|
||||
{
|
||||
"title": "$:/plugins/tiddlywiki2/stripcomments",
|
||||
"description": "Strips //# comments from JavaScript source",
|
||||
"author": "JeremyRuston",
|
||||
"version": "0.0.0",
|
||||
"coreVersion": ">=5.0.0"
|
||||
}
|
@@ -1,54 +0,0 @@
|
||||
/*\
|
||||
title: $:/plugins/tiddlywiki2/stripcomments/stripcomments.js
|
||||
type: application/javascript
|
||||
module-type: fieldviewer
|
||||
|
||||
Special viewer for cooking old versions of TiddlyWiki. It removes JavaScript comments formatted as `//#`
|
||||
|
||||
\*/
|
||||
(function(){
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
var stripComments = function(text) {
|
||||
var lines = text.split("\n"),
|
||||
out = [];
|
||||
for(var line=0; line<lines.length; line++) {
|
||||
var text = lines[line];
|
||||
if(!/^\s*\/\/#/.test(text)) {
|
||||
out.push(text);
|
||||
}
|
||||
}
|
||||
return out.join("\n");
|
||||
};
|
||||
|
||||
var StripCommentsViewer = function(viewWidget,tiddler,field,value) {
|
||||
this.viewWidget = viewWidget;
|
||||
this.tiddler = tiddler;
|
||||
this.field = field;
|
||||
this.value = value;
|
||||
};
|
||||
|
||||
StripCommentsViewer.prototype.render = function() {
|
||||
// Get the value as a string
|
||||
if(this.field !== "text" && this.tiddler) {
|
||||
this.value = this.tiddler.getFieldString(this.field);
|
||||
}
|
||||
var value = "";
|
||||
if(this.value !== undefined && this.value !== null) {
|
||||
value = stripComments(this.value);
|
||||
}
|
||||
// Set the element details
|
||||
this.viewWidget.tag = "span";
|
||||
this.viewWidget.attributes = {};
|
||||
this.viewWidget.children = this.viewWidget.renderer.renderTree.createRenderers(this.viewWidget.renderer.renderContext,[{
|
||||
type: "text",
|
||||
text: value
|
||||
}]);
|
||||
};
|
||||
|
||||
exports.stripcomments = StripCommentsViewer;
|
||||
|
||||
})();
|
6
editions/tw2/tiddlywiki.info
Normal file
6
editions/tw2/tiddlywiki.info
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"plugins": [
|
||||
"tiddlywiki/loadrecipe",
|
||||
"tiddlywiki/stripcomments"
|
||||
]
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
title: $:/core/templates/tiddlywiki2.externaljs.template.html
|
||||
|
||||
{{{ [prefix[{prejs}]] ||$:/core/templates/plain-text-tiddler-strip-comments}}}
|
||||
{{{ [prefix[{js}]] ||$:/core/templates/plain-text-tiddler-strip-comments}}}
|
||||
{{{ [prefix[{postjs}]] ||$:/core/templates/plain-text-tiddler-strip-comments}}}
|
||||
{{{ [prefix[{jsext}]] ||$:/core/templates/plain-text-tiddler-strip-comments}}}
|
||||
|
Reference in New Issue
Block a user