2012-05-02 14:02:58 +00:00
|
|
|
/*\
|
2012-05-03 20:47:16 +00:00
|
|
|
title: $:/core/modules/commands/dump.js
|
2012-05-02 14:02:58 +00:00
|
|
|
type: application/javascript
|
|
|
|
module-type: command
|
|
|
|
|
2012-05-19 17:23:14 +00:00
|
|
|
Dump command for inspecting TiddlyWiki internals
|
2012-05-02 14:02:58 +00:00
|
|
|
|
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
2012-05-04 17:49:04 +00:00
|
|
|
/*jshint node: true, browser: true */
|
|
|
|
/*global $tw: false */
|
2012-05-02 14:02:58 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
exports.info = {
|
|
|
|
name: "dump",
|
2012-05-02 16:26:36 +00:00
|
|
|
synchronous: true
|
2012-05-04 17:49:04 +00:00
|
|
|
};
|
2012-05-02 14:02:58 +00:00
|
|
|
|
|
|
|
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";
|
|
|
|
}
|
2012-05-04 17:49:04 +00:00
|
|
|
};
|
2012-05-02 14:02:58 +00:00
|
|
|
|
|
|
|
Command.prototype.subcommands = {};
|
|
|
|
|
2012-05-05 10:18:24 +00:00
|
|
|
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
|
|
|
|
};
|
2012-05-02 14:02:58 +00:00
|
|
|
|
|
|
|
Command.prototype.subcommands.tiddlers = function() {
|
2012-05-08 15:02:24 +00:00
|
|
|
var tiddlers = this.commander.wiki.getTiddlers();
|
2012-05-02 14:02:58 +00:00
|
|
|
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() {
|
2012-06-06 11:07:33 +00:00
|
|
|
var tiddlers = this.commander.wiki.getShadowTitles();
|
2012-05-02 14:02:58 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
})();
|