From 7c5deda4c17c70bd0ee5d7638a3141232783a8b6 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 21 Apr 2025 22:46:59 +0200 Subject: [PATCH] Rename `pluralize` arguments into `singular` and `plural` --- askama_derive/src/generator/filter.rs | 4 +-- book/src/filters.md | 8 +++--- testing/tests/named_filter_arguments.rs | 6 ++-- testing/tests/ui/named_filter_arguments.rs | 8 +++--- .../tests/ui/named_filter_arguments.stderr | 28 +++++++++---------- 5 files changed, 27 insertions(+), 27 deletions(-) diff --git a/askama_derive/src/generator/filter.rs b/askama_derive/src/generator/filter.rs index cb27d43a..4a7ead5f 100644 --- a/askama_derive/src/generator/filter.rs +++ b/askama_derive/src/generator/filter.rs @@ -232,11 +232,11 @@ impl<'a> Generator<'a, '_> { const ARGUMENTS: &[&FilterArgument; 3] = &[ FILTER_SOURCE, &FilterArgument { - name: "sg", + name: "singular", default_value: Some(SINGULAR), }, &FilterArgument { - name: "pl", + name: "plural", default_value: Some(PLURAL), }, ]; diff --git a/book/src/filters.md b/book/src/filters.md index c38b4f77..27e61714 100644 --- a/book/src/filters.md +++ b/book/src/filters.md @@ -22,10 +22,10 @@ Built-in filters that take (optional) arguments can be called with named argumen The order of the named arguments does not matter, but named arguments must come after positional (i.e. unnamed) arguments. -E.g. the filter `pluralize` takes two optional arguments: `sg` and `pl` (singular and plural), -which are `sg = ""` and `pl = "s"` by default. +E.g. the filter `pluralize` takes two optional arguments: `singular` and `plural` +which are `singular = ""` and `plural = "s"` by default. If you are fine with the default empty string for the singular, and you only want to set a -specific plural, then you can call the filter like `dog{{ count | pluralize(pl = "gies") }}`. +specific plural, then you can call the filter like `dog{{ count | pluralize(plural = "gies") }}`. ### capitalize [#capitalize]: #capitalize @@ -415,7 +415,7 @@ hello ```jinja {{ integer | pluralize }} -{{ integer | pluralize([sg = ""], [pl = "s"]) }} +{{ integer | pluralize([singular = ""], [plural = "s"]) }} ```
diff --git a/testing/tests/named_filter_arguments.rs b/testing/tests/named_filter_arguments.rs index 5ac4637e..04b624de 100644 --- a/testing/tests/named_filter_arguments.rs +++ b/testing/tests/named_filter_arguments.rs @@ -29,7 +29,7 @@ fn test_pluralize_two_positional_args() { fn test_pluralize_positional_and_named() { #[derive(Template)] #[template( - source = r#"I have {{ count }} butterfl{{ count | pluralize("y", pl = "ies") }}."#, + source = r#"I have {{ count }} butterfl{{ count | pluralize("y", plural = "ies") }}."#, ext = "txt" )] struct CountButterflies { @@ -54,7 +54,7 @@ fn test_pluralize_positional_and_named() { fn test_pluralize_named_reordered() { #[derive(Template)] #[template( - source = r#"I have {{ count }} butterfl{{ count | pluralize(pl = "ies", sg = "y") }}."#, + source = r#"I have {{ count }} butterfl{{ count | pluralize(plural = "ies", singular = "y") }}."#, ext = "txt" )] struct CountButterflies { @@ -79,7 +79,7 @@ fn test_pluralize_named_reordered() { fn test_pluralize_defaulted_and_named() { #[derive(Template)] #[template( - source = r#"I have {{ count }} potato{{ count | pluralize(pl = "es") }}."#, + source = r#"I have {{ count }} potato{{ count | pluralize(plural = "es") }}."#, ext = "txt" )] struct CountPotatoes { diff --git a/testing/tests/ui/named_filter_arguments.rs b/testing/tests/ui/named_filter_arguments.rs index 443e9b79..bc04349c 100644 --- a/testing/tests/ui/named_filter_arguments.rs +++ b/testing/tests/ui/named_filter_arguments.rs @@ -2,7 +2,7 @@ use askama::Template; #[derive(Template)] #[template( - source = r#"I have {{ count }} butterfl{{ count | pluralize(pl = "ies", "y") }}."#, + source = r#"I have {{ count }} butterfl{{ count | pluralize(plural = "ies", "y") }}."#, ext = "txt" )] struct PositionalAfterNamed { @@ -11,7 +11,7 @@ struct PositionalAfterNamed { #[derive(Template)] #[template( - source = r#"I have {{ count }} butterfl{{ count | pluralize(pl = "y", pl = "ies") }}."#, + source = r#"I have {{ count }} butterfl{{ count | pluralize(plural = "y", plural = "ies") }}."#, ext = "txt" )] struct NamedRepeated { @@ -20,7 +20,7 @@ struct NamedRepeated { #[derive(Template)] #[template( - source = r#"I have {{ count }} butterfl{{ count | pluralize("y", sg = "ies") }}."#, + source = r#"I have {{ count }} butterfl{{ count | pluralize("y", pl = "ies") }}."#, ext = "txt" )] struct NamedButAlreadyPositional { @@ -29,7 +29,7 @@ struct NamedButAlreadyPositional { #[derive(Template)] #[template( - source = r#"I have {{ count }} butterfl{{ count | pluralize("y", plural = "ies") }}."#, + source = r#"I have {{ count }} butterfl{{ count | pluralize("y", sg = "ies") }}."#, ext = "txt" )] struct NoSuchNamedArgument { diff --git a/testing/tests/ui/named_filter_arguments.stderr b/testing/tests/ui/named_filter_arguments.stderr index 1dc90593..702ae97a 100644 --- a/testing/tests/ui/named_filter_arguments.stderr +++ b/testing/tests/ui/named_filter_arguments.stderr @@ -1,34 +1,34 @@ error: named arguments must always be passed last --> :1:47 - "(pl = \"ies\", \"y\") }}." + "(plural = \"ies\", \"y\") }}." --> tests/ui/named_filter_arguments.rs:5:14 | -5 | source = r#"I have {{ count }} butterfl{{ count | pluralize(pl = "ies", "y") }}."#, - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +5 | source = r#"I have {{ count }} butterfl{{ count | pluralize(plural = "ies", "y") }}."#, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: named argument `pl` was passed more than once +error: named argument `plural` was passed more than once --> :1:47 - "(pl = \"y\", pl = \"ies\") }}." + "(plural = \"y\", plural = \"ies\") }}." --> tests/ui/named_filter_arguments.rs:14:14 | -14 | source = r#"I have {{ count }} butterfl{{ count | pluralize(pl = "y", pl = "ies") }}."#, - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +14 | source = r#"I have {{ count }} butterfl{{ count | pluralize(plural = "y", plural = "ies") }}."#, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: `sg` argument to `pluralize` filter was already set; its arguments are: ([sg], [pl]) +error: `pluralize` filter does not have an argument `pl`; its arguments are: ([singular], [plural]) --> NamedButAlreadyPositional.txt:1:47 - "(\"y\", sg = \"ies\") }}." + "(\"y\", pl = \"ies\") }}." --> tests/ui/named_filter_arguments.rs:23:14 | -23 | source = r#"I have {{ count }} butterfl{{ count | pluralize("y", sg = "ies") }}."#, +23 | source = r#"I have {{ count }} butterfl{{ count | pluralize("y", pl = "ies") }}."#, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: `pluralize` filter does not have an argument `plural`; its arguments are: ([sg], [pl]) +error: `pluralize` filter does not have an argument `sg`; its arguments are: ([singular], [plural]) --> NoSuchNamedArgument.txt:1:47 - "(\"y\", plural = \"ies\") }}." + "(\"y\", sg = \"ies\") }}." --> tests/ui/named_filter_arguments.rs:32:14 | -32 | source = r#"I have {{ count }} butterfl{{ count | pluralize("y", plural = "ies") }}."#, - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +32 | source = r#"I have {{ count }} butterfl{{ count | pluralize("y", sg = "ies") }}."#, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: `uppercase` filter does not have any arguments --> NamedArgumentButNoArgumentExpected.txt:1:30