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",
|
2015-01-11 17:55:42 +00:00
|
|
|
deleteDirectory = (this.params[5] || "") != "noclean",
|
2013-10-21 17:33:00 +00:00
|
|
|
tiddlers = wiki.filterTiddlers(filter);
|
2015-01-11 17:55:42 +00:00
|
|
|
if(deleteDirectory){
|
2015-01-10 21:44:56 +00:00
|
|
|
$tw.utils.deleteDirectory(pathname);
|
|
|
|
}
|
2014-04-25 21:41:59 +00:00
|
|
|
$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;
|
|
|
|
|
|
|
|
})();
|