2013-10-12 16:05:13 +00:00
|
|
|
/*\
|
2013-11-08 08:51:14 +00:00
|
|
|
title: $:/core/modules/commands/rendertiddler.js
|
2013-10-12 16:05:13 +00:00
|
|
|
type: application/javascript
|
|
|
|
module-type: command
|
|
|
|
|
|
|
|
Command to render a tiddler and save it to a file
|
|
|
|
|
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
|
|
|
/*jslint node: true, browser: true */
|
|
|
|
/*global $tw: false */
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
exports.info = {
|
2013-11-08 08:51:14 +00:00
|
|
|
name: "rendertiddler",
|
2013-10-12 16:05:13 +00:00
|
|
|
synchronous: false
|
|
|
|
};
|
|
|
|
|
|
|
|
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"),
|
|
|
|
title = this.params[0],
|
2014-04-25 21:41:59 +00:00
|
|
|
filename = path.resolve(this.commander.outputPath,this.params[1]),
|
2015-09-03 07:53:08 +00:00
|
|
|
type = this.params[2] || "text/html",
|
|
|
|
template = this.params[3],
|
|
|
|
variables = {};
|
2014-04-25 21:41:59 +00:00
|
|
|
$tw.utils.createFileDirectories(filename);
|
2015-09-03 07:53:08 +00:00
|
|
|
if(template) {
|
|
|
|
variables.currentTiddler = title;
|
|
|
|
title = template;
|
|
|
|
}
|
|
|
|
fs.writeFile(filename,this.commander.wiki.renderTiddler(type,title,{variables: variables}),"utf8",function(err) {
|
2013-10-12 16:05:13 +00:00
|
|
|
self.callback(err);
|
|
|
|
});
|
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.Command = Command;
|
|
|
|
|
|
|
|
})();
|