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
Copy file name to clipboardExpand all lines: Cookbook.md
+17-55Lines changed: 17 additions & 55 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,28 +1,23 @@
1
1
# Nancy Cookbook
2
2
3
-
See the [README](README.md) for installation and usage. The rest of this
4
-
document shows examples of its use.
3
+
See the [README](README.md) for installation and usage. The rest of this document shows examples of its use.
5
4
6
5
There are other projects that use Nancy, and further illustrate its use:
7
6
8
7
+[python-project-template](https://github.com/rrthomas/python-project-template) is a simple customizable Python project template
9
8
10
9
## Generating a web site <aname="website-example"></a>
11
10
12
-
*Note: the techniques used here, and more, are bundled into a convenient
13
-
tool that builds on Nancy, called
14
-
[Linton](https://rrthomas.github.io/linton).*
11
+
*Note: the techniques used here, and more, are bundled into a convenient tool that builds on Nancy, called [Linton](https://rrthomas.github.io/linton).*
15
12
16
13
Suppose a web site has the following page design:
17
14
18
15

19
16
20
-
Most of the elements are the same on each page, but the breadcrumb trail has
21
-
to show the canonical path to each page, and the logo is bigger on the home
17
+
Most of the elements are the same on each page, but the breadcrumb trail has to show the canonical path to each page, and the logo is bigger on the home
22
18
page, which is `index/index.html`.
23
19
24
-
Suppose further that the web site has the following structure, where each
25
-
line corresponds to a page:
20
+
Suppose further that the web site has the following structure, where each line corresponds to a page:
26
21
27
22
```
28
23
├── Home page
@@ -56,8 +51,7 @@ The basic page template looks something like this:
56
51
</html>
57
52
```
58
53
59
-
Making the menu an included file is not strictly necessary, but makes the
60
-
template easier to read. The pages will be laid out as follows:
54
+
Making the menu an included file is not strictly necessary, but makes the template easier to read. The pages will be laid out as follows:
61
55
62
56
```
63
57
├── index
@@ -81,9 +75,7 @@ template easier to read. The pages will be laid out as follows:
81
75
└── style.css
82
76
```
83
77
84
-
The corresponding source files are laid out as follows. This may look a
85
-
little confusing at first, but note the similarity to the HTML pages, and
86
-
hold on for the explanation!
78
+
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!
87
79
88
80
```
89
81
├── index
@@ -133,41 +125,23 @@ hold on for the explanation!
133
125
└── template.in.html
134
126
```
135
127
136
-
Note that there is only one menu fragment (the main menu is the same for
137
-
every page), while each section has its own breadcrumb trail
138
-
(`breadcrumb.in.html`), and each page has its own content
139
-
(`main.in.html`).
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`).
140
129
141
-
Now consider how Nancy builds the page whose URL is
142
-
`Places/Vladivostok/index.html`. Assume the source files are in the
143
-
directory `source`. This page is built from
144
-
`source/Places/Vladivostok/index.nancy.html`, whose contents is
145
-
`$include{template.in.html}`. According to the rules given in the
146
-
[Operation](README.md#operation) section of the manual, Nancy will look
147
-
first for files in `source/Places/Vladivostok`, then in `source/places`, and
148
-
finally in `source`. Hence, the actual list of files used to assemble the
149
-
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:
150
131
151
132
152
133
153
-
For the site’s index page, the file `index/logo.in.html` will be used for the
154
-
logo fragment, which can refer to the larger graphic desired.
134
+
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.
155
135
156
-
The `breadcrumb.in.html` fragments, except for the top-level one, contain the
157
-
command
136
+
The `breadcrumb.in.html` fragments, except for the top-level one, contain the command
158
137
159
138
```
160
139
$include{breadcrumb.in.html}
161
140
```
162
141
163
-
When expanding `source/Places/breadcrumb.in.html`, Nancy ignores that file,
164
-
since it is already expanding it, and goes straight to
165
-
`source/breadcrumb.in.html`. This means that the breadcrumb trail can be
166
-
defined recursively: each `breadcrumb.in.html` fragment includes all those
167
-
above it in the source tree.
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.
168
143
169
-
This scheme, though simple, is surprisingly flexible; this example has
170
-
covered all the standard techniques for Nancy’s use.
144
+
This scheme, though simple, is surprisingly flexible; this example has covered all the techniques most users will ever need.
171
145
172
146
### Building the site
173
147
@@ -226,27 +200,15 @@ Then, you can use `$include{printenv,VARIABLE1}` (or the equivalent in Python or
226
200
227
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}`.
228
202
229
-
The output of commands can similarly be included in documents. The output of
230
-
terminal commands may be better included in a code block, to preserve
231
-
formatting that depends on a fixed-width font.
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.
232
204
233
-
Look at the [source](Cookbook.nancy.md) for the Cookbook for more examples
234
-
of these techniques, including the use of `sed` and `grep` to filter the
235
-
contents of files and output of commands.
205
+
Look at the [source](Cookbook.nancy.md) for the Cookbook for more examples of these techniques, including the use of `sed` and `grep` to filter the contents of files and output of commands.
236
206
237
207
## Creating binary files in the output
238
208
239
-
Nancy is mostly intended for templating text files. Sometimes, we would like
240
-
to create binary files, for example an image containing context-dependent
241
-
text. In theory, one could use `$paste` to do this, but since any trailing
242
-
newline is stripped from the output, this is not a good technique in
243
-
general. Also, it may be desirable to create binary files based on other
244
-
outputs. This can be achieved by using the `$realpath` command to construct
245
-
a filename in the output directory, and a `.in.nancy` file to run commands
246
-
without creating a file in the output directory.
247
-
248
-
The following script, given a directory on the command line, creates a Zip
249
-
file of a directory in that directory:
209
+
Nancy is mostly intended for templating text files. Sometimes, we would like to create binary files, for example an image containing context-dependent text. In theory, one could use `$paste` to do this, but since any trailing newline is stripped from the output, this is not a good technique in general. Also, it may be desirable to create binary files based on other outputs. This can be achieved by using the `$realpath` command to construct a filename in the output directory, and a `.in.nancy` file to run commands without creating a file in the output directory.
210
+
211
+
The following script, given a directory on the command line, creates a Zip file of a directory in that directory:
Copy file name to clipboardExpand all lines: Cookbook.nancy.md
+17-55Lines changed: 17 additions & 55 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,28 +1,23 @@
1
1
# Nancy Cookbook
2
2
3
-
See the [README](README.md) for installation and usage. The rest of this
4
-
document shows examples of its use.
3
+
See the [README](README.md) for installation and usage. The rest of this document shows examples of its use.
5
4
6
5
There are other projects that use Nancy, and further illustrate its use:
7
6
8
7
+[python-project-template](https://github.com/rrthomas/python-project-template) is a simple customizable Python project template
9
8
10
9
## Generating a web site <aname="website-example"></a>
11
10
12
-
*Note: the techniques used here, and more, are bundled into a convenient
13
-
tool that builds on Nancy, called
14
-
[Linton](https://rrthomas.github.io/linton).*
11
+
*Note: the techniques used here, and more, are bundled into a convenient tool that builds on Nancy, called [Linton](https://rrthomas.github.io/linton).*
15
12
16
13
Suppose a web site has the following page design:
17
14
18
15

19
16
20
-
Most of the elements are the same on each page, but the breadcrumb trail has
21
-
to show the canonical path to each page, and the logo is bigger on the home
17
+
Most of the elements are the same on each page, but the breadcrumb trail has to show the canonical path to each page, and the logo is bigger on the home
22
18
page, which is `index/index.html`.
23
19
24
-
Suppose further that the web site has the following structure, where each
25
-
line corresponds to a page:
20
+
Suppose further that the web site has the following structure, where each line corresponds to a page:
26
21
27
22
```
28
23
├── Home page
@@ -35,56 +30,35 @@ The basic page template looks something like this:
The corresponding source files are laid out as follows. This may look a
46
-
little confusing at first, but note the similarity to the HTML pages, and
47
-
hold on for the explanation!
39
+
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
54
-
every page), while each section has its own breadcrumb trail
55
-
(`breadcrumb.in.html`), and each page has its own content
56
-
(`main.in.html`).
45
+
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`).
57
46
58
-
Now consider how Nancy builds the page whose URL is
59
-
`Places/Vladivostok/index.html`. Assume the source files are in the
60
-
directory `source`. This page is built from
61
-
`source/Places/Vladivostok/index.nancy.html`, whose contents is
62
-
`$paste{cat,tests/test-files/cookbook-example-website-src/Places/Vladivostok/index.nancy.html}`. According to the rules given in the
63
-
[Operation](README.md#operation) section of the manual, Nancy will look
64
-
first for files in `source/Places/Vladivostok`, then in `source/places`, and
65
-
finally in `source`. Hence, the actual list of files used to assemble the
66
-
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 `$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:
For the site’s index page, the file `index/logo.in.html` will be used for the
71
-
logo fragment, which can refer to the larger graphic desired.
51
+
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.
72
52
73
-
The `breadcrumb.in.html` fragments, except for the top-level one, contain the
74
-
command
53
+
The `breadcrumb.in.html` fragments, except for the top-level one, contain the command
75
54
76
55
```
77
56
\$include{breadcrumb.in.html}
78
57
```
79
58
80
-
When expanding `source/Places/breadcrumb.in.html`, Nancy ignores that file,
81
-
since it is already expanding it, and goes straight to
82
-
`source/breadcrumb.in.html`. This means that the breadcrumb trail can be
83
-
defined recursively: each `breadcrumb.in.html` fragment includes all those
84
-
above it in the source tree.
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.
85
60
86
-
This scheme, though simple, is surprisingly flexible; this example has
87
-
covered all the standard techniques for Nancy’s use.
61
+
This scheme, though simple, is surprisingly flexible; this example has covered all the techniques most users will ever need.
88
62
89
63
### Building the site
90
64
@@ -131,27 +105,15 @@ Then, you can use `\$include{printenv,VARIABLE1}` (or the equivalent in Python o
131
105
132
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}`.
133
107
134
-
The output of commands can similarly be included in documents. The output of
135
-
terminal commands may be better included in a code block, to preserve
136
-
formatting that depends on a fixed-width font.
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.
137
109
138
-
Look at the [source](Cookbook.nancy.md) for the Cookbook for more examples
139
-
of these techniques, including the use of `sed` and `grep` to filter the
140
-
contents of files and output of commands.
110
+
Look at the [source](Cookbook.nancy.md) for the Cookbook for more examples of these techniques, including the use of `sed` and `grep` to filter the contents of files and output of commands.
141
111
142
112
## Creating binary files in the output
143
113
144
-
Nancy is mostly intended for templating text files. Sometimes, we would like
145
-
to create binary files, for example an image containing context-dependent
146
-
text. In theory, one could use `\$paste` to do this, but since any trailing
147
-
newline is stripped from the output, this is not a good technique in
148
-
general. Also, it may be desirable to create binary files based on other
149
-
outputs. This can be achieved by using the `\$realpath` command to construct
150
-
a filename in the output directory, and a `.in.nancy` file to run commands
151
-
without creating a file in the output directory.
152
-
153
-
The following script, given a directory on the command line, creates a Zip
154
-
file of a directory in that directory:
114
+
Nancy is mostly intended for templating text files. Sometimes, we would like to create binary files, for example an image containing context-dependent text. In theory, one could use `\$paste` to do this, but since any trailing newline is stripped from the output, this is not a good technique in general. Also, it may be desirable to create binary files based on other outputs. This can be achieved by using the `\$realpath` command to construct a filename in the output directory, and a `.in.nancy` file to run commands without creating a file in the output directory.
115
+
116
+
The following script, given a directory on the command line, creates a Zip file of a directory in that directory:
0 commit comments