mirror of
https://github.com/askama-rs/askama.git
synced 2025-10-03 07:45:14 +00:00
Rename pluralize
arguments into singular
and plural
This commit is contained in:
parent
6cea91a9b5
commit
7c5deda4c1
@ -232,11 +232,11 @@ impl<'a> Generator<'a, '_> {
|
|||||||
const ARGUMENTS: &[&FilterArgument; 3] = &[
|
const ARGUMENTS: &[&FilterArgument; 3] = &[
|
||||||
FILTER_SOURCE,
|
FILTER_SOURCE,
|
||||||
&FilterArgument {
|
&FilterArgument {
|
||||||
name: "sg",
|
name: "singular",
|
||||||
default_value: Some(SINGULAR),
|
default_value: Some(SINGULAR),
|
||||||
},
|
},
|
||||||
&FilterArgument {
|
&FilterArgument {
|
||||||
name: "pl",
|
name: "plural",
|
||||||
default_value: Some(PLURAL),
|
default_value: Some(PLURAL),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
@ -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
|
The order of the named arguments does not matter, but named arguments must come after
|
||||||
positional (i.e. unnamed) arguments.
|
positional (i.e. unnamed) arguments.
|
||||||
|
|
||||||
E.g. the filter `pluralize` takes two optional arguments: `sg` and `pl` (singular and plural),
|
E.g. the filter `pluralize` takes two optional arguments: `singular` and `plural`
|
||||||
which are `sg = ""` and `pl = "s"` by default.
|
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
|
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]: #capitalize
|
[#capitalize]: #capitalize
|
||||||
@ -415,7 +415,7 @@ hello
|
|||||||
|
|
||||||
```jinja
|
```jinja
|
||||||
{{ integer | pluralize }}
|
{{ integer | pluralize }}
|
||||||
{{ integer | pluralize([sg = ""], [pl = "s"]) }}
|
{{ integer | pluralize([singular = ""], [plural = "s"]) }}
|
||||||
```
|
```
|
||||||
|
|
||||||
<hr style="clear:both; border:0; border-bottom:1pt solid currentColor">
|
<hr style="clear:both; border:0; border-bottom:1pt solid currentColor">
|
||||||
|
@ -29,7 +29,7 @@ fn test_pluralize_two_positional_args() {
|
|||||||
fn test_pluralize_positional_and_named() {
|
fn test_pluralize_positional_and_named() {
|
||||||
#[derive(Template)]
|
#[derive(Template)]
|
||||||
#[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"
|
ext = "txt"
|
||||||
)]
|
)]
|
||||||
struct CountButterflies {
|
struct CountButterflies {
|
||||||
@ -54,7 +54,7 @@ fn test_pluralize_positional_and_named() {
|
|||||||
fn test_pluralize_named_reordered() {
|
fn test_pluralize_named_reordered() {
|
||||||
#[derive(Template)]
|
#[derive(Template)]
|
||||||
#[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"
|
ext = "txt"
|
||||||
)]
|
)]
|
||||||
struct CountButterflies {
|
struct CountButterflies {
|
||||||
@ -79,7 +79,7 @@ fn test_pluralize_named_reordered() {
|
|||||||
fn test_pluralize_defaulted_and_named() {
|
fn test_pluralize_defaulted_and_named() {
|
||||||
#[derive(Template)]
|
#[derive(Template)]
|
||||||
#[template(
|
#[template(
|
||||||
source = r#"I have {{ count }} potato{{ count | pluralize(pl = "es") }}."#,
|
source = r#"I have {{ count }} potato{{ count | pluralize(plural = "es") }}."#,
|
||||||
ext = "txt"
|
ext = "txt"
|
||||||
)]
|
)]
|
||||||
struct CountPotatoes {
|
struct CountPotatoes {
|
||||||
|
@ -2,7 +2,7 @@ use askama::Template;
|
|||||||
|
|
||||||
#[derive(Template)]
|
#[derive(Template)]
|
||||||
#[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"
|
ext = "txt"
|
||||||
)]
|
)]
|
||||||
struct PositionalAfterNamed {
|
struct PositionalAfterNamed {
|
||||||
@ -11,7 +11,7 @@ struct PositionalAfterNamed {
|
|||||||
|
|
||||||
#[derive(Template)]
|
#[derive(Template)]
|
||||||
#[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"
|
ext = "txt"
|
||||||
)]
|
)]
|
||||||
struct NamedRepeated {
|
struct NamedRepeated {
|
||||||
@ -20,7 +20,7 @@ struct NamedRepeated {
|
|||||||
|
|
||||||
#[derive(Template)]
|
#[derive(Template)]
|
||||||
#[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"
|
ext = "txt"
|
||||||
)]
|
)]
|
||||||
struct NamedButAlreadyPositional {
|
struct NamedButAlreadyPositional {
|
||||||
@ -29,7 +29,7 @@ struct NamedButAlreadyPositional {
|
|||||||
|
|
||||||
#[derive(Template)]
|
#[derive(Template)]
|
||||||
#[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"
|
ext = "txt"
|
||||||
)]
|
)]
|
||||||
struct NoSuchNamedArgument {
|
struct NoSuchNamedArgument {
|
||||||
|
@ -1,34 +1,34 @@
|
|||||||
error: named arguments must always be passed last
|
error: named arguments must always be passed last
|
||||||
--> <source attribute>:1:47
|
--> <source attribute>:1:47
|
||||||
"(pl = \"ies\", \"y\") }}."
|
"(plural = \"ies\", \"y\") }}."
|
||||||
--> tests/ui/named_filter_arguments.rs:5:14
|
--> 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
|
||||||
--> <source attribute>:1:47
|
--> <source attribute>:1:47
|
||||||
"(pl = \"y\", pl = \"ies\") }}."
|
"(plural = \"y\", plural = \"ies\") }}."
|
||||||
--> tests/ui/named_filter_arguments.rs:14:14
|
--> 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
|
--> NamedButAlreadyPositional.txt:1:47
|
||||||
"(\"y\", sg = \"ies\") }}."
|
"(\"y\", pl = \"ies\") }}."
|
||||||
--> tests/ui/named_filter_arguments.rs:23:14
|
--> 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
|
--> NoSuchNamedArgument.txt:1:47
|
||||||
"(\"y\", plural = \"ies\") }}."
|
"(\"y\", sg = \"ies\") }}."
|
||||||
--> tests/ui/named_filter_arguments.rs:32:14
|
--> 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
|
error: `uppercase` filter does not have any arguments
|
||||||
--> NamedArgumentButNoArgumentExpected.txt:1:30
|
--> NamedArgumentButNoArgumentExpected.txt:1:30
|
||||||
|
Loading…
x
Reference in New Issue
Block a user