mirror of
https://github.com/askama-rs/askama.git
synced 2025-10-02 15:25:19 +00:00
Merge pull request #398 from Kijewski/pr-0.13.x-non-breaking
Revert breaking changes in branch v0.13.x
This commit is contained in:
commit
0b1c0e4d35
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "askama"
|
name = "askama"
|
||||||
version = "0.13.0"
|
version = "0.13.1"
|
||||||
description = "Type-safe, compiled Jinja-like templates for Rust"
|
description = "Type-safe, compiled Jinja-like templates for Rust"
|
||||||
keywords = ["markup", "template", "jinja2", "html"]
|
keywords = ["markup", "template", "jinja2", "html"]
|
||||||
categories = ["template-engine"]
|
categories = ["template-engine"]
|
||||||
@ -27,7 +27,7 @@ harness = false
|
|||||||
itoa = "1.0.11"
|
itoa = "1.0.11"
|
||||||
|
|
||||||
# needed by feature "derive"
|
# needed by feature "derive"
|
||||||
askama_derive = { version = "=0.13.0", path = "../askama_derive", default-features = false, optional = true }
|
askama_derive = { version = "=0.13.1", path = "../askama_derive", default-features = false, optional = true }
|
||||||
|
|
||||||
# needed by feature "serde_json"
|
# needed by feature "serde_json"
|
||||||
serde = { version = "1.0", optional = true, default-features = false }
|
serde = { version = "1.0", optional = true, default-features = false }
|
||||||
@ -56,7 +56,7 @@ alloc = [
|
|||||||
blocks = ["askama_derive?/blocks"]
|
blocks = ["askama_derive?/blocks"]
|
||||||
code-in-doc = ["askama_derive?/code-in-doc"]
|
code-in-doc = ["askama_derive?/code-in-doc"]
|
||||||
config = ["askama_derive?/config"]
|
config = ["askama_derive?/config"]
|
||||||
derive = ["dep:askama_derive"]
|
derive = ["askama_derive"]
|
||||||
serde_json = ["std", "askama_derive?/serde_json", "dep:serde", "dep:serde_json"]
|
serde_json = ["std", "askama_derive?/serde_json", "dep:serde", "dep:serde_json"]
|
||||||
std = [
|
std = [
|
||||||
"alloc",
|
"alloc",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "askama_derive"
|
name = "askama_derive"
|
||||||
version = "0.13.0"
|
version = "0.13.1"
|
||||||
description = "Procedural macro package for Askama"
|
description = "Procedural macro package for Askama"
|
||||||
homepage = "https://github.com/askama-rs/askama"
|
homepage = "https://github.com/askama-rs/askama"
|
||||||
repository = "https://github.com/askama-rs/askama"
|
repository = "https://github.com/askama-rs/askama"
|
||||||
|
@ -965,11 +965,7 @@ impl<'a> Generator<'a, '_> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.visit_target(buf, true, true, &l.var);
|
self.visit_target(buf, true, true, &l.var);
|
||||||
// If it's not taking the ownership of a local variable or copyable, then we need to add
|
let (before, after) = if !is_copyable(val) {
|
||||||
// a reference.
|
|
||||||
let (before, after) = if !matches!(**val, Expr::Var(name) if self.locals.get(name).is_some())
|
|
||||||
&& !is_copyable(val)
|
|
||||||
{
|
|
||||||
("&(", ")")
|
("&(", ")")
|
||||||
} else {
|
} else {
|
||||||
("", "")
|
("", "")
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "askama_derive_standalone"
|
name = "askama_derive_standalone"
|
||||||
version = "0.13.0"
|
version = "0.13.1"
|
||||||
description = "Procedural macro package for Askama"
|
description = "Procedural macro package for Askama"
|
||||||
homepage = "https://github.com/askama-rs/askama"
|
homepage = "https://github.com/askama-rs/askama"
|
||||||
repository = "https://github.com/askama-rs/askama"
|
repository = "https://github.com/askama-rs/askama"
|
||||||
@ -23,7 +23,7 @@ required-features = ["__standalone"]
|
|||||||
parser = { package = "askama_parser", version = "=0.13.0", path = "../askama_parser" }
|
parser = { package = "askama_parser", version = "=0.13.0", path = "../askama_parser" }
|
||||||
|
|
||||||
basic-toml = { version = "0.1.1", optional = true }
|
basic-toml = { version = "0.1.1", optional = true }
|
||||||
pulldown-cmark = { version = "0.12.0", optional = true, default-features = false }
|
pulldown-cmark = { version = "0.13.0", optional = true, default-features = false }
|
||||||
serde = { version = "1.0", optional = true }
|
serde = { version = "1.0", optional = true }
|
||||||
serde_derive = { version = "1.0", optional = true }
|
serde_derive = { version = "1.0", optional = true }
|
||||||
|
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "bench-build"
|
name = "bench-build"
|
||||||
version = "0.13.0"
|
version = "0.13.1"
|
||||||
authors = ["askama-rs developers"]
|
authors = ["askama-rs developers"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
rust-version = "1.81"
|
rust-version = "1.81"
|
||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
askama = { path = "../askama", version = "0.13.0", default-features = false, features = ["std"] }
|
askama = { path = "../askama", version = "0.13.1", default-features = false, features = ["std"] }
|
||||||
askama_derive = { path = "../askama_derive", version = "0.13.0", features = ["std"] }
|
askama_derive = { path = "../askama_derive", version = "0.13.1", features = ["std"] }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = []
|
||||||
|
@ -41,8 +41,8 @@ Without the feature, `cargo` will be able to compile more dependencies in parall
|
|||||||
```toml
|
```toml
|
||||||
# Cargo.toml
|
# Cargo.toml
|
||||||
[dependencies]
|
[dependencies]
|
||||||
askama = { version = "0.13.0", default-features = false, features = ["std"] }
|
askama = { version = "0.13.1", default-features = false, features = ["std"] }
|
||||||
askama_derive = { version = "0.13.0", features = ["std"] }
|
askama_derive = { version = "0.13.1", features = ["std"] }
|
||||||
```
|
```
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
|
@ -9,7 +9,7 @@ you have to opt-in to the feature [`"serde_json"`](#serde_json):
|
|||||||
|
|
||||||
```toml
|
```toml
|
||||||
[dependencies]
|
[dependencies]
|
||||||
askama = { version = "0.13.0", features = ["serde_json"] }
|
askama = { version = "0.13.1", features = ["serde_json"] }
|
||||||
```
|
```
|
||||||
|
|
||||||
Please read the [Cargo manual](https://doc.rust-lang.org/cargo/reference/features.html#dependency-features)
|
Please read the [Cargo manual](https://doc.rust-lang.org/cargo/reference/features.html#dependency-features)
|
||||||
@ -28,7 +28,7 @@ You can opt-out of using the feature flags by using
|
|||||||
|
|
||||||
```toml
|
```toml
|
||||||
[dependencies]
|
[dependencies]
|
||||||
askama = { version = "0.13.0", default-features = false }
|
askama = { version = "0.13.1", default-features = false }
|
||||||
```
|
```
|
||||||
|
|
||||||
Without `default-features = false`, i.e with default features enabled,
|
Without `default-features = false`, i.e with default features enabled,
|
||||||
|
@ -65,16 +65,6 @@ Like Rust, Askama also supports shadowing variables.
|
|||||||
|
|
||||||
For compatibility with Jinja, `set` can be used in place of `let`.
|
For compatibility with Jinja, `set` can be used in place of `let`.
|
||||||
|
|
||||||
### Borrow rules
|
|
||||||
|
|
||||||
In some cases, the value of a variable initialization will be put behind a reference
|
|
||||||
to prevent changing ownership. The rules are as follows:
|
|
||||||
|
|
||||||
* If the value is an expression of more than one element (like `x + 2`), it WILL NOT BE put behind a reference.
|
|
||||||
* If the value is a variable defined in the templates, it WILL NOT BE put behind a reference.
|
|
||||||
* If the value has a filter applied to it (`x|capitalize`), it WILL NOT BE put behind a reference.
|
|
||||||
* If the value is a field (`x.y`), it WILL BE put behind a reference.
|
|
||||||
|
|
||||||
## Filters
|
## Filters
|
||||||
|
|
||||||
Values such as those obtained from variables can be post-processed
|
Values such as those obtained from variables can be post-processed
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "actix-web-app"
|
name = "actix-web-app"
|
||||||
version = "0.13.0"
|
version = "0.13.1"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
publish = false
|
publish = false
|
||||||
@ -9,7 +9,7 @@ publish = false
|
|||||||
# and actix-web as your web-framework.
|
# and actix-web as your web-framework.
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-web = { version = "4.9.0", default-features = false, features = ["macros"] }
|
actix-web = { version = "4.9.0", default-features = false, features = ["macros"] }
|
||||||
askama = { version = "0.13.0", path = "../../askama" }
|
askama = { version = "0.13.1", path = "../../askama" }
|
||||||
tokio = { version = "1.43.0", features = ["macros", "rt-multi-thread"] }
|
tokio = { version = "1.43.0", features = ["macros", "rt-multi-thread"] }
|
||||||
|
|
||||||
# serde and strum are used to parse (deserialize) and generate (serialize) information
|
# serde and strum are used to parse (deserialize) and generate (serialize) information
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "axum-app"
|
name = "axum-app"
|
||||||
version = "0.13.0"
|
version = "0.13.1"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
publish = false
|
publish = false
|
||||||
@ -8,7 +8,7 @@ publish = false
|
|||||||
# This is an example application that uses both askama as template engine,
|
# This is an example application that uses both askama as template engine,
|
||||||
# and axum as your web-framework.
|
# and axum as your web-framework.
|
||||||
[dependencies]
|
[dependencies]
|
||||||
askama = { version = "0.13.0", path = "../../askama" }
|
askama = { version = "0.13.1", path = "../../askama" }
|
||||||
axum = "0.8.1"
|
axum = "0.8.1"
|
||||||
tokio = { version = "1.43.0", features = ["macros", "rt-multi-thread"] }
|
tokio = { version = "1.43.0", features = ["macros", "rt-multi-thread"] }
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "poem-app"
|
name = "poem-app"
|
||||||
version = "0.13.0"
|
version = "0.13.1"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
publish = false
|
publish = false
|
||||||
@ -8,7 +8,7 @@ publish = false
|
|||||||
# This is an example application that uses both askama as template engine,
|
# This is an example application that uses both askama as template engine,
|
||||||
# and poem as your web-framework.
|
# and poem as your web-framework.
|
||||||
[dependencies]
|
[dependencies]
|
||||||
askama = { version = "0.13.0", path = "../../askama" }
|
askama = { version = "0.13.1", path = "../../askama" }
|
||||||
poem = "3.1.6"
|
poem = "3.1.6"
|
||||||
tokio = { version = "1.43.0", features = ["macros", "rt-multi-thread"] }
|
tokio = { version = "1.43.0", features = ["macros", "rt-multi-thread"] }
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "actix-web-app"
|
name = "actix-web-app"
|
||||||
version = "0.13.0"
|
version = "0.13.1"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
publish = false
|
publish = false
|
||||||
@ -8,7 +8,7 @@ publish = false
|
|||||||
# This is an example application that uses both askama as template engine,
|
# This is an example application that uses both askama as template engine,
|
||||||
# and rocket as your web-framework.
|
# and rocket as your web-framework.
|
||||||
[dependencies]
|
[dependencies]
|
||||||
askama = { version = "0.13.0", path = "../../askama" }
|
askama = { version = "0.13.1", path = "../../askama" }
|
||||||
rocket = "0.5.1"
|
rocket = "0.5.1"
|
||||||
|
|
||||||
# strum is used to parse and serialize information between web requests,
|
# strum is used to parse and serialize information between web requests,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "salvo-app"
|
name = "salvo-app"
|
||||||
version = "0.13.0"
|
version = "0.13.1"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
publish = false
|
publish = false
|
||||||
@ -8,7 +8,7 @@ publish = false
|
|||||||
# This is an example application that uses both askama as template engine,
|
# This is an example application that uses both askama as template engine,
|
||||||
# and salvo as your web-framework.
|
# and salvo as your web-framework.
|
||||||
[dependencies]
|
[dependencies]
|
||||||
askama = { version = "0.13.0", path = "../../askama" }
|
askama = { version = "0.13.1", path = "../../askama" }
|
||||||
salvo = { version = "0.76.0", default-features = false, features = ["http1", "logging", "server"] }
|
salvo = { version = "0.76.0", default-features = false, features = ["http1", "logging", "server"] }
|
||||||
tokio = { version = "1.43.0", features = ["macros", "rt-multi-thread"] }
|
tokio = { version = "1.43.0", features = ["macros", "rt-multi-thread"] }
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "actix-web-app"
|
name = "actix-web-app"
|
||||||
version = "0.13.0"
|
version = "0.13.1"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
publish = false
|
publish = false
|
||||||
@ -8,7 +8,7 @@ publish = false
|
|||||||
# This is an example application that uses both askama as template engine,
|
# This is an example application that uses both askama as template engine,
|
||||||
# and actix-web as your web-framework.
|
# and actix-web as your web-framework.
|
||||||
[dependencies]
|
[dependencies]
|
||||||
askama = { version = "0.13.0", path = "../../askama" }
|
askama = { version = "0.13.1", path = "../../askama" }
|
||||||
http = "0.2.12"
|
http = "0.2.12"
|
||||||
tokio = { version = "1.43.0", features = ["macros", "rt-multi-thread"] }
|
tokio = { version = "1.43.0", features = ["macros", "rt-multi-thread"] }
|
||||||
warp = "0.3.7"
|
warp = "0.3.7"
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "askama_testing-alloc"
|
name = "askama_testing-alloc"
|
||||||
version = "0.13.0"
|
version = "0.13.1"
|
||||||
authors = ["askama-rs developers"]
|
authors = ["askama-rs developers"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
rust-version = "1.81"
|
rust-version = "1.81"
|
||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
askama = { path = "../askama", version = "0.13.0", default-features = false, features = ["alloc", "derive"] }
|
askama = { path = "../askama", version = "0.13.1", default-features = false, features = ["alloc", "derive"] }
|
||||||
|
|
||||||
assert_matches = "1.5.0"
|
assert_matches = "1.5.0"
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "askama_testing-no-std"
|
name = "askama_testing-no-std"
|
||||||
version = "0.13.0"
|
version = "0.13.1"
|
||||||
authors = ["askama-rs developers"]
|
authors = ["askama-rs developers"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
rust-version = "1.81"
|
rust-version = "1.81"
|
||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
askama = { path = "../askama", version = "0.13.0", default-features = false, features = ["derive"] }
|
askama = { path = "../askama", version = "0.13.1", default-features = false, features = ["derive"] }
|
||||||
|
|
||||||
assert_matches = "1.5.0"
|
assert_matches = "1.5.0"
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "askama_testing-renamed"
|
name = "askama_testing-renamed"
|
||||||
version = "0.13.0"
|
version = "0.13.1"
|
||||||
authors = ["askama-rs developers"]
|
authors = ["askama-rs developers"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
rust-version = "1.81"
|
rust-version = "1.81"
|
||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
some_name = { package = "askama", path = "../askama", version = "0.13.0", default-features = false, features = ["derive"] }
|
some_name = { package = "askama", path = "../askama", version = "0.13.1", default-features = false, features = ["derive"] }
|
||||||
|
|
||||||
assert_matches = "1.5.0"
|
assert_matches = "1.5.0"
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "askama_testing"
|
name = "askama_testing"
|
||||||
version = "0.13.0"
|
version = "0.13.1"
|
||||||
authors = ["askama-rs developers"]
|
authors = ["askama-rs developers"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
rust-version = "1.81"
|
rust-version = "1.81"
|
||||||
@ -15,7 +15,7 @@ name = "normalize_identifier"
|
|||||||
harness = false
|
harness = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
askama = { path = "../askama", version = "0.13.0" }
|
askama = { path = "../askama", version = "0.13.1" }
|
||||||
|
|
||||||
serde_json = { version = "1.0", optional = true }
|
serde_json = { version = "1.0", optional = true }
|
||||||
|
|
||||||
@ -23,7 +23,7 @@ serde_json = { version = "1.0", optional = true }
|
|||||||
core = { package = "intentionally-empty", version = "1.0.0" }
|
core = { package = "intentionally-empty", version = "1.0.0" }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
askama = { path = "../askama", version = "0.13.0", features = ["blocks", "code-in-doc", "serde_json"] }
|
askama = { path = "../askama", version = "0.13.1", features = ["blocks", "code-in-doc", "serde_json"] }
|
||||||
|
|
||||||
assert_matches = "1.5.0"
|
assert_matches = "1.5.0"
|
||||||
criterion = "0.5"
|
criterion = "0.5"
|
||||||
|
@ -151,48 +151,3 @@ fn test_not_moving_fields_in_var() {
|
|||||||
};
|
};
|
||||||
assert_eq!(x.render().unwrap(), "a/a");
|
assert_eq!(x.render().unwrap(), "a/a");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure that using a local variable as value when creating
|
|
||||||
// another variable will not be behind a reference.
|
|
||||||
#[test]
|
|
||||||
fn test_moving_local_vars() {
|
|
||||||
#[derive(Template)]
|
|
||||||
#[template(
|
|
||||||
source = r#"
|
|
||||||
{%- let a = 1 -%}
|
|
||||||
{%- if a == 1 %}A{% endif -%}
|
|
||||||
{%- let b = a -%}
|
|
||||||
{%- if b == 1 %}B{% endif -%}
|
|
||||||
{%- let c = a + 0 -%}
|
|
||||||
{%- if c == 1 %}C{% endif -%}
|
|
||||||
{% let d = x %}
|
|
||||||
{%- if *d == 1 %}D{% endif -%}
|
|
||||||
{%- let e = y -%}
|
|
||||||
{%- if e == "a" %}E{% endif -%}
|
|
||||||
{%- let f = Bla::new() -%}
|
|
||||||
{%- if f.x == 0 %}F{% endif -%}
|
|
||||||
{%- let g = f.x -%}
|
|
||||||
{%- if *g == 0 %}G{% endif -%}
|
|
||||||
"#,
|
|
||||||
ext = "txt"
|
|
||||||
)]
|
|
||||||
struct X {
|
|
||||||
x: u32,
|
|
||||||
y: String,
|
|
||||||
}
|
|
||||||
struct Bla {
|
|
||||||
x: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Bla {
|
|
||||||
fn new() -> Self {
|
|
||||||
Self { x: 0 }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let x = X {
|
|
||||||
x: 1,
|
|
||||||
y: "a".to_owned(),
|
|
||||||
};
|
|
||||||
assert_eq!(x.render().unwrap(), "ABCDEFG");
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user