You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Rejig Nancy’s command set, in particular how it runs programs
Have a separate $run command, rather than allowing $include and $paste to
take external arguments. Add $expand to allow the output of $run to be
expanded.
@@ -127,7 +127,7 @@ The corresponding source files are laid out as follows. This may look a little c
127
127
128
128
Note that there is only one menu fragment (the main menu is the same for every page), while each section has its own breadcrumb trail (`breadcrumb.in.html`), and each page has its own content (`main.in.html`).
129
129
130
-
Now consider how Nancy builds the page whose URL is `Places/Vladivostok/index.html`. Assume the source files are in the directory `source`. This page is built from `source/Places/Vladivostok/index.nancy.html`, whose contents is `$include{template.in.html}`. According to the rules given in the [Operation](README.md#operation) section of the manual, Nancy will look first for files in `source/Places/Vladivostok`, then in `source/places`, and finally in `source`. Hence, the actual list of files used to assemble the page is:
130
+
Now consider how Nancy builds the page whose URL is `Places/Vladivostok/index.html`. Assume the source files are in the directory `source`. This page is built from `source/Places/Vladivostok/index.nancy.html`, whose contents is `$include(template.in.html)`. According to the rules given in the [Operation](README.md#operation) section of the manual, Nancy will look first for files in `source/Places/Vladivostok`, then in `source/places`, and finally in `source`. Hence, the actual list of files used to assemble the page is:
131
131
132
132
133
133
@@ -136,7 +136,7 @@ For the site’s index page, the file `index/logo.in.html` will be used for the
136
136
The `breadcrumb.in.html` fragments, except for the top-level one, contain the command
137
137
138
138
```
139
-
$include{breadcrumb.in.html}
139
+
$include(breadcrumb.in.html)
140
140
```
141
141
142
142
When expanding `source/Places/breadcrumb.in.html`, Nancy ignores that file, since it is already expanding it, and goes straight to `source/breadcrumb.in.html`. This means that the breadcrumb trail can be defined recursively: each `breadcrumb.in.html` fragment includes all those above it in the source tree.
@@ -163,7 +163,7 @@ Page contents.
163
163
164
164
--
165
165
166
-
Last updated: $paste(python,-c,import datetime; print(datetime.now().strftime('%Y-%m-%d')))
166
+
Last updated: $expand{$run(python,-c,import datetime; print(datetime.now().strftime('%Y-%m-%d')))}
167
167
```
168
168
169
169
This gives a result looking something like:
@@ -175,14 +175,14 @@ Page contents.
175
175
176
176
--
177
177
178
-
Last updated: $paste(python,-c,import datetime; print(datetime.datetime(2016\,10\,12).strftime('%Y-%m-%d')))
178
+
Last updated: $expand{$run(python,-c,import datetime; print(datetime.datetime(2016\,10\,12).strftime('%Y-%m-%d')))}
179
179
```
180
180
181
181
## Dynamically naming output files and directories according
182
182
183
183
Since output file and directory names are expanded from input names, you can use commands to determine the name of an output file or directory.
184
184
185
-
For example, given a file called `author.in.txt` containing the text `Jo Bloggs`, an input file in the same directory called `$include{author.in.txt}.txt` would be called `Jo Bloggs.txt` in the output.
185
+
For example, given a file called `author.in.txt` containing the text `Jo Bloggs`, an input file in the same directory called `$include(author.in.txt).txt` would be called `Jo Bloggs.txt` in the output.
186
186
187
187
## Dynamic customization
188
188
@@ -194,11 +194,11 @@ This can be done conveniently with environment variables, by invoking Nancy as f
194
194
env VARIABLE1=value1 VARIABLE2=value2 … nancy …
195
195
```
196
196
197
-
Then, you can use `$include(printenv,VARIABLE1)` (or the equivalent in Python or other languages) in the template files. [python-project-template](https://github.com/rrthomas/python-project-template) uses this technique to generate skeleton Python projects.
197
+
Then, you can use `$run(printenv,VARIABLE1)` (or the equivalent in Python or other languages) in the template files. [python-project-template](https://github.com/rrthomas/python-project-template) uses this technique to generate skeleton Python projects.
198
198
199
199
## Adding code examples and command output to Markdown
200
200
201
-
Source code examples can be added inline as normal in Markdown [code blocks](https://www.markdownguide.org/extended-syntax/#fenced-code-blocks), but it’s often more convenient to include code directly from a source file. This can be done directly with `$paste`, or you can use the `cat` command to include a file that is not in the Nancy input tree: `$paste(cat,/path/to/source.js)`.
201
+
Source code examples can be added inline as normal in Markdown [code blocks](https://www.markdownguide.org/extended-syntax/#fenced-code-blocks), but it’s often more convenient to include code directly from a source file. This can be done directly with `$paste`, or you can use the `cat` command to include a file that is not in the Nancy input tree: `$run(cat,/path/to/source.js)`.
202
202
203
203
The output of commands can similarly be included in documents. The output of terminal commands may be better included in a code block, to preserve formatting that depends on a fixed-width font.
204
204
@@ -219,5 +219,5 @@ zip -r archive.zip .
219
219
Assuming it is called `make-zip.in.sh`, it can be used thus, from a file called `make-zip.in.nancy`:
The corresponding source files are laid out as follows. This may look a little confusing at first, but note the similarity to the HTML pages, and hold on for the explanation!
Note that there is only one menu fragment (the main menu is the same for every page), while each section has its own breadcrumb trail (`breadcrumb.in.html`), and each page has its own content (`main.in.html`).
46
46
47
-
Now consider how Nancy builds the page whose URL is `Places/Vladivostok/index.html`. Assume the source files are in the directory `source`. This page is built from `source/Places/Vladivostok/index.nancy.html`, whose contents is `$paste(cat,tests/test-files/cookbook-example-website-src/Places/Vladivostok/index.nancy.html)`. According to the rules given in the [Operation](README.md#operation) section of the manual, Nancy will look first for files in `source/Places/Vladivostok`, then in `source/places`, and finally in `source`. Hence, the actual list of files used to assemble the page is:
47
+
Now consider how Nancy builds the page whose URL is `Places/Vladivostok/index.html`. Assume the source files are in the directory `source`. This page is built from `source/Places/Vladivostok/index.nancy.html`, whose contents is `$expand{$run(cat,tests/test-files/cookbook-example-website-src/Places/Vladivostok/index.nancy.html)}`. According to the rules given in the [Operation](README.md#operation) section of the manual, Nancy will look first for files in `source/Places/Vladivostok`, then in `source/places`, and finally in `source`. Hence, the actual list of files used to assemble the page is:
For the site’s index page, the file `index/logo.in.html` will be used for the logo fragment, which can refer to the larger graphic desired.
52
52
53
53
The `breadcrumb.in.html` fragments, except for the top-level one, contain the command
54
54
55
55
```
56
-
\$include{breadcrumb.in.html}
56
+
\$include(breadcrumb.in.html)
57
57
```
58
58
59
59
When expanding `source/Places/breadcrumb.in.html`, Nancy ignores that file, since it is already expanding it, and goes straight to `source/breadcrumb.in.html`. This means that the breadcrumb trail can be defined recursively: each `breadcrumb.in.html` fragment includes all those above it in the source tree.
@@ -74,20 +74,20 @@ Given a simple page template, a datestamp can be added by using the `date`
## Dynamically naming output files and directories according
87
87
88
88
Since output file and directory names are expanded from input names, you can use commands to determine the name of an output file or directory.
89
89
90
-
For example, given a file called `author.in.txt` containing the text `Jo Bloggs`, an input file in the same directory called `\$include{author.in.txt}.txt` would be called `Jo Bloggs.txt` in the output.
90
+
For example, given a file called `author.in.txt` containing the text `Jo Bloggs`, an input file in the same directory called `\$include(author.in.txt).txt` would be called `Jo Bloggs.txt` in the output.
91
91
92
92
## Dynamic customization
93
93
@@ -99,11 +99,11 @@ This can be done conveniently with environment variables, by invoking Nancy as f
99
99
env VARIABLE1=value1 VARIABLE2=value2 … nancy …
100
100
```
101
101
102
-
Then, you can use `\$include(printenv,VARIABLE1)` (or the equivalent in Python or other languages) in the template files. [python-project-template](https://github.com/rrthomas/python-project-template) uses this technique to generate skeleton Python projects.
102
+
Then, you can use `\$run(printenv,VARIABLE1)` (or the equivalent in Python or other languages) in the template files. [python-project-template](https://github.com/rrthomas/python-project-template) uses this technique to generate skeleton Python projects.
103
103
104
104
## Adding code examples and command output to Markdown
105
105
106
-
Source code examples can be added inline as normal in Markdown [code blocks](https://www.markdownguide.org/extended-syntax/#fenced-code-blocks), but it’s often more convenient to include code directly from a source file. This can be done directly with `\$paste`, or you can use the `cat` command to include a file that is not in the Nancy input tree: `\$paste(cat,/path/to/source.js)`.
106
+
Source code examples can be added inline as normal in Markdown [code blocks](https://www.markdownguide.org/extended-syntax/#fenced-code-blocks), but it’s often more convenient to include code directly from a source file. This can be done directly with `\$paste`, or you can use the `cat` command to include a file that is not in the Nancy input tree: `\$run(cat,/path/to/source.js)`.
107
107
108
108
The output of commands can similarly be included in documents. The output of terminal commands may be better included in a code block, to preserve formatting that depends on a fixed-width font.
109
109
@@ -124,5 +124,5 @@ zip -r archive.zip .
124
124
Assuming it is called `make-zip.in.sh`, it can be used thus, from a file called `make-zip.in.nancy`:
0 commit comments