Skip to content

Commit db3b0df

Browse files
committed
Soft-wrap the Cookbook
1 parent acef997 commit db3b0df

File tree

2 files changed

+34
-110
lines changed

2 files changed

+34
-110
lines changed

Cookbook.md

Lines changed: 17 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,23 @@
11
# Nancy Cookbook
22

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.
54

65
There are other projects that use Nancy, and further illustrate its use:
76

87
+ [python-project-template](https://github.com/rrthomas/python-project-template) is a simple customizable Python project template
98

109
## Generating a web site <a name="website-example"></a>
1110

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).*
1512

1613
Suppose a web site has the following page design:
1714

1815
![from top to bottom: logo, breadcrumb trail, navigation menu, page body](website.svg)
1916

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
2218
page, which is `index/index.html`.
2319

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:
2621

2722
```
2823
├── Home page
@@ -56,8 +51,7 @@ The basic page template looks something like this:
5651
</html>
5752
```
5853

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:
6155

6256
```
6357
├── index
@@ -81,9 +75,7 @@ template easier to read. The pages will be laid out as follows:
8175
└── style.css
8276
```
8377

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!
8779

8880
```
8981
├── index
@@ -133,41 +125,23 @@ hold on for the explanation!
133125
└── template.in.html
134126
```
135127

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`).
140129

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:
150131

151132

152133

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.
155135

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
158137

159138
```
160139
$include{breadcrumb.in.html}
161140
```
162141

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.
168143

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.
171145

172146
### Building the site
173147

@@ -226,27 +200,15 @@ Then, you can use `$include{printenv,VARIABLE1}` (or the equivalent in Python or
226200

227201
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}`.
228202

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.
232204

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.
236206

237207
## Creating binary files in the output
238208

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:
250212

251213
```
252214
#!/bin/sh

Cookbook.nancy.md

Lines changed: 17 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,23 @@
11
# Nancy Cookbook
22

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.
54

65
There are other projects that use Nancy, and further illustrate its use:
76

87
+ [python-project-template](https://github.com/rrthomas/python-project-template) is a simple customizable Python project template
98

109
## Generating a web site <a name="website-example"></a>
1110

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).*
1512

1613
Suppose a web site has the following page design:
1714

1815
![from top to bottom: logo, breadcrumb trail, navigation menu, page body](website.svg)
1916

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
2218
page, which is `index/index.html`.
2319

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:
2621

2722
```
2823
├── Home page
@@ -35,56 +30,35 @@ The basic page template looks something like this:
3530
$paste{cat,tests/test-files/cookbook-example-website-src/template.in.html}
3631
```
3732

38-
Making the menu an included file is not strictly necessary, but makes the
39-
template easier to read. The pages will be laid out as follows:
33+
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:
4034

4135
```
4236
$paste{build-aux/dirtree,tests/test-files/cookbook-example-website-expected}
4337
```
4438

45-
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!
4840

4941
```
5042
$paste{build-aux/dirtree,tests/test-files/cookbook-example-website-src}
5143
```
5244

53-
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`).
5746

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:
6748

6849
$paste{env,NANCY_TMPDIR=/tmp/cookbook-dest.$$,sh,-c,rm -rf ${NANCY_TMPDIR} && DEBUG="*" PYTHONPATH=. python -m nancy --path Places/Vladivostok tests/test-files/cookbook-example-website-src ${NANCY_TMPDIR} 2>&1 | grep Found | cut -d " " -f 4 | sort | uniq | sed -e 's|^'\''tests/test-files/cookbook-example-website-src\(.*\)'\''$|* `source\1`|' && rm -rf ${NANCY_TMPDIR}}
6950

70-
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.
7252

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
7554

7655
```
7756
\$include{breadcrumb.in.html}
7857
```
7958

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.
8560

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.
8862

8963
### Building the site
9064

@@ -131,27 +105,15 @@ Then, you can use `\$include{printenv,VARIABLE1}` (or the equivalent in Python o
131105

132106
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}`.
133107

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.
137109

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.
141111

142112
## Creating binary files in the output
143113

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:
155117

156118
```
157119
#!/bin/sh

0 commit comments

Comments
 (0)