2013-10-21 17:33:00 +00:00
|
|
|
/*\
|
2013-11-08 08:51:14 +00:00
|
|
|
title: $:/core/modules/commands/rendertiddlers.js
|
2013-10-21 17:33:00 +00:00
|
|
|
type: application/javascript
|
|
|
|
module-type: command
|
|
|
|
|
|
|
|
Command to render several tiddlers to a folder of files
|
|
|
|
|
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
|
|
|
/*jslint node: true, browser: true */
|
|
|
|
/*global $tw: false */
|
|
|
|
"use strict";
|
|
|
|
|
2013-11-08 08:47:00 +00:00
|
|
|
var widget = require("$:/core/modules/widgets/widget.js");
|
2013-10-21 17:33:00 +00:00
|
|
|
|
|
|
|
exports.info = {
|
2013-11-08 08:51:14 +00:00
|
|
|
name: "rendertiddlers",
|
2013-10-21 17:33:00 +00:00
|
|
|
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 < 2) {
|
|
|
|
return "Missing filename";
|
|
|
|
}
|
|
|
|
var self = this,
|
|
|
|
fs = require("fs"),
|
|
|
|
path = require("path"),
|
|
|
|
wiki = this.commander.wiki,
|
|
|
|
filter = this.params[0],
|
|
|
|
template = this.params[1],
|
2014-04-25 21:41:59 +00:00
|
|
|
pathname = path.resolve(this.commander.outputPath,this.params[2]),
|
2013-10-21 17:33:00 +00:00
|
|
|
type = this.params[3] || "text/html",
|
|
|
|
extension = this.params[4] || ".html",
|
|
|
|
tiddlers = wiki.filterTiddlers(filter);
|
2014-04-25 21:41:59 +00:00
|
|
|
$tw.utils.deleteDirectory(pathname);
|
|
|
|
$tw.utils.createDirectory(pathname);
|
2013-10-21 17:33:00 +00:00
|
|
|
$tw.utils.each(tiddlers,function(title) {
|
2013-11-08 08:51:14 +00:00
|
|
|
var parser = wiki.parseTiddler(template),
|
2013-10-29 14:51:35 +00:00
|
|
|
widgetNode = wiki.makeWidget(parser,{variables: {currentTiddler: title}});
|
2014-01-15 14:57:35 +00:00
|
|
|
var container = $tw.fakeDocument.createElement("div");
|
2013-10-21 17:33:00 +00:00
|
|
|
widgetNode.render(container,null);
|
|
|
|
var text = type === "text/html" ? container.innerHTML : container.textContent;
|
|
|
|
fs.writeFileSync(path.resolve(pathname,encodeURIComponent(title) + extension),text,"utf8");
|
|
|
|
});
|
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.Command = Command;
|
|
|
|
|
|
|
|
})();
|