Skip to content

Commit

Permalink
Rename as_ref filter into ref
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Jul 1, 2024
1 parent 214c445 commit b37e7d3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
36 changes: 18 additions & 18 deletions book/src/filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ Enable it with Cargo features (see below for more information).
* **[Built-in filters][#built-in-filters]:**

* [`abs`][#abs]
* [`as_ref`][#as_ref]
* [`capitalize`][#capitalize]
* [`center`][#center]
* [`deref`][#deref]
Expand All @@ -35,6 +34,7 @@ Enable it with Cargo features (see below for more information).
* [`linebreaks`][#linebreaks]
* [`linebreaksbr`][#linebreaksbr]
* [`lower|lowercase`][#lower]
* [`ref`][#ref]
* [`safe`][#safe]
* [`title`][#title]
* [`trim`][#trim]
Expand Down Expand Up @@ -66,23 +66,6 @@ Output:
2
```

### as_ref
[#as_ref]: #as_ref

Creates a reference to the given argument.

```jinja
{{ "a"|as_ref }}
{{ self.x|as_ref }}
```

will become:

```rust
&"a"
&self.x
```

### capitalize
[#capitalize]: #capitalize

Expand Down Expand Up @@ -323,6 +306,23 @@ Output:
hello
```

### ref
[#ref]: #ref

Creates a reference to the given argument.

```jinja
{{ "a"|ref }}
{{ self.x|ref }}
```

will become:

```rust
&"a"
&self.x
```

### safe
[#safe]: #safe

Expand Down
4 changes: 2 additions & 2 deletions rinja_derive/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1297,13 +1297,13 @@ impl<'a> Generator<'a> {
filter: &WithSpan<'_, T>,
) -> Result<DisplayWrap, CompileError> {
match name {
"as_ref" => return self._visit_as_ref_filter(ctx, buf, args, filter),
"deref" => return self._visit_deref_filter(ctx, buf, args, filter),
"escape" | "e" => return self._visit_escape_filter(ctx, buf, args, filter),
"fmt" => return self._visit_fmt_filter(ctx, buf, args, filter),
"format" => return self._visit_format_filter(ctx, buf, args, filter),
"join" => return self._visit_join_filter(ctx, buf, args),
"json" | "tojson" => return self._visit_json_filter(ctx, buf, args, filter),
"ref" => return self._visit_ref_filter(ctx, buf, args, filter),
"safe" => return self._visit_safe_filter(ctx, buf, args, filter),
_ => {}
}
Expand All @@ -1318,7 +1318,7 @@ impl<'a> Generator<'a> {
Ok(DisplayWrap::Unwrapped)
}

fn _visit_as_ref_filter<T>(
fn _visit_ref_filter<T>(
&mut self,
ctx: &Context<'_>,
buf: &mut Buffer,
Expand Down
2 changes: 1 addition & 1 deletion testing/tests/filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ fn test_json_script() {

#[derive(rinja::Template)]
#[template(
source = r#"{% let word = s|as_ref %}{{ word }}
source = r#"{% let word = s|ref %}{{ word }}
{%- let hello = String::from("hello") %}
{%- if word|deref == hello %}1{% else %}2{% endif %}"#,
ext = "html"
Expand Down

0 comments on commit b37e7d3

Please sign in to comment.