2013-03-04 18:15:54 +00:00
|
|
|
/*\
|
2013-08-04 21:26:45 +00:00
|
|
|
title: $:/core/modules/commands/rendertiddlers.js
|
2013-03-04 18:15:54 +00:00
|
|
|
type: application/javascript
|
|
|
|
module-type: command
|
|
|
|
|
2013-08-04 21:26:45 +00:00
|
|
|
Command to render several tiddlers to a folder of files
|
2013-03-04 18:15:54 +00:00
|
|
|
|
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
|
|
|
/*jslint node: true, browser: true */
|
|
|
|
/*global $tw: false */
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
exports.info = {
|
2013-08-04 21:26:45 +00:00
|
|
|
name: "rendertiddlers",
|
2013-08-04 21:02:19 +00:00
|
|
|
synchronous: true
|
2013-03-04 18:15:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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],
|
|
|
|
pathname = this.params[2],
|
|
|
|
type = this.params[3] || "text/html",
|
|
|
|
extension = this.params[4] || ".html",
|
|
|
|
parser = wiki.parseTiddler(template),
|
|
|
|
tiddlers = wiki.filterTiddlers(filter);
|
|
|
|
$tw.utils.each(tiddlers,function(title) {
|
2013-05-17 09:12:25 +00:00
|
|
|
var renderTree = new $tw.WikiRenderTree(parser,{wiki: wiki, context: {tiddlerTitle: title}, document: $tw.document});
|
2013-05-15 16:32:17 +00:00
|
|
|
renderTree.execute();
|
2013-05-17 09:12:25 +00:00
|
|
|
var container = $tw.document.createElement("div");
|
|
|
|
renderTree.renderInDom(container);
|
|
|
|
var text = type === "text/html" ? container.innerHTML : container.textContent;
|
2013-03-18 22:16:01 +00:00
|
|
|
fs.writeFileSync(path.resolve(pathname,encodeURIComponent(title) + extension),text,"utf8");
|
2013-03-04 18:15:54 +00:00
|
|
|
});
|
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.Command = Command;
|
|
|
|
|
|
|
|
})();
|