Extend render command to allow multiple variables to be passed

publishing-framework
jeremy@jermolene.com 2021-03-19 17:09:53 +00:00
rodzic 9af68297cd
commit a38dc17300
2 zmienionych plików z 8 dodań i 7 usunięć

Wyświetl plik

@ -8,15 +8,15 @@ Optionally, the title of a template tiddler can be specified. In this case, inst
A name and value for an additional variable may optionally also be specified.
```
--render <tiddler-filter> [<filename-filter>] [<render-type>] [<template>] [<name>] [<value>]
--render <tiddler-filter> [<filename-filter>] [<render-type>] [<template>] [ [<name>] [<value>] ]*
```
* ''tiddler-filter'': A filter identifying the tiddler(s) to be rendered
* ''filename-filter'': Optional filter transforming tiddler titles into pathnames. If omitted, defaults to `[is[tiddler]addsuffix[.html]]`, which uses the unchanged tiddler title as the filename
* ''render-type'': Optional render type: `text/html` (the default) returns the full HTML text and `text/plain` just returns the text content (ie it ignores HTML tags and other unprintable material)
* ''template'': Optional template through which each tiddler is rendered
* ''name'': Name of optional variable
* ''value'': Value of optional variable
* ''name'': Name of optional variables
* ''value'': Value of optional variables
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.
@ -26,6 +26,7 @@ Notes:
* Any missing directories in the path to the filename are automatically created.
* When referring to a tiddler with spaces in its title, take care to use both the quotes required by your shell and also TiddlyWiki's double square brackets : `--render "[[Motovun Jack.jpg]]"`
* The filename filter is evaluated with the selected items being set to the title of the tiddler currently being rendered, allowing the title to be used as the basis for computing the filename. For example `[encodeuricomponent[]addprefix[static/]]` applies URI encoding to each title, and then adds the prefix `static/`
* Multiple ''name''/''value'' pairs can be used to pass more than one variable
* The `--render` command is a more flexible replacement for both the `--rendertiddler` and `--rendertiddlers` commands, which are deprecated
Examples:

Wyświetl plik

@ -37,14 +37,14 @@ Command.prototype.execute = function() {
filenameFilter = this.params[1] || "[is[tiddler]addsuffix[.html]]",
type = this.params[2] || "text/html",
template = this.params[3],
varName = this.params[4],
varValue = this.params[5],
variableList = this.params.slice(4),
tiddlers = wiki.filterTiddlers(tiddlerFilter);
$tw.utils.each(tiddlers,function(title) {
var parser = wiki.parseTiddler(template || title),
variables = {currentTiddler: title};
if(varName) {
variables[varName] = varValue || "";
while(variableList.length >= 2) {
variables[variableList[0]] = variableList[1];
variableList = variableList.slice(2);
}
var widgetNode = wiki.makeWidget(parser,{variables: variables}),
container = $tw.fakeDocument.createElement("div");