nancy 8.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
nancy-8.0.0/PKG-INFO ADDED
@@ -0,0 +1,245 @@
1
+ Metadata-Version: 2.1
2
+ Name: nancy
3
+ Version: 8.0.0
4
+ Summary: Simple templating system
5
+ Author-email: Reuben Thomas <rrt@sc3d.org>
6
+ License: GPL v3 or later
7
+ Project-URL: Homepage, https://github.com/rrthomas/nancy
8
+ Classifier: Environment :: Console
9
+ Classifier: Programming Language :: Python :: 3
10
+ Requires-Python: >=3.9
11
+ Description-Content-Type: text/markdown
12
+ Provides-Extra: test
13
+ Requires-Dist: pytest; extra == "test"
14
+
15
+ # Nancy
16
+
17
+ ![logo](logo/nancy-small.png) _logo by Silvia Polverini_
18
+
19
+ © 2002–2024 Reuben Thomas <rrt@sc3d.org>
20
+ https://github.com/rrthomas/nancy
21
+
22
+ Nancy is a simple macro processor that copies a file or directory, filling
23
+ in templates as it goes. It has just one non-trivial construct:
24
+ context-dependent file inclusion. A file can either be included literally,
25
+ or run as a command and its output included.
26
+
27
+ Nancy was originally designed to build simple static web sites, but can be
28
+ used for all sorts of other tasks, similar to more complicated systems like
29
+ [AutoGen] and [TXR].
30
+
31
+ [AutoGen]: https://autogen.sourceforge.net
32
+ [TXR]: https://www.nongnu.org/txr
33
+
34
+ Nancy is free software, licensed under the GNU GPL version 3 (or, at your
35
+ option, any later version), and written in TypeScript.
36
+
37
+ See the [Cookbook](Cookbook.md) for examples.
38
+
39
+ Please send questions, comments, and bug reports to the maintainer, or
40
+ report them on the project’s web page (see above for addresses).
41
+
42
+ ## Installation
43
+
44
+ Install Nancy with pip (part of [Python](https://python.org)):
45
+
46
+ ```
47
+ $ pip install nancy
48
+ ```
49
+
50
+ ## Invocation
51
+
52
+ ```
53
+ nancy [-h] [--path PATH] [--version] INPUT-PATH OUTPUT
54
+
55
+ A simple templating system.
56
+
57
+ positional arguments:
58
+ INPUT-PATH list of input directories, or a single file
59
+ OUTPUT output directory, or file ('-' for stdout)
60
+
61
+ options:
62
+ -h, --help show this help message and exit
63
+ --path PATH path to build relative to input tree [default: '']
64
+ --version show program's version number and exit
65
+
66
+ The INPUT-PATH is a ':'-separated list; the inputs are merged
67
+ in left-to-right order.
68
+
69
+ OUTPUT cannot be in any input directory.
70
+ ```
71
+
72
+ ## Operation <a name="operation"></a>
73
+
74
+ Nancy starts by combining the list of inputs given as its _input path_. If
75
+ the same file or directory exists in more than one of the directories on the
76
+ input path, the left-most takes precedence. The result is called the “input
77
+ tree”, and all paths are relative to it.
78
+
79
+ Next, Nancy traverses the input tree, or the tree given by the `--path`
80
+ argument, if any, which is a relative path denoting a subtree of the
81
+ input tree.
82
+
83
+ For each directory in the input tree, Nancy creates a corresponding
84
+ directory, if it does not already exist.
85
+
86
+ For each file, Nancy looks at its name, and:
87
+
88
+ + If the name contains the suffix `.nancy`, the file’s contents is expanded
89
+ (see below), and the result is then written to a file of the same name,
90
+ but with `.nancy` removed, in the corresponding place in the output
91
+ directory.
92
+ + Else, if the name contains the suffix `.in`, the file is skipped. (It may
93
+ be used by macros in other files.)
94
+ + Otherwise, the file is copied verbatim to the corresponding place in the
95
+ output.
96
+
97
+ Files and directories in the output have the same name as in the input tree,
98
+ except for the root directory (or file), which is called `OUTPUT`.
99
+
100
+ The special suffixes need not end the file name; they can be used as infixes
101
+ before the file type suffix.
102
+
103
+ ### Special cases
104
+
105
+ + If the input path is a single file, and no `--path` argument is given,
106
+ then Nancy acts as if the input path were the current directory and the
107
+ `--path` argument were the file name. This makes it convenient to expand a
108
+ single file using the command: `nancy INPUT-FILE OUTPUT-FILE`
109
+ + When the output is a single file, the special filename `-` may be used to
110
+ cause Nancy to print the result to standard output instead of writing it to
111
+ a file.
112
+
113
+ ### Template expansion
114
+
115
+ Nancy expands a template file as follows:
116
+
117
+ 1. Scan the text for commands. Expand any arguments to the command, run each
118
+ command, and replace the command by the result, eliding any final
119
+ newline. (This elision may look tricky, but it almost always does what
120
+ you want, and makes `$include` behave better in various contexts.)
121
+ 2. Output the resultant text.
122
+
123
+ A command takes the form `$COMMAND` or `$COMMAND{ARGUMENT, ...}`.
124
+
125
+ ### Built-in commands
126
+
127
+ Nancy recognises these commands:
128
+
129
+ * *`$include{FILE}`* Look up the given source file in the input tree (see
130
+ below); read its contents, then expand them (that is, execute any commands
131
+ it contains) and return the result.
132
+ * *`$paste{FILE}`* Like `$include`, but does not expand its result before
133
+ returning it.
134
+ * *`$path`* Expands to the file currently being expanded, relative to the
135
+ input tree.
136
+ * *`$realpath`* Expands to the real path of the file currently being
137
+ expanded.
138
+
139
+ The last two commands are mostly useful as arguments to external programs
140
+ (see below).
141
+
142
+ To find the file specified by a `$include{FILE}` command, Nancy proceeds
143
+ thus:
144
+
145
+ 1. Set `path` to the value of `$path`.
146
+ 2. See whether `path/FILE` is a file (or a symbolic link to a file). If so,
147
+ return the file path, unless we are already in the middle of expanding
148
+ this file.
149
+ 3. If `path` is empty, stop. Otherwise, remove the last directory from
150
+ `path` and go to step 2.
151
+
152
+ If no file is found, Nancy stops with an error message.
153
+
154
+ For example, if Nancy is trying to find `file.html`, starting in the
155
+ subdirectory `foo/bar/baz`, it will try the following files, in order:
156
+
157
+ 1. `foo/bar/baz/file.html`
158
+ 2. `foo/bar/file.html`
159
+ 3. `foo/file.html`
160
+ 4. `file.html`
161
+
162
+ See the [website example](Cookbook.md#website-example) in the Cookbook for a
163
+ worked example.
164
+
165
+ ### Running other programs
166
+
167
+ In addition to the rules given above, Nancy also allows `$include` and
168
+ `$paste` to take their input from programs. This can be useful in a variety
169
+ of ways: to insert the current date or time, to make a calculation, or to
170
+ convert a file to a different format.
171
+
172
+ Nancy can run a program in two ways:
173
+
174
+ 1. If a file found by an `$include` or `$paste` command has the “execute”
175
+ permission, it is run.
176
+
177
+ 2. If no file of the given name can be found using the rules in the previous
178
+ section, Nancy looks for an executable file on the user’s `PATH` (the
179
+ list of directories specified by the `PATH` environment variable). If one
180
+ is found, it is run.
181
+
182
+ In either case, arguments may be passed to the program: use
183
+ `$include{FILE,ARGUMENT_1,ARGUMENT_2,…}`, or the equivalent for `$paste`.
184
+
185
+ For example, to insert the current date:
186
+
187
+ ```
188
+ $paste{date,+%Y-%m-%d}
189
+ ```
190
+
191
+ See the [date example](Cookbook.md#date-example) in the Cookbook for more
192
+ detail.
193
+
194
+ When commands that run programs are nested inside each other, the order in
195
+ which they are run may matter. Nancy only guarantees that if one command is
196
+ nested inside another, the inner command will be processed first.
197
+
198
+ [FIXME]: # (Add example where this is significant)
199
+
200
+ ### Escaping
201
+
202
+ To prevent a comma from being interpreted as an argument separator, put a
203
+ backslash in front of it:
204
+
205
+ ```
206
+ $include{cat,I\, Robot.txt,3 Rules of Robotics.txt}
207
+ ```
208
+
209
+ This will run the `$include` command with the following arguments:
210
+
211
+ 1. `cat`
212
+ 2. `I, Robot.txt`
213
+ 3. `3 Rules of Robotics.txt`
214
+
215
+ Note that the filenames supplied to `cat` refer not to the input tree, but
216
+ to the file system.
217
+
218
+ Similarly, a command can be treated as literal text by putting a backslash
219
+ in front of it:
220
+
221
+ ```
222
+ Now I can talk about \$paste.
223
+ ```
224
+
225
+ This will output:
226
+
227
+ ```
228
+ Now I can talk about $paste.
229
+ ```
230
+
231
+ ## Development
232
+
233
+ Check out the git repository with:
234
+
235
+ ```
236
+ git clone https://github.com/rrthomas/nancy
237
+ ```
238
+
239
+ To run the tests:
240
+
241
+ ```
242
+ make test
243
+ ```
244
+
245
+ You will need the `tree` utility to build the documentation.
nancy-8.0.0/README.md ADDED
@@ -0,0 +1,231 @@
1
+ # Nancy
2
+
3
+ ![logo](logo/nancy-small.png) _logo by Silvia Polverini_
4
+
5
+ © 2002–2024 Reuben Thomas <rrt@sc3d.org>
6
+ https://github.com/rrthomas/nancy
7
+
8
+ Nancy is a simple macro processor that copies a file or directory, filling
9
+ in templates as it goes. It has just one non-trivial construct:
10
+ context-dependent file inclusion. A file can either be included literally,
11
+ or run as a command and its output included.
12
+
13
+ Nancy was originally designed to build simple static web sites, but can be
14
+ used for all sorts of other tasks, similar to more complicated systems like
15
+ [AutoGen] and [TXR].
16
+
17
+ [AutoGen]: https://autogen.sourceforge.net
18
+ [TXR]: https://www.nongnu.org/txr
19
+
20
+ Nancy is free software, licensed under the GNU GPL version 3 (or, at your
21
+ option, any later version), and written in TypeScript.
22
+
23
+ See the [Cookbook](Cookbook.md) for examples.
24
+
25
+ Please send questions, comments, and bug reports to the maintainer, or
26
+ report them on the project’s web page (see above for addresses).
27
+
28
+ ## Installation
29
+
30
+ Install Nancy with pip (part of [Python](https://python.org)):
31
+
32
+ ```
33
+ $ pip install nancy
34
+ ```
35
+
36
+ ## Invocation
37
+
38
+ ```
39
+ nancy [-h] [--path PATH] [--version] INPUT-PATH OUTPUT
40
+
41
+ A simple templating system.
42
+
43
+ positional arguments:
44
+ INPUT-PATH list of input directories, or a single file
45
+ OUTPUT output directory, or file ('-' for stdout)
46
+
47
+ options:
48
+ -h, --help show this help message and exit
49
+ --path PATH path to build relative to input tree [default: '']
50
+ --version show program's version number and exit
51
+
52
+ The INPUT-PATH is a ':'-separated list; the inputs are merged
53
+ in left-to-right order.
54
+
55
+ OUTPUT cannot be in any input directory.
56
+ ```
57
+
58
+ ## Operation <a name="operation"></a>
59
+
60
+ Nancy starts by combining the list of inputs given as its _input path_. If
61
+ the same file or directory exists in more than one of the directories on the
62
+ input path, the left-most takes precedence. The result is called the “input
63
+ tree”, and all paths are relative to it.
64
+
65
+ Next, Nancy traverses the input tree, or the tree given by the `--path`
66
+ argument, if any, which is a relative path denoting a subtree of the
67
+ input tree.
68
+
69
+ For each directory in the input tree, Nancy creates a corresponding
70
+ directory, if it does not already exist.
71
+
72
+ For each file, Nancy looks at its name, and:
73
+
74
+ + If the name contains the suffix `.nancy`, the file’s contents is expanded
75
+ (see below), and the result is then written to a file of the same name,
76
+ but with `.nancy` removed, in the corresponding place in the output
77
+ directory.
78
+ + Else, if the name contains the suffix `.in`, the file is skipped. (It may
79
+ be used by macros in other files.)
80
+ + Otherwise, the file is copied verbatim to the corresponding place in the
81
+ output.
82
+
83
+ Files and directories in the output have the same name as in the input tree,
84
+ except for the root directory (or file), which is called `OUTPUT`.
85
+
86
+ The special suffixes need not end the file name; they can be used as infixes
87
+ before the file type suffix.
88
+
89
+ ### Special cases
90
+
91
+ + If the input path is a single file, and no `--path` argument is given,
92
+ then Nancy acts as if the input path were the current directory and the
93
+ `--path` argument were the file name. This makes it convenient to expand a
94
+ single file using the command: `nancy INPUT-FILE OUTPUT-FILE`
95
+ + When the output is a single file, the special filename `-` may be used to
96
+ cause Nancy to print the result to standard output instead of writing it to
97
+ a file.
98
+
99
+ ### Template expansion
100
+
101
+ Nancy expands a template file as follows:
102
+
103
+ 1. Scan the text for commands. Expand any arguments to the command, run each
104
+ command, and replace the command by the result, eliding any final
105
+ newline. (This elision may look tricky, but it almost always does what
106
+ you want, and makes `$include` behave better in various contexts.)
107
+ 2. Output the resultant text.
108
+
109
+ A command takes the form `$COMMAND` or `$COMMAND{ARGUMENT, ...}`.
110
+
111
+ ### Built-in commands
112
+
113
+ Nancy recognises these commands:
114
+
115
+ * *`$include{FILE}`* Look up the given source file in the input tree (see
116
+ below); read its contents, then expand them (that is, execute any commands
117
+ it contains) and return the result.
118
+ * *`$paste{FILE}`* Like `$include`, but does not expand its result before
119
+ returning it.
120
+ * *`$path`* Expands to the file currently being expanded, relative to the
121
+ input tree.
122
+ * *`$realpath`* Expands to the real path of the file currently being
123
+ expanded.
124
+
125
+ The last two commands are mostly useful as arguments to external programs
126
+ (see below).
127
+
128
+ To find the file specified by a `$include{FILE}` command, Nancy proceeds
129
+ thus:
130
+
131
+ 1. Set `path` to the value of `$path`.
132
+ 2. See whether `path/FILE` is a file (or a symbolic link to a file). If so,
133
+ return the file path, unless we are already in the middle of expanding
134
+ this file.
135
+ 3. If `path` is empty, stop. Otherwise, remove the last directory from
136
+ `path` and go to step 2.
137
+
138
+ If no file is found, Nancy stops with an error message.
139
+
140
+ For example, if Nancy is trying to find `file.html`, starting in the
141
+ subdirectory `foo/bar/baz`, it will try the following files, in order:
142
+
143
+ 1. `foo/bar/baz/file.html`
144
+ 2. `foo/bar/file.html`
145
+ 3. `foo/file.html`
146
+ 4. `file.html`
147
+
148
+ See the [website example](Cookbook.md#website-example) in the Cookbook for a
149
+ worked example.
150
+
151
+ ### Running other programs
152
+
153
+ In addition to the rules given above, Nancy also allows `$include` and
154
+ `$paste` to take their input from programs. This can be useful in a variety
155
+ of ways: to insert the current date or time, to make a calculation, or to
156
+ convert a file to a different format.
157
+
158
+ Nancy can run a program in two ways:
159
+
160
+ 1. If a file found by an `$include` or `$paste` command has the “execute”
161
+ permission, it is run.
162
+
163
+ 2. If no file of the given name can be found using the rules in the previous
164
+ section, Nancy looks for an executable file on the user’s `PATH` (the
165
+ list of directories specified by the `PATH` environment variable). If one
166
+ is found, it is run.
167
+
168
+ In either case, arguments may be passed to the program: use
169
+ `$include{FILE,ARGUMENT_1,ARGUMENT_2,…}`, or the equivalent for `$paste`.
170
+
171
+ For example, to insert the current date:
172
+
173
+ ```
174
+ $paste{date,+%Y-%m-%d}
175
+ ```
176
+
177
+ See the [date example](Cookbook.md#date-example) in the Cookbook for more
178
+ detail.
179
+
180
+ When commands that run programs are nested inside each other, the order in
181
+ which they are run may matter. Nancy only guarantees that if one command is
182
+ nested inside another, the inner command will be processed first.
183
+
184
+ [FIXME]: # (Add example where this is significant)
185
+
186
+ ### Escaping
187
+
188
+ To prevent a comma from being interpreted as an argument separator, put a
189
+ backslash in front of it:
190
+
191
+ ```
192
+ $include{cat,I\, Robot.txt,3 Rules of Robotics.txt}
193
+ ```
194
+
195
+ This will run the `$include` command with the following arguments:
196
+
197
+ 1. `cat`
198
+ 2. `I, Robot.txt`
199
+ 3. `3 Rules of Robotics.txt`
200
+
201
+ Note that the filenames supplied to `cat` refer not to the input tree, but
202
+ to the file system.
203
+
204
+ Similarly, a command can be treated as literal text by putting a backslash
205
+ in front of it:
206
+
207
+ ```
208
+ Now I can talk about \$paste.
209
+ ```
210
+
211
+ This will output:
212
+
213
+ ```
214
+ Now I can talk about $paste.
215
+ ```
216
+
217
+ ## Development
218
+
219
+ Check out the git repository with:
220
+
221
+ ```
222
+ git clone https://github.com/rrthomas/nancy
223
+ ```
224
+
225
+ To run the tests:
226
+
227
+ ```
228
+ make test
229
+ ```
230
+
231
+ You will need the `tree` utility to build the documentation.