mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2026-09-20 00:30:43 +00:00
Part two of turning the rabbit hole inside out
This commit is contained in:
@@ -0,0 +1,112 @@
|
||||
/*\
|
||||
title: $:/core/modules/commands/dump.js
|
||||
type: application/javascript
|
||||
module-type: command
|
||||
|
||||
Dump command
|
||||
|
||||
\*/
|
||||
(function(){
|
||||
|
||||
/*jshint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
exports.info = {
|
||||
name: "dump",
|
||||
synchronous: true
|
||||
};
|
||||
|
||||
var Command = function(params,commander) {
|
||||
this.params = params;
|
||||
this.commander = commander;
|
||||
this.output = commander.streams.output;
|
||||
};
|
||||
|
||||
Command.prototype.execute = function() {
|
||||
if(this.params.length < 1) {
|
||||
return "Too few parameters for dump command";
|
||||
}
|
||||
var subcommand = this.subcommands[this.params[0]];
|
||||
if(subcommand) {
|
||||
return subcommand.call(this);
|
||||
} else {
|
||||
return "Unknown subcommand (" + this.params[0] + ") for dump command";
|
||||
}
|
||||
};
|
||||
|
||||
Command.prototype.subcommands = {};
|
||||
|
||||
Command.prototype.subcommands.tiddler = function() {
|
||||
if(this.params.length < 2) {
|
||||
return "Too few parameters for dump tiddler command";
|
||||
}
|
||||
var tiddler = this.commander.wiki.getTiddler(this.params[1]);
|
||||
this.output.write("Tiddler '" + this.params[1] + "' contains these fields:\n");
|
||||
for(var t in tiddler.fields) {
|
||||
this.output.write(" " + t + ": " + tiddler.getFieldString(t) + "\n");
|
||||
}
|
||||
return null; // No error
|
||||
};
|
||||
|
||||
Command.prototype.subcommands.tiddlers = function() {
|
||||
var tiddlers = this.commander.wiki.sortTiddlers();
|
||||
this.output.write("Wiki contains these tiddlers:\n");
|
||||
for(var t=0; t<tiddlers.length; t++) {
|
||||
this.output.write(tiddlers[t] + "\n");
|
||||
}
|
||||
return null; // No error
|
||||
};
|
||||
|
||||
Command.prototype.subcommands.shadows = function() {
|
||||
var tiddlers = this.commander.wiki.shadows.sortTiddlers();
|
||||
this.output.write("Wiki contains these shadow tiddlers:\n");
|
||||
for(var t=0; t<tiddlers.length; t++) {
|
||||
this.output.write(tiddlers[t] + "\n");
|
||||
}
|
||||
return null; // No error
|
||||
};
|
||||
|
||||
Command.prototype.subcommands.config = function() {
|
||||
var self = this;
|
||||
var quotePropertyName = function(p) {
|
||||
var unquotedPattern = /^[A-Za-z0-9_]*$/mg;
|
||||
if(unquotedPattern.test(p)) {
|
||||
return p;
|
||||
} else {
|
||||
return "[\"" + $tw.utils.stringify(p) + "\"]";
|
||||
}
|
||||
},
|
||||
dumpConfig = function(object,prefix) {
|
||||
for(var n in object) {
|
||||
var v = object[n];
|
||||
if(typeof v === "object") {
|
||||
dumpConfig(v,prefix + "." + quotePropertyName(n));
|
||||
} else if(typeof v === "string") {
|
||||
self.output.write(prefix + "." + quotePropertyName(n) + ": \"" + $tw.utils.stringify(v) + "\"\n");
|
||||
} else {
|
||||
self.output.write(prefix + "." + quotePropertyName(n) + ": " + v.toString() + "\n");
|
||||
}
|
||||
}
|
||||
},
|
||||
dumpObject = function(heading,object) {
|
||||
self.output.write(heading +"\n");
|
||||
for(var n in object) {
|
||||
self.output.write(" " + n + "\n");
|
||||
}
|
||||
};
|
||||
this.output.write("Configuration:\n");
|
||||
dumpConfig($tw.config," $tw.config");
|
||||
dumpObject("Tiddler field plugins:",$tw.Tiddler.fieldPlugins);
|
||||
dumpObject("Loaded modules:",$tw.modules.titles);
|
||||
dumpObject("Loaded plugins:",$tw.plugins.moduleTypes);
|
||||
dumpObject("Command plugins:",$tw.commands);
|
||||
dumpObject("Parser plugins:",$tw.wiki.parsers);
|
||||
dumpObject("Macro plugins:",$tw.wiki.macros);
|
||||
dumpObject("Deserializer plugins:",$tw.Wiki.tiddlerDeserializerPlugins);
|
||||
return null; // No error
|
||||
};
|
||||
|
||||
exports.Command = Command;
|
||||
|
||||
})();
|
||||
@@ -0,0 +1,56 @@
|
||||
/*\
|
||||
title: $:/core/modules/commands/load.js
|
||||
type: application/javascript
|
||||
module-type: command
|
||||
|
||||
Load tiddlers command
|
||||
|
||||
\*/
|
||||
(function(){
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
exports.info = {
|
||||
name: "load",
|
||||
synchronous: false
|
||||
};
|
||||
|
||||
var Command = function(params,commander,callback) {
|
||||
this.params = params;
|
||||
this.commander = commander;
|
||||
this.callback = callback;
|
||||
};
|
||||
|
||||
Command.prototype.execute = function() {
|
||||
var self = this,
|
||||
fs = require("fs"),
|
||||
path = require("path");
|
||||
if(this.params.length < 1) {
|
||||
return "Missing filename";
|
||||
}
|
||||
fs.readFile(this.params[0],"utf8",function(err,data) {
|
||||
if(err) {
|
||||
self.callback(err);
|
||||
} else {
|
||||
var fields = {title: self.params[0]},
|
||||
extname = path.extname(self.params[0]),
|
||||
type = extname === ".html" ? "application/x-tiddlywiki" : extname;
|
||||
var tiddlers = self.commander.wiki.deserializeTiddlers(type,data,fields);
|
||||
if(!tiddlers) {
|
||||
self.callback("No tiddlers found in file \"" + self.params[0] + "\"");
|
||||
} else {
|
||||
for(var t=0; t<tiddlers.length; t++) {
|
||||
self.commander.wiki.addTiddler(new $tw.Tiddler(tiddlers[t]));
|
||||
}
|
||||
self.callback(null);
|
||||
}
|
||||
}
|
||||
});
|
||||
return null;
|
||||
};
|
||||
|
||||
exports.Command = Command;
|
||||
|
||||
})();
|
||||
@@ -0,0 +1,44 @@
|
||||
/*\
|
||||
title: $:/core/modules/commands/savetiddler.js
|
||||
type: application/javascript
|
||||
module-type: command
|
||||
|
||||
Save tiddlers command
|
||||
|
||||
\*/
|
||||
(function(){
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
exports.info = {
|
||||
name: "savetiddler",
|
||||
synchronous: false
|
||||
};
|
||||
|
||||
var Command = function(params,commander,callback) {
|
||||
this.params = params;
|
||||
this.commander = commander;
|
||||
this.callback = callback;
|
||||
};
|
||||
|
||||
Command.prototype.execute = function() {
|
||||
if(this.params.length < 2) {
|
||||
return "Missing filename";
|
||||
}
|
||||
var self = this,
|
||||
fs = require("fs"),
|
||||
path = require("path"),
|
||||
title = this.params[0],
|
||||
filename = this.params[1],
|
||||
type = this.params[2] || "text/html";
|
||||
fs.writeFile(filename,this.commander.wiki.renderTiddler(type,title),"utf8",function(err) {
|
||||
self.callback(err);
|
||||
});
|
||||
return null;
|
||||
};
|
||||
|
||||
exports.Command = Command;
|
||||
|
||||
})();
|
||||
@@ -0,0 +1,32 @@
|
||||
/*\
|
||||
title: $:/core/modules/commands/verbose.js
|
||||
type: application/javascript
|
||||
module-type: command
|
||||
|
||||
Verbose command
|
||||
|
||||
\*/
|
||||
(function(){
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
exports.info = {
|
||||
name: "verbose",
|
||||
synchronous: true
|
||||
};
|
||||
|
||||
var Command = function(params,commander) {
|
||||
this.params = params;
|
||||
this.commander = commander;
|
||||
};
|
||||
|
||||
Command.prototype.execute = function() {
|
||||
this.commander.verbose = true;
|
||||
return null; // No error
|
||||
};
|
||||
|
||||
exports.Command = Command;
|
||||
|
||||
})();
|
||||
@@ -0,0 +1,32 @@
|
||||
/*\
|
||||
title: $:/core/modules/commands/version.js
|
||||
type: application/javascript
|
||||
module-type: command
|
||||
|
||||
Version command
|
||||
|
||||
\*/
|
||||
(function(){
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
exports.info = {
|
||||
name: "version",
|
||||
synchronous: true
|
||||
};
|
||||
|
||||
var Command = function(params,commander) {
|
||||
this.params = params;
|
||||
this.commander = commander;
|
||||
};
|
||||
|
||||
Command.prototype.execute = function() {
|
||||
this.commander.streams.output.write($tw.utils.getVersionString() + "\n");
|
||||
return null; // No error
|
||||
};
|
||||
|
||||
exports.Command = Command;
|
||||
|
||||
})();
|
||||
@@ -0,0 +1,74 @@
|
||||
/*\
|
||||
title: $:/core/modules/commands/wikitest.js
|
||||
type: application/javascript
|
||||
module-type: command
|
||||
|
||||
wikitest command
|
||||
|
||||
\*/
|
||||
(function(){
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
exports.info = {
|
||||
name: "wikitest",
|
||||
synchronous: true
|
||||
};
|
||||
|
||||
var Command = function(params,commander) {
|
||||
this.params = params;
|
||||
this.commander = commander;
|
||||
};
|
||||
|
||||
Command.prototype.execute = function() {
|
||||
if(this.params.length <1) {
|
||||
return "Missing parameters";
|
||||
}
|
||||
var fs = require("fs"),
|
||||
path = require("path"),
|
||||
testdirectory = this.params[0],
|
||||
saveResults = this.params[1] === "save",
|
||||
files = fs.readdirSync(testdirectory),
|
||||
titles = [],
|
||||
f,t,extname,basename;
|
||||
for(f=0; f<files.length; f++) {
|
||||
extname = path.extname(files[f]);
|
||||
if(extname === ".tid") {
|
||||
var tiddlers = this.commander.wiki.deserializeTiddlers(extname,fs.readFileSync(path.resolve(testdirectory,files[f]),"utf8"));
|
||||
if(tiddlers.length > 1) {
|
||||
throw "Cannot use .JSON files";
|
||||
}
|
||||
this.commander.wiki.addTiddler(new $tw.Tiddler(tiddlers[0]));
|
||||
titles.push(tiddlers[0].title);
|
||||
}
|
||||
}
|
||||
for(t=0; t<titles.length; t++) {
|
||||
var htmlFilename = path.resolve(testdirectory,titles[t] + ".html"),
|
||||
plainFilename = path.resolve(testdirectory,titles[t] + ".txt"),
|
||||
htmlTarget = fs.readFileSync(htmlFilename,"utf8"),
|
||||
plainTarget = fs.readFileSync(plainFilename,"utf8"),
|
||||
tiddler = this.commander.wiki.getTiddler(titles[t]),
|
||||
htmlRender = this.commander.wiki.renderTiddler("text/html",titles[t]),
|
||||
plainRender = this.commander.wiki.renderTiddler("text/plain",titles[t]);
|
||||
if(saveResults) {
|
||||
// Save results
|
||||
fs.writeFileSync(htmlFilename,htmlRender,"utf8");
|
||||
fs.writeFileSync(plainFilename,plainRender,"utf8");
|
||||
} else {
|
||||
// Report results
|
||||
if(htmlTarget !== htmlRender) {
|
||||
this.commander.streams.output.write("Tiddler " + titles[t] + " html error\nTarget: " + htmlTarget + "\nFound: " + htmlRender +"\n");
|
||||
}
|
||||
if(plainTarget !== plainRender) {
|
||||
this.commander.streams.output.write("Tiddler " + titles[t] + " plain text error\nTarget: " + plainTarget + "\nFound: " + plainRender + "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
return null; // No error
|
||||
};
|
||||
|
||||
exports.Command = Command;
|
||||
|
||||
})();
|
||||
Reference in New Issue
Block a user