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: CHANGES.md
+16-12Lines changed: 16 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,23 +2,24 @@
2
2
3
3
## Version 2.0.0 (unreleased)
4
4
5
-
This major release:
5
+
This is a major release with several breaking changes. As well as API changes listed below, we:
6
6
7
-
- Drops support for Python version 3.7 and 3.8.
8
-
- Introduces API changes [discussed here](https://github.com/jg-rp/liquid/discussions/137).
7
+
- Drop support for Python version 3.7 and 3.8.
9
8
- Promotes rendering behavior from `liquid.future.Environment` to be the default, so as to improve Shopify/liquid compatibility by default.
10
-
-Fixes variable/identifier/path parsing described in [issue #39](https://github.com/jg-rp/liquid/issues/39).
11
-
-Improves Liquid syntax error messages and exposes source index, line numbers and column numbers through methods on Liquid exceptions. See [#53](https://github.com/jg-rp/liquid/issues/53).
12
-
-Changes comment tag parsing to better match Shopify/Liquid. See [#133](https://github.com/jg-rp/liquid/issues/133).
13
-
-Removes`BoundTemplate.analyze_with_context()`. Shout if you need contextual analysis and we'll restore this feature.
14
-
-Removes the `cache_size` argument to `liquid.Environment` and `liquid.Template`. Template caching is now handled by template loaders.
15
-
-Removes the `expression_cache_size` argument to `liquid.Environment` and `liquid.Template`. Environment-level expression caching is no longer available as it does not play nicely with detailed error messages. If you need to cache parsing of Liquid expressions, it is now recommended to implement a cache per tag, where it makes sense to do so for your use case.
16
-
-Makes markupsafe>=3 a dependency. Previously markupsafe was an optional dependency. Version 3 of markupsafe brings some subtle changes to the `replace`, `replace_first` and `replace_last` filters when they receive a "safe" string wrapped in `Markup()`.
17
-
-Adds new filters `reject`, `has`, `find` and `find_index`.
18
-
-Adds the new `doc` tag.
9
+
-Fixe variable/identifier/path parsing described in [issue #39](https://github.com/jg-rp/liquid/issues/39).
10
+
-Improve Liquid syntax error messages and exposes source index, line numbers and column numbers through methods on Liquid exceptions. See [#53](https://github.com/jg-rp/liquid/issues/53).
11
+
-Change comment tag parsing to better match Shopify/Liquid. See [#133](https://github.com/jg-rp/liquid/issues/133).
12
+
-Remove`BoundTemplate.analyze_with_context()`. Shout if you need contextual analysis and we'll restore this feature.
13
+
-Remove the `cache_size` argument to `liquid.Environment` and `liquid.Template`. Template caching is now handled by template loaders.
14
+
-Remove the `expression_cache_size` argument to `liquid.Environment` and `liquid.Template`. Environment-level expression caching is no longer available as it does not play nicely with detailed error messages. If you need to cache parsing of Liquid expressions, it is now recommended to implement a cache per tag, where it makes sense to do so for your use case.
15
+
-Make markupsafe>=3 a dependency. Previously markupsafe was an optional dependency. Version 3 of markupsafe brings some subtle changes to the `replace`, `replace_first` and `replace_last` filters when they receive a "safe" string wrapped in `Markup()`.
16
+
-Add new filters `reject`, `has`, `find` and `find_index`.
17
+
-Add the new `doc` tag.
19
18
20
19
### API changes
21
20
21
+
Also see the [migration guide].
22
+
22
23
#### Miscellaneous
23
24
24
25
- Added `liquid.parse(source)`, `liquid.render(source, **data)` and `liquid.render_async(source, **data)`. These are shorthand functions that use `liquid.DEFAULT_ENVIRONMENT`.
@@ -27,6 +28,9 @@ This major release:
27
28
- Added `liquid.Environment.render(source, **data)` and `liquid.Environment.render_async(source, **data)`. These are convenience methods equivalent to `liquid.Environment.from_string(source).render(**data)`.
28
29
- Renamed `liquid.Context` to `liquid.RenderContext`.
29
30
- Change the `liquid.RenderContext` constructor (previously `liquid.Context`) to require an instance of `BoundTemplate` as its only positional argument instead of an instance of `Environment`. All other arguments are now keyword only.
31
+
- Renamed `liquid.exceptions.Error` to `liquid.exceptions.LiquidError`.
32
+
- Renamed `liquid.exceptions.TemplateNotFound` to `liquid.exceptions.TemplateNotFoundError`.
33
+
- Renamed `liquid.exceptions.NoSuchFilterFunc` to `liquid.exceptions.UnknownFilterError`.
Copy file name to clipboardExpand all lines: README.md
+44-58Lines changed: 44 additions & 58 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,13 +1,9 @@
1
-
> [!IMPORTANT]
2
-
> 🎉 Announcing the release of [Python Liquid2](https://github.com/jg-rp/python-liquid2) 🎉 See the [migration guide](https://jg-rp.github.io/python-liquid2/migration/) and the list of [new features](https://jg-rp.github.io/python-liquid2/migration/#new-features).
3
-
4
-
---
5
-
6
1
<h1align="center">Python Liquid</h1>
7
2
8
3
<palign="center">
9
-
A Python engine for <ahref="https://shopify.github.io/liquid/">Liquid</a>, the safe customer-facing template language for flexible web apps.
10
-
<br>We follow <ahref="https://github.com/Shopify/liquid">Shopify/Liquid</a> closely and test against the <ahref="https://github.com/jg-rp/golden-liquid">Golden Liquid</a> test suite.
4
+
Python Liquid is a Python engine for <ahref="https://shopify.github.io/liquid/">Liquid</a>, the safe, customer-facing template language.
5
+
<br>
6
+
We follow <ahref="https://github.com/Shopify/liquid">Shopify/Liquid</a> closely and test against the <ahref="https://github.com/jg-rp/golden-liquid">Golden Liquid</a> test suite.
-[Python Liquid2](https://github.com/jg-rp/python-liquid2): A new Python engine for Liquid with [extra features](https://jg-rp.github.io/python-liquid2/migration/#new-features).
81
+
-[LiquidScript](https://github.com/jg-rp/liquidscript): A JavaScript engine for Liquid with a similar high-level API to Python Liquid.
92
82
93
-
## Related Projects
83
+
## Quick Start
94
84
95
-
-[Python Liquid2](https://github.com/jg-rp/python-liquid2): A new Python pakage for Liquid, with extra features.
96
-
-[liquid-babel](https://github.com/jg-rp/liquid-babel): Internationalization and localization for Liquid templates.
97
-
-[LiquidScript](https://github.com/jg-rp/liquidscript): A JavaScript and TypeScript engine for Liquid with a similar high-level API to Python Liquid.
98
-
-[django-liquid](https://github.com/jg-rp/django-liquid): A Django template backend for Liquid. Render Liquid templates in your Django apps.
99
-
-[Flask-Liquid](https://github.com/jg-rp/Flask-Liquid): A Flask extension for Liquid. Render Liquid templates in your Flask applications.
100
-
-[golden-liquid](https://github.com/jg-rp/golden-liquid): A test suite for Liquid. See how various Liquid template engines compare to the reference implementation.
85
+
### `render()`
101
86
102
-
## Compatibility
87
+
This example renders a template from a string of text with the package-level `render()` function. The template has just one placeholder variable `you`, which we've given the value `"World"`.
103
88
104
-
We strive to be 100% compatible with the [reference implementation](https://shopify.github.io/liquid/) of Liquid, written in Ruby. That is, given an equivalent render context, a template rendered with Python Liquid should produce the same output as when rendered with Ruby Liquid.
89
+
```python
90
+
from liquid import render
105
91
106
-
See the [known issues page](https://jg-rp.github.io/liquid/known_issues) for details of known incompatibilities between Python Liquid and Ruby Liquid, and please help by raising an issue if you notice an incompatibility.
92
+
print(render("Hello, {{ you }}!", you="World"))
93
+
# Hello, World!
94
+
```
107
95
108
-
##Benchmark
96
+
### `parse()`
109
97
110
-
You can run the benchmark using `hatch run benchmark` (or `python -O scripts/performance.py` if you don't have `make`) from the root of the source tree. On my ropey desktop computer with a Ryzen 5 1500X and Python 3.11.0, we get the following results.
98
+
Often you'll want to render the same template several times with different variables. We can parse source text without immediately rendering it using the `parse()` function. `parse()` returns a `BoundTemplate` instance with a `render()` method.
111
99
112
-
```text
113
-
Best of 5 rounds with 100 iterations per round and 60 ops per iteration (6000 ops per round).
lex, parse and render: 4.6s (1298.18 ops/s, 21.64 i/s)
130
-
```
110
+
Both `parse()` and `render()` are convenience functions that use the default Liquid environment. For all but the simplest cases, you'll want to configure an instance of `Environment`, then load and render templates from that.
131
111
132
-
On the same machine, running `rake benchmark:run` from the root of the reference implementation source tree gives us these results.
112
+
```python
113
+
from liquid import CachingFileSystemLoader
114
+
from liquid import Environment
133
115
134
-
```text
135
-
/usr/bin/ruby ./performance/benchmark.rb lax
116
+
env = Environment(
117
+
autoescape=True,
118
+
loader=CachingFileSystemLoader("./templates"),
119
+
)
120
+
```
136
121
137
-
Running benchmark for 10 seconds (with 5 seconds warmup).
122
+
Then, using `env.parse()` or `env.get_template()`, we can create a `BoundTemplate` from a string or read from the file system, respectively.
138
123
139
-
Warming up --------------------------------------
140
-
parse: 3.000 i/100ms
141
-
render: 8.000 i/100ms
142
-
parse & render: 2.000 i/100ms
143
-
Calculating -------------------------------------
144
-
parse: 39.072 (± 0.0%) i/s - 393.000 in 10.058789s
145
-
render: 86.995 (± 1.1%) i/s - 872.000 in 10.024951s
I've tried to match the benchmark workload to that of the reference implementation, so that we might compare results directly. The workload is meant to be representative of Shopify's use case, although I wouldn't be surprised if their usage has changed subtly since the benchmark fixture was designed.
135
+
Unless you happen to have a relative folder called `templates` with a file called `index.html` within it, we would expect a `TemplateNotFoundError` to be raised when running the example above.
Copy file name to clipboardExpand all lines: contributing.md
+3-5Lines changed: 3 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Contributing to Python Liquid
2
2
3
-
Hi. Your contributions and questions are always welcome. Feel free to ask questions, report bugs or request features on the [issue tracker](https://github.com/jg-rp/liquid/issues) or on [Github Discussions](https://github.com/jg-rp/liquid/discussions).
3
+
Your contributions and questions are always welcome. Feel free to ask questions, report bugs or request features on the [issue tracker](https://github.com/jg-rp/liquid/issues) or on [Github Discussions](https://github.com/jg-rp/liquid/discussions).
4
4
5
5
**Table of contents**
6
6
@@ -52,9 +52,7 @@ Then open `htmlcov/index.html` in your browser.
52
52
53
53
## Documentation
54
54
55
-
[Documentation](https://jg-rp.github.io/liquid/) is built using [Docusaurus](https://docusaurus.io/). Find the source in the [docs branch](https://github.com/jg-rp/liquid/tree/docs) of this repository.
56
-
57
-
The `docs` folder in the root of this repository contains docs generated from Python docstrings, hosted on [Read the Docs](https://liquid.readthedocs.io/en/latest/). The plan is to mirror this API documentation to the Docusaurus site with the help of [Griffe](https://mkdocstrings.github.io/griffe/).
55
+
[Documentation](https://jg-rp.github.io/liquid/) is built using [Material for MkDocs](https://squidfunk.github.io/mkdocs-material/getting-started/). Find the source in the `docs` folder of this repository.
58
56
59
57
## Style Guides
60
58
@@ -64,6 +62,6 @@ There are no hard rules for git commit messages, although you might like to indi
64
62
65
63
### Python Style
66
64
67
-
All Python files are formatted using [Black](https://github.com/psf/black), with its default configuration.
65
+
All Python files are formatted using [Ruff](https://github.com/astral-sh/ruff), configured in `pyproject.toml`
68
66
69
67
Docstrings must use [Google style docstrings](https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html).
0 commit comments