mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-02-03 20:59:09 +00:00
Enhance rendertiddler command with support for additional variable
Passing an arbitrary variable allows us to e.g. reuse the export filters as shown in the example
This commit is contained in:
parent
91b341e8e0
commit
6f93ce6ea7
@ -1,12 +1,22 @@
|
||||
title: $:/language/Help/rendertiddler
|
||||
description: Render an individual tiddler as a specified ContentType
|
||||
|
||||
Render an individual tiddler as a specified ContentType, defaulting to `text/html` and save it to the specified filename. Optionally a template can be specified, in which case the template tiddler is rendered with the "currentTiddler" variable set to the tiddler that is being rendered (the first parameter value).
|
||||
Render an individual tiddler as a specified ContentType, defaulting to `text/html` and save it to the specified filename.
|
||||
|
||||
Optionally the title of a template tiddler can be specified, in which case the template tiddler is rendered with the "currentTiddler" variable set to the tiddler that is being rendered (the first parameter value).
|
||||
|
||||
A name and value for an additional variable may optionally also be specified.
|
||||
|
||||
```
|
||||
--rendertiddler <title> <filename> [<type>] [<template>]
|
||||
--rendertiddler <title> <filename> [<type>] [<template>] [<name>] [<value>]
|
||||
```
|
||||
|
||||
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 path to the filename are automatically created.
|
||||
|
||||
For example, the following command saves all tiddlers matching the filter `[tag[done]]` to a JSON file titled `output.json` by employing the core template `$:/core/templates/exporters/JsonFile`.
|
||||
|
||||
```
|
||||
--rendertiddler "$:/core/templates/exporters/JsonFile" output.json text/plain "" exportFilter "[tag[done]]"
|
||||
```
|
||||
|
@ -34,12 +34,17 @@ Command.prototype.execute = function() {
|
||||
filename = path.resolve(this.commander.outputPath,this.params[1]),
|
||||
type = this.params[2] || "text/html",
|
||||
template = this.params[3],
|
||||
name = this.params[4],
|
||||
value = this.params[5],
|
||||
variables = {};
|
||||
$tw.utils.createFileDirectories(filename);
|
||||
if(template) {
|
||||
variables.currentTiddler = title;
|
||||
title = template;
|
||||
}
|
||||
if(name && value) {
|
||||
variables[name] = value;
|
||||
}
|
||||
fs.writeFile(filename,this.commander.wiki.renderTiddler(type,title,{variables: variables}),"utf8",function(err) {
|
||||
self.callback(err);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user