mstache 0.2.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.
- mstache-0.2.0/LICENSE +21 -0
- mstache-0.2.0/PKG-INFO +176 -0
- mstache-0.2.0/README.md +120 -0
- mstache-0.2.0/mstache.egg-info/PKG-INFO +176 -0
- mstache-0.2.0/mstache.egg-info/SOURCES.txt +13 -0
- mstache-0.2.0/mstache.egg-info/dependency_links.txt +1 -0
- mstache-0.2.0/mstache.egg-info/entry_points.txt +3 -0
- mstache-0.2.0/mstache.egg-info/requires.txt +41 -0
- mstache-0.2.0/mstache.egg-info/top_level.txt +1 -0
- mstache-0.2.0/mstache.egg-info/zip-safe +1 -0
- mstache-0.2.0/mstache.py +1147 -0
- mstache-0.2.0/pyproject.toml +104 -0
- mstache-0.2.0/setup.cfg +90 -0
- mstache-0.2.0/setup.py +121 -0
mstache-0.2.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021-2024 Felipe A Hernandez <ergoithz@gmail.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of the software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions.
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
mstache-0.2.0/PKG-INFO
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: mstache
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: mstache, Mustache for Python
|
|
5
|
+
Home-page: https://gitlab.com/ergoithz/mstache
|
|
6
|
+
Author: Felipe A Hernandez
|
|
7
|
+
Author-email: ergoithz@gmail.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Keywords: template,mustache
|
|
10
|
+
Platform: any
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
17
|
+
Requires-Python: >=3.10.0
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
Provides-Extra: codestyle
|
|
21
|
+
Requires-Dist: pycodestyle; extra == "codestyle"
|
|
22
|
+
Requires-Dist: ruff; extra == "codestyle"
|
|
23
|
+
Requires-Dist: sphinx; extra == "codestyle"
|
|
24
|
+
Requires-Dist: rstcheck; extra == "codestyle"
|
|
25
|
+
Requires-Dist: mypy; extra == "codestyle"
|
|
26
|
+
Provides-Extra: coverage
|
|
27
|
+
Requires-Dist: coverage[toml]; extra == "coverage"
|
|
28
|
+
Provides-Extra: docs
|
|
29
|
+
Requires-Dist: recommonmark; extra == "docs"
|
|
30
|
+
Requires-Dist: sphinx; extra == "docs"
|
|
31
|
+
Requires-Dist: sphinx-autobuild; extra == "docs"
|
|
32
|
+
Requires-Dist: sphinx-autodoc-typehints; extra == "docs"
|
|
33
|
+
Provides-Extra: release
|
|
34
|
+
Requires-Dist: build; extra == "release"
|
|
35
|
+
Requires-Dist: twine; extra == "release"
|
|
36
|
+
Provides-Extra: benchmark
|
|
37
|
+
Requires-Dist: ustache==0.1.5; extra == "benchmark"
|
|
38
|
+
Requires-Dist: chevron; extra == "benchmark"
|
|
39
|
+
Requires-Dist: tabulate; extra == "benchmark"
|
|
40
|
+
Provides-Extra: dev
|
|
41
|
+
Requires-Dist: pycodestyle; extra == "dev"
|
|
42
|
+
Requires-Dist: ruff; extra == "dev"
|
|
43
|
+
Requires-Dist: sphinx; extra == "dev"
|
|
44
|
+
Requires-Dist: rstcheck; extra == "dev"
|
|
45
|
+
Requires-Dist: mypy; extra == "dev"
|
|
46
|
+
Requires-Dist: coverage[toml]; extra == "dev"
|
|
47
|
+
Requires-Dist: recommonmark; extra == "dev"
|
|
48
|
+
Requires-Dist: sphinx; extra == "dev"
|
|
49
|
+
Requires-Dist: sphinx-autobuild; extra == "dev"
|
|
50
|
+
Requires-Dist: sphinx-autodoc-typehints; extra == "dev"
|
|
51
|
+
Requires-Dist: build; extra == "dev"
|
|
52
|
+
Requires-Dist: twine; extra == "dev"
|
|
53
|
+
Requires-Dist: ustache==0.1.5; extra == "dev"
|
|
54
|
+
Requires-Dist: chevron; extra == "dev"
|
|
55
|
+
Requires-Dist: tabulate; extra == "dev"
|
|
56
|
+
|
|
57
|
+
# mstache
|
|
58
|
+
|
|
59
|
+
Mustache for Python.
|
|
60
|
+
|
|
61
|
+
Documentation: [mstache.readthedocs.io](https://mstache.readthedocs.io)
|
|
62
|
+
|
|
63
|
+
## License
|
|
64
|
+
|
|
65
|
+
[MIT License](https://gitlab.com/ergoithz/mstache/-/blob/master/LICENSE)
|
|
66
|
+
|
|
67
|
+
## Installation
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
pip install mstache
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Usage
|
|
74
|
+
|
|
75
|
+
Python:
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
import mstache
|
|
79
|
+
|
|
80
|
+
print(mstache.render('Hello {{v}}', {'v': 'World!'}))
|
|
81
|
+
# Hello World!
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Command line:
|
|
85
|
+
|
|
86
|
+
```sh
|
|
87
|
+
$ mstache -j data.json -o output.html template.mustache
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Highlights
|
|
91
|
+
|
|
92
|
+
- The fastest pure-python Mustache implementation to this date.
|
|
93
|
+
- Command line interface.
|
|
94
|
+
- Spec compliant, but also highly compatible with `Mustache.js`.
|
|
95
|
+
- Small codebase, efficiently rendering to `str` or `bytes`,
|
|
96
|
+
either buffered or streaming.
|
|
97
|
+
- Fully customizable behavior: cache, property getter, partial resolver,
|
|
98
|
+
stringification, escaping and lambdas.
|
|
99
|
+
- No dynamic code generation, both jit and transpiler friendly.
|
|
100
|
+
|
|
101
|
+
## Considerations
|
|
102
|
+
|
|
103
|
+
For inter-compatibility with JavaScript (especially `Mustache.js`, enabling
|
|
104
|
+
client-side rendering with the same templates), **mstache** must behave
|
|
105
|
+
somewhat atypically for a `Python` template engine:
|
|
106
|
+
|
|
107
|
+
- Mustache blocks stick to JavaScript truthyness
|
|
108
|
+
(`Mustache.js` truthyness emulation):
|
|
109
|
+
- Empty mappings (such as `dict`) are unconditionally truthy.
|
|
110
|
+
- `NaN`/`-NaN` are falsy.
|
|
111
|
+
- Mustache blocks loop through any iterable other than mappings and strings
|
|
112
|
+
(`Mustache.js` `Array` handling).
|
|
113
|
+
- Non-mapping sized objects will expose a virtual `length` property
|
|
114
|
+
(JavaScript `Array.length` emulation, customizable via `getter` parameter).
|
|
115
|
+
- Mapping keys containing dot (`.`) or whitespace (` `) are unreachable,
|
|
116
|
+
(`Mustache.js` property limitation, customizable via `getter` parameter).
|
|
117
|
+
- Sequence elements are accessible by positive index in the same way mapping
|
|
118
|
+
integer-keyed items are also accessible when no string key conflicts, as
|
|
119
|
+
properties (JavaScript `Object` emulation, customizable via `getter` parameter).
|
|
120
|
+
|
|
121
|
+
## Syntax
|
|
122
|
+
|
|
123
|
+
Check out the [mustache(5) manual](https://mustache.github.io/mustache.5.html).
|
|
124
|
+
|
|
125
|
+
For quick reference, here is a quick overview of the Mustache syntax.
|
|
126
|
+
|
|
127
|
+
Template (`template.mustache`):
|
|
128
|
+
```handlebars
|
|
129
|
+
{{!comment}}
|
|
130
|
+
<ul>
|
|
131
|
+
{{#object}}<li>{{property}}</li>{{/object}}
|
|
132
|
+
{{^object}}<li>As <b>object</b> is truthy, this won't be shown</li>{{/object}}
|
|
133
|
+
{{^null}}<li><b>null</b> is falsy</li>{{/null}}
|
|
134
|
+
{{#array}}<li>{{property}}</li>
|
|
135
|
+
{{/array}}
|
|
136
|
+
{{^array}}<li>Array isn't empty, this won't be shown.</li>{{/array}}
|
|
137
|
+
{{#empty_array}}<li>Empty Array, this won't be shown</li>{{/empty_array}}
|
|
138
|
+
{{^empty_array}}<li>empty_array is empty</li>{{/empty_array}}
|
|
139
|
+
{{&unescaped_html}}
|
|
140
|
+
</ul>
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Data (`data.json`):
|
|
144
|
+
```json
|
|
145
|
+
{
|
|
146
|
+
"object": {
|
|
147
|
+
"property": "Object property value"
|
|
148
|
+
},
|
|
149
|
+
"null": null,
|
|
150
|
+
"array": [
|
|
151
|
+
{"property": "Array item1 property"},
|
|
152
|
+
{"property": "Array item2 property"},
|
|
153
|
+
{"property": "Array item3 property"}
|
|
154
|
+
],
|
|
155
|
+
"empty_array": [],
|
|
156
|
+
"unescaped_html": "<li>this is unescaped html</li>"
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
Command:
|
|
161
|
+
```sh
|
|
162
|
+
$ mstache -j data.json -o output.html template.mustache
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
Output:
|
|
166
|
+
```html
|
|
167
|
+
<ul>
|
|
168
|
+
<li>Object property value</li>
|
|
169
|
+
<li><b>null</b> is falsy</li>
|
|
170
|
+
<li>Array item1 property</li>
|
|
171
|
+
<li>Array item2 property</li>
|
|
172
|
+
<li>Array item3 property</li>
|
|
173
|
+
<li>empty_array is empty</li>
|
|
174
|
+
<li>this is unescaped html</li>
|
|
175
|
+
</ul>
|
|
176
|
+
```
|
mstache-0.2.0/README.md
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# mstache
|
|
2
|
+
|
|
3
|
+
Mustache for Python.
|
|
4
|
+
|
|
5
|
+
Documentation: [mstache.readthedocs.io](https://mstache.readthedocs.io)
|
|
6
|
+
|
|
7
|
+
## License
|
|
8
|
+
|
|
9
|
+
[MIT License](./LICENSE)
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
pip install mstache
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
Python:
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
import mstache
|
|
23
|
+
|
|
24
|
+
print(mstache.render('Hello {{v}}', {'v': 'World!'}))
|
|
25
|
+
# Hello World!
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Command line:
|
|
29
|
+
|
|
30
|
+
```sh
|
|
31
|
+
$ mstache -j data.json -o output.html template.mustache
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Highlights
|
|
35
|
+
|
|
36
|
+
- The fastest pure-python Mustache implementation to this date.
|
|
37
|
+
- Command line interface.
|
|
38
|
+
- Spec compliant, but also highly compatible with `Mustache.js`.
|
|
39
|
+
- Small codebase, efficiently rendering to `str` or `bytes`,
|
|
40
|
+
either buffered or streaming.
|
|
41
|
+
- Fully customizable behavior: cache, property getter, partial resolver,
|
|
42
|
+
stringification, escaping and lambdas.
|
|
43
|
+
- No dynamic code generation, both jit and transpiler friendly.
|
|
44
|
+
|
|
45
|
+
## Considerations
|
|
46
|
+
|
|
47
|
+
For inter-compatibility with JavaScript (especially `Mustache.js`, enabling
|
|
48
|
+
client-side rendering with the same templates), **mstache** must behave
|
|
49
|
+
somewhat atypically for a `Python` template engine:
|
|
50
|
+
|
|
51
|
+
- Mustache blocks stick to JavaScript truthyness
|
|
52
|
+
(`Mustache.js` truthyness emulation):
|
|
53
|
+
- Empty mappings (such as `dict`) are unconditionally truthy.
|
|
54
|
+
- `NaN`/`-NaN` are falsy.
|
|
55
|
+
- Mustache blocks loop through any iterable other than mappings and strings
|
|
56
|
+
(`Mustache.js` `Array` handling).
|
|
57
|
+
- Non-mapping sized objects will expose a virtual `length` property
|
|
58
|
+
(JavaScript `Array.length` emulation, customizable via `getter` parameter).
|
|
59
|
+
- Mapping keys containing dot (`.`) or whitespace (` `) are unreachable,
|
|
60
|
+
(`Mustache.js` property limitation, customizable via `getter` parameter).
|
|
61
|
+
- Sequence elements are accessible by positive index in the same way mapping
|
|
62
|
+
integer-keyed items are also accessible when no string key conflicts, as
|
|
63
|
+
properties (JavaScript `Object` emulation, customizable via `getter` parameter).
|
|
64
|
+
|
|
65
|
+
## Syntax
|
|
66
|
+
|
|
67
|
+
Check out the [mustache(5) manual](https://mustache.github.io/mustache.5.html).
|
|
68
|
+
|
|
69
|
+
For quick reference, here is a quick overview of the Mustache syntax.
|
|
70
|
+
|
|
71
|
+
Template (`template.mustache`):
|
|
72
|
+
```handlebars
|
|
73
|
+
{{!comment}}
|
|
74
|
+
<ul>
|
|
75
|
+
{{#object}}<li>{{property}}</li>{{/object}}
|
|
76
|
+
{{^object}}<li>As <b>object</b> is truthy, this won't be shown</li>{{/object}}
|
|
77
|
+
{{^null}}<li><b>null</b> is falsy</li>{{/null}}
|
|
78
|
+
{{#array}}<li>{{property}}</li>
|
|
79
|
+
{{/array}}
|
|
80
|
+
{{^array}}<li>Array isn't empty, this won't be shown.</li>{{/array}}
|
|
81
|
+
{{#empty_array}}<li>Empty Array, this won't be shown</li>{{/empty_array}}
|
|
82
|
+
{{^empty_array}}<li>empty_array is empty</li>{{/empty_array}}
|
|
83
|
+
{{&unescaped_html}}
|
|
84
|
+
</ul>
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Data (`data.json`):
|
|
88
|
+
```json
|
|
89
|
+
{
|
|
90
|
+
"object": {
|
|
91
|
+
"property": "Object property value"
|
|
92
|
+
},
|
|
93
|
+
"null": null,
|
|
94
|
+
"array": [
|
|
95
|
+
{"property": "Array item1 property"},
|
|
96
|
+
{"property": "Array item2 property"},
|
|
97
|
+
{"property": "Array item3 property"}
|
|
98
|
+
],
|
|
99
|
+
"empty_array": [],
|
|
100
|
+
"unescaped_html": "<li>this is unescaped html</li>"
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Command:
|
|
105
|
+
```sh
|
|
106
|
+
$ mstache -j data.json -o output.html template.mustache
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Output:
|
|
110
|
+
```html
|
|
111
|
+
<ul>
|
|
112
|
+
<li>Object property value</li>
|
|
113
|
+
<li><b>null</b> is falsy</li>
|
|
114
|
+
<li>Array item1 property</li>
|
|
115
|
+
<li>Array item2 property</li>
|
|
116
|
+
<li>Array item3 property</li>
|
|
117
|
+
<li>empty_array is empty</li>
|
|
118
|
+
<li>this is unescaped html</li>
|
|
119
|
+
</ul>
|
|
120
|
+
```
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: mstache
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: mstache, Mustache for Python
|
|
5
|
+
Home-page: https://gitlab.com/ergoithz/mstache
|
|
6
|
+
Author: Felipe A Hernandez
|
|
7
|
+
Author-email: ergoithz@gmail.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Keywords: template,mustache
|
|
10
|
+
Platform: any
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
17
|
+
Requires-Python: >=3.10.0
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
Provides-Extra: codestyle
|
|
21
|
+
Requires-Dist: pycodestyle; extra == "codestyle"
|
|
22
|
+
Requires-Dist: ruff; extra == "codestyle"
|
|
23
|
+
Requires-Dist: sphinx; extra == "codestyle"
|
|
24
|
+
Requires-Dist: rstcheck; extra == "codestyle"
|
|
25
|
+
Requires-Dist: mypy; extra == "codestyle"
|
|
26
|
+
Provides-Extra: coverage
|
|
27
|
+
Requires-Dist: coverage[toml]; extra == "coverage"
|
|
28
|
+
Provides-Extra: docs
|
|
29
|
+
Requires-Dist: recommonmark; extra == "docs"
|
|
30
|
+
Requires-Dist: sphinx; extra == "docs"
|
|
31
|
+
Requires-Dist: sphinx-autobuild; extra == "docs"
|
|
32
|
+
Requires-Dist: sphinx-autodoc-typehints; extra == "docs"
|
|
33
|
+
Provides-Extra: release
|
|
34
|
+
Requires-Dist: build; extra == "release"
|
|
35
|
+
Requires-Dist: twine; extra == "release"
|
|
36
|
+
Provides-Extra: benchmark
|
|
37
|
+
Requires-Dist: ustache==0.1.5; extra == "benchmark"
|
|
38
|
+
Requires-Dist: chevron; extra == "benchmark"
|
|
39
|
+
Requires-Dist: tabulate; extra == "benchmark"
|
|
40
|
+
Provides-Extra: dev
|
|
41
|
+
Requires-Dist: pycodestyle; extra == "dev"
|
|
42
|
+
Requires-Dist: ruff; extra == "dev"
|
|
43
|
+
Requires-Dist: sphinx; extra == "dev"
|
|
44
|
+
Requires-Dist: rstcheck; extra == "dev"
|
|
45
|
+
Requires-Dist: mypy; extra == "dev"
|
|
46
|
+
Requires-Dist: coverage[toml]; extra == "dev"
|
|
47
|
+
Requires-Dist: recommonmark; extra == "dev"
|
|
48
|
+
Requires-Dist: sphinx; extra == "dev"
|
|
49
|
+
Requires-Dist: sphinx-autobuild; extra == "dev"
|
|
50
|
+
Requires-Dist: sphinx-autodoc-typehints; extra == "dev"
|
|
51
|
+
Requires-Dist: build; extra == "dev"
|
|
52
|
+
Requires-Dist: twine; extra == "dev"
|
|
53
|
+
Requires-Dist: ustache==0.1.5; extra == "dev"
|
|
54
|
+
Requires-Dist: chevron; extra == "dev"
|
|
55
|
+
Requires-Dist: tabulate; extra == "dev"
|
|
56
|
+
|
|
57
|
+
# mstache
|
|
58
|
+
|
|
59
|
+
Mustache for Python.
|
|
60
|
+
|
|
61
|
+
Documentation: [mstache.readthedocs.io](https://mstache.readthedocs.io)
|
|
62
|
+
|
|
63
|
+
## License
|
|
64
|
+
|
|
65
|
+
[MIT License](https://gitlab.com/ergoithz/mstache/-/blob/master/LICENSE)
|
|
66
|
+
|
|
67
|
+
## Installation
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
pip install mstache
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Usage
|
|
74
|
+
|
|
75
|
+
Python:
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
import mstache
|
|
79
|
+
|
|
80
|
+
print(mstache.render('Hello {{v}}', {'v': 'World!'}))
|
|
81
|
+
# Hello World!
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Command line:
|
|
85
|
+
|
|
86
|
+
```sh
|
|
87
|
+
$ mstache -j data.json -o output.html template.mustache
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Highlights
|
|
91
|
+
|
|
92
|
+
- The fastest pure-python Mustache implementation to this date.
|
|
93
|
+
- Command line interface.
|
|
94
|
+
- Spec compliant, but also highly compatible with `Mustache.js`.
|
|
95
|
+
- Small codebase, efficiently rendering to `str` or `bytes`,
|
|
96
|
+
either buffered or streaming.
|
|
97
|
+
- Fully customizable behavior: cache, property getter, partial resolver,
|
|
98
|
+
stringification, escaping and lambdas.
|
|
99
|
+
- No dynamic code generation, both jit and transpiler friendly.
|
|
100
|
+
|
|
101
|
+
## Considerations
|
|
102
|
+
|
|
103
|
+
For inter-compatibility with JavaScript (especially `Mustache.js`, enabling
|
|
104
|
+
client-side rendering with the same templates), **mstache** must behave
|
|
105
|
+
somewhat atypically for a `Python` template engine:
|
|
106
|
+
|
|
107
|
+
- Mustache blocks stick to JavaScript truthyness
|
|
108
|
+
(`Mustache.js` truthyness emulation):
|
|
109
|
+
- Empty mappings (such as `dict`) are unconditionally truthy.
|
|
110
|
+
- `NaN`/`-NaN` are falsy.
|
|
111
|
+
- Mustache blocks loop through any iterable other than mappings and strings
|
|
112
|
+
(`Mustache.js` `Array` handling).
|
|
113
|
+
- Non-mapping sized objects will expose a virtual `length` property
|
|
114
|
+
(JavaScript `Array.length` emulation, customizable via `getter` parameter).
|
|
115
|
+
- Mapping keys containing dot (`.`) or whitespace (` `) are unreachable,
|
|
116
|
+
(`Mustache.js` property limitation, customizable via `getter` parameter).
|
|
117
|
+
- Sequence elements are accessible by positive index in the same way mapping
|
|
118
|
+
integer-keyed items are also accessible when no string key conflicts, as
|
|
119
|
+
properties (JavaScript `Object` emulation, customizable via `getter` parameter).
|
|
120
|
+
|
|
121
|
+
## Syntax
|
|
122
|
+
|
|
123
|
+
Check out the [mustache(5) manual](https://mustache.github.io/mustache.5.html).
|
|
124
|
+
|
|
125
|
+
For quick reference, here is a quick overview of the Mustache syntax.
|
|
126
|
+
|
|
127
|
+
Template (`template.mustache`):
|
|
128
|
+
```handlebars
|
|
129
|
+
{{!comment}}
|
|
130
|
+
<ul>
|
|
131
|
+
{{#object}}<li>{{property}}</li>{{/object}}
|
|
132
|
+
{{^object}}<li>As <b>object</b> is truthy, this won't be shown</li>{{/object}}
|
|
133
|
+
{{^null}}<li><b>null</b> is falsy</li>{{/null}}
|
|
134
|
+
{{#array}}<li>{{property}}</li>
|
|
135
|
+
{{/array}}
|
|
136
|
+
{{^array}}<li>Array isn't empty, this won't be shown.</li>{{/array}}
|
|
137
|
+
{{#empty_array}}<li>Empty Array, this won't be shown</li>{{/empty_array}}
|
|
138
|
+
{{^empty_array}}<li>empty_array is empty</li>{{/empty_array}}
|
|
139
|
+
{{&unescaped_html}}
|
|
140
|
+
</ul>
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Data (`data.json`):
|
|
144
|
+
```json
|
|
145
|
+
{
|
|
146
|
+
"object": {
|
|
147
|
+
"property": "Object property value"
|
|
148
|
+
},
|
|
149
|
+
"null": null,
|
|
150
|
+
"array": [
|
|
151
|
+
{"property": "Array item1 property"},
|
|
152
|
+
{"property": "Array item2 property"},
|
|
153
|
+
{"property": "Array item3 property"}
|
|
154
|
+
],
|
|
155
|
+
"empty_array": [],
|
|
156
|
+
"unescaped_html": "<li>this is unescaped html</li>"
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
Command:
|
|
161
|
+
```sh
|
|
162
|
+
$ mstache -j data.json -o output.html template.mustache
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
Output:
|
|
166
|
+
```html
|
|
167
|
+
<ul>
|
|
168
|
+
<li>Object property value</li>
|
|
169
|
+
<li><b>null</b> is falsy</li>
|
|
170
|
+
<li>Array item1 property</li>
|
|
171
|
+
<li>Array item2 property</li>
|
|
172
|
+
<li>Array item3 property</li>
|
|
173
|
+
<li>empty_array is empty</li>
|
|
174
|
+
<li>this is unescaped html</li>
|
|
175
|
+
</ul>
|
|
176
|
+
```
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
mstache.py
|
|
4
|
+
pyproject.toml
|
|
5
|
+
setup.cfg
|
|
6
|
+
setup.py
|
|
7
|
+
mstache.egg-info/PKG-INFO
|
|
8
|
+
mstache.egg-info/SOURCES.txt
|
|
9
|
+
mstache.egg-info/dependency_links.txt
|
|
10
|
+
mstache.egg-info/entry_points.txt
|
|
11
|
+
mstache.egg-info/requires.txt
|
|
12
|
+
mstache.egg-info/top_level.txt
|
|
13
|
+
mstache.egg-info/zip-safe
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
|
|
2
|
+
[benchmark]
|
|
3
|
+
ustache==0.1.5
|
|
4
|
+
chevron
|
|
5
|
+
tabulate
|
|
6
|
+
|
|
7
|
+
[codestyle]
|
|
8
|
+
pycodestyle
|
|
9
|
+
ruff
|
|
10
|
+
sphinx
|
|
11
|
+
rstcheck
|
|
12
|
+
mypy
|
|
13
|
+
|
|
14
|
+
[coverage]
|
|
15
|
+
coverage[toml]
|
|
16
|
+
|
|
17
|
+
[dev]
|
|
18
|
+
pycodestyle
|
|
19
|
+
ruff
|
|
20
|
+
sphinx
|
|
21
|
+
rstcheck
|
|
22
|
+
mypy
|
|
23
|
+
coverage[toml]
|
|
24
|
+
recommonmark
|
|
25
|
+
sphinx-autobuild
|
|
26
|
+
sphinx-autodoc-typehints
|
|
27
|
+
build
|
|
28
|
+
twine
|
|
29
|
+
ustache==0.1.5
|
|
30
|
+
chevron
|
|
31
|
+
tabulate
|
|
32
|
+
|
|
33
|
+
[docs]
|
|
34
|
+
recommonmark
|
|
35
|
+
sphinx
|
|
36
|
+
sphinx-autobuild
|
|
37
|
+
sphinx-autodoc-typehints
|
|
38
|
+
|
|
39
|
+
[release]
|
|
40
|
+
build
|
|
41
|
+
twine
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
mstache
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|