diff --git a/core/language/en-GB/Help/savetiddlers.tid b/core/language/en-GB/Help/savetiddlers.tid new file mode 100644 index 000000000..56c094d2d --- /dev/null +++ b/core/language/en-GB/Help/savetiddlers.tid @@ -0,0 +1,12 @@ +title: $:/language/Help/savetiddlers +description: Saves a raw tiddler to a file + +Saves a group of tiddlers in their raw text or binary format to the specified directory. + +``` +--savetiddlers +``` + +By default, the filename is resolved relative to the `output` subdirectory of the edition directory. The `--output` command can be used to direct output to a different directory. + +Any missing directories in the pathname are automatically created. diff --git a/core/modules/commands/savetiddlers.js b/core/modules/commands/savetiddlers.js new file mode 100644 index 000000000..e7bd9e901 --- /dev/null +++ b/core/modules/commands/savetiddlers.js @@ -0,0 +1,53 @@ +/*\ +title: $:/core/modules/commands/savetiddlers.js +type: application/javascript +module-type: command + +Command to save several tiddlers to a folder of files + +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +var widget = require("$:/core/modules/widgets/widget.js"); + +exports.info = { + name: "savetiddlers", + synchronous: true +}; + +var Command = function(params,commander,callback) { + this.params = params; + this.commander = commander; + this.callback = callback; +}; + +Command.prototype.execute = function() { + if(this.params.length < 1) { + return "Missing filename"; + } + var self = this, + fs = require("fs"), + path = require("path"), + wiki = this.commander.wiki, + filter = this.params[0], + pathname = path.resolve(this.commander.outputPath,this.params[1]), + tiddlers = wiki.filterTiddlers(filter); + $tw.utils.deleteDirectory(pathname); + $tw.utils.createDirectory(pathname); + $tw.utils.each(tiddlers,function(title) { + var tiddler = self.commander.wiki.getTiddler(title), + type = tiddler.fields.type || "text/vnd.tiddlywiki", + contentTypeInfo = $tw.config.contentTypeInfo[type] || {encoding: "utf8"}, + filename = path.resolve(pathname,encodeURIComponent(title)); + fs.writeFileSync(filename,tiddler.fields.text,contentTypeInfo.encoding); + }); + return null; +}; + +exports.Command = Command; + +})(); diff --git a/editions/tw5.com/tiddlers/commands/SaveTiddlersCommand.tid b/editions/tw5.com/tiddlers/commands/SaveTiddlersCommand.tid new file mode 100644 index 000000000..dd887c541 --- /dev/null +++ b/editions/tw5.com/tiddlers/commands/SaveTiddlersCommand.tid @@ -0,0 +1,6 @@ +title: SaveTiddlersCommand +tags: command +created: 20140609121606089 +modified: 20140609121606089 + +{{$:/language/Help/savetiddler}}