590 Commits

Author SHA1 Message Date
René Kijewski
08674bde11 derive: without rendered message for now 2024-07-29 21:57:28 +02:00
René Kijewski
821a147b37 Doens't work: no indentation 2024-07-29 18:38:32 +02:00
René Kijewski
2e887a56a6 derive: use config span in error message 2024-07-29 16:50:39 +02:00
René Kijewski
c3639ec14a derive: use source/path as error source span 2024-07-29 15:48:18 +02:00
René Kijewski
fa8c936cff derive: way less noisy error messages 2024-07-29 13:46:31 +02:00
René Kijewski
380ecc1d8e derive: properly display error locations 2024-07-29 05:05:00 +02:00
Guillaume Gomez
e74f0d20ba Change the error message to make it start at the as keyword 2024-07-28 21:37:22 +02:00
René Kijewski
a6a474514e Implement operator as in template language
Because it is not always super obvious if an identifier refers to `T` or
`&T`, any references are automatically followed.
2024-07-28 18:02:14 +02:00
Guillaume Gomez
fcf1a97d9d Add tests for if (not) defined feature 2024-07-24 13:14:51 +02:00
René Kijewski
b593f1ffa7 parser: better error msg for unkn. number suffices 2024-07-20 12:15:13 +02:00
René Kijewski
5163e38355 filters: proper escaping for |linebreaks and friends
The filters `|linebreaks`, `|linebreaksbr` and `|paragraphbreaks`
generate HTML code to be embedded in a page. Having to specify that the
output of these filters is `|safe` is cumbersome. Also, these filters
need to operate on already escaped HTML data. This could be done by
writing `{{ s|escape|linebreaks|safe }}`.

This PR does the input and output formatting escaping for the user. The
input gets escaped for HTML (invariant of the selected escaper), and the
output gets marked as HTML safe.
2024-07-13 14:44:28 +02:00
René Kijewski
fba84762cf tests: remove stray print = "code" 2024-07-13 13:12:23 +02:00
René Kijewski
10e67fa312 Reimplement {% filter %} block
This PR reimplements the code generation for `{% filter %}` blocks, so
that the data is written directly into its destination writer, without
using a buffer. This way it behaves like a specialized
`{{ expr|filter1|filter2 }}` would, if the `expr` was a `Template` that
contained the body of the filter block.
2024-07-13 11:11:04 +02:00
René Kijewski
cd6b4ad49b
Merge pull request #76 from GuillaumeGomez/update-authors
Update authors list for `testing/Cargo.toml`
2024-07-13 10:48:08 +02:00
Guillaume Gomez
ee054c4f07 Update authors list for testing/Cargo.toml 2024-07-13 10:35:43 +02:00
Guillaume Gomez
b753dd6e4d Add more tests for filter block feature 2024-07-13 10:29:11 +02:00
René Kijewski
34073642b1 Run typos to fix typos 2024-07-12 07:07:00 +02:00
Sheldon Young
39e3c951f4
phf should be a dev dependency
The `phf` crate is used in a benchmark for testing identifier normalization but not in the library itself.  This moves it to be a dev dependency.
2024-07-11 12:13:56 -07:00
René Kijewski
85330b353a Raise the MSRV to 1.71 2024-07-10 21:38:43 +02:00
René Kijewski
277cff4ebf Reset all version numbers to 0.2.0 2024-07-09 12:48:41 +02:00
René Kijewski
1017451579 Speed-up HTML escaping by using equal sized entities
By using codepoint entities like `'&'` → `"&"`, we have a much
smaller lookup table (58 bytes instead of 29× pointer size ~= 232
bytes). This makes the cache happy, and the benchmark run about ~20%
faster.

```text
$ cargo bench --bench escape
Escaping                time:   [3.4087 µs 3.4126 µs 3.4168 µs]
                        change: [-19.790% -19.580% -19.354%] (p = 0.00 < 0.05)
                        Performance has improved.
```
2024-07-08 00:52:56 +02:00
René Kijewski
9beca5ed10 Add MsgValidEscapers to show list of configured escapers 2024-07-07 22:51:57 +02:00
René Kijewski
6b0ea27742 More useful error message and UI tests for missing escaper 2024-07-07 22:51:23 +02:00
René Kijewski
6a6994670d Show error reason when template could not be read 2024-07-04 11:02:58 +02:00
René Kijewski
ee3a9e675a Add .rustfmt.toml configuration
This PR configures the formatting with a few defaults that aid
readability, in my opinion. One drawback of adding this file is that
rustfmt uses unstable features, now, and you have to use nightly to run
it:

```sh
cargo +nightly fmt --all
```
2024-07-04 07:05:57 +02:00
Guillaume Gomez
37c300d483
Merge pull request #42 from GuillaumeGomez/top-level-nodes-errors
Generate better errors for top level nodes
2024-07-03 10:39:33 +02:00
René Kijewski
d4b363b9a4 Dedup top-level check in heritage 2024-07-03 01:18:36 +02:00
Guillaume Gomez
e7f2979b73 Add regression test for moving variables in let statement 2024-07-02 22:40:09 +02:00
Guillaume Gomez
27e12f083b Add UI tests for top level nodes 2024-07-02 22:15:02 +02:00
René Kijewski
145127e241
Merge pull request #40 from GuillaumeGomez/rename-as_ref
Rename `as_ref` filter into `ref`
2024-07-02 15:49:17 +02:00
Guillaume Gomez
6c46e4f7b8 Update tests about methods use 2024-07-02 13:44:27 +02:00
René Kijewski
79e747a28a
Merge pull request #39 from GuillaumeGomez/ref-deref-ops
Allow to use `*` and `&` in expressions
2024-07-02 02:03:25 +02:00
Guillaume Gomez
e5a3e1c763 Add regression test for * and & in expressions 2024-07-01 21:11:41 +02:00
Guillaume Gomez
b37e7d3703 Rename as_ref filter into ref 2024-07-01 21:09:18 +02:00
Guillaume Gomez
62bbece0aa Add regression test to prevent moving variables 2024-07-01 18:05:16 +02:00
René Kijewski
f4ccdb6585 Better information that .. must come last in a named struct 2024-06-28 23:32:13 +02:00
René Kijewski
0d8373e3b2 Linted 2024-06-28 23:06:21 +02:00
René Kijewski
cf4f514d7e Move passing tests 2024-06-28 23:03:22 +02:00
René Kijewski
6b8b97672a Better error message on missing comma 2024-06-28 22:48:45 +02:00
Guillaume Gomez
6ee3765098 Add regression test for .. pattern in structs 2024-06-28 05:25:21 +02:00
René Kijewski
e94525f483 Add support for .. in let pattern matching for structs 2024-06-28 05:25:21 +02:00
René Kijewski
dcabf0cf1a feature: serde-json → serde_json 2024-06-27 14:25:22 +02:00
René Kijewski
64a8094aaf Split pretty and ugly JSON filter impl 2024-06-27 14:25:22 +02:00
René Kijewski
f7710a94d6 Add "json: too many args" ui test 2024-06-25 00:42:28 +02:00
René Kijewski
462c04c0a0 Make JSON prettifying optional
This PR adds an optional argument to the `|tojson` filter, which
controls if the serialized JSON data gets prettified or not. The
arguments works the same as flask's [`|tojson`][flask] filter, which
passes the argument to python's [`json.dumps()`][python]:

* Omitting the argument, providing a negative integer, or `None`, then
  compact JSON data is generated.
* Providing a non-negative integer, then this amount of ASCII spaces is
  used to indent the data. (Capped to 16 characters.)
* Providing a string, then this string is used as prefix. I attempts are
  made to ensure that the prefix actually consists of whitespaces,
  because chances are, that if you provide e.g. `&nsbp;`, then you are
  doing it intentionally.

This is a breaking change, because it changes the default behavior to
not prettify the data. This is done intentionally, because this is how
it works in flask.

[flask]: https://jinja.palletsprojects.com/en/3.1.x/templates/#jinja-filters.tojson
[python]: https://docs.python.org/3/library/json.html#json.dump
2024-06-25 00:12:25 +02:00
Guillaume Gomez
fd1108c4bc
Merge pull request #18 from Kijewski/pr-iso646
Use ISO 646 alternative operators for bit ops + proper error messages for spaces around the `|filter` operator
2024-06-24 14:04:53 +02:00
Guillaume Gomez
1f1cff059d Update ui tests 2024-06-23 20:55:23 +02:00
René Kijewski
50ac555684 Remove helper functions 2024-06-23 20:55:00 +02:00
René Kijewski
fb4d8a6073 Better error message for space + filter 2024-06-23 20:54:28 +02:00
René Kijewski
879d889bb2 Use ISO 646 alternative operators for bit ops
This change allows simplifying the use of filter expressions, because
you won't have to care about spaces around the `|` pipe operator.
2024-06-23 20:47:27 +02:00