mirror of
https://github.com/askama-rs/askama.git
synced 2025-09-30 14:31:36 +00:00
Rename rinja
into askama
This commit is contained in:
parent
0b098f1dd0
commit
3b52c907c3
16
.github/workflows/rust.yml
vendored
16
.github/workflows/rust.yml
vendored
@ -16,7 +16,7 @@ jobs:
|
|||||||
Rustfmt:
|
Rustfmt:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
# No need to test `rinja_derive_standalone`. It has same the `src` folder as `rinja_derive`.
|
# No need to test `askama_derive_standalone`. It has same the `src` folder as `askama_derive`.
|
||||||
# No need to run the checks in parallel. They are fast enough.
|
# No need to run the checks in parallel. They are fast enough.
|
||||||
# No need for caching. No code is compiled at all.
|
# No need for caching. No code is compiled at all.
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
@ -27,7 +27,7 @@ jobs:
|
|||||||
set -eu
|
set -eu
|
||||||
for PKG in \
|
for PKG in \
|
||||||
bench-build examples/actix-web-app examples/axum-app examples/poem-app examples/rocket-app examples/salvo-app examples/warp-app fuzzing \
|
bench-build examples/actix-web-app examples/axum-app examples/poem-app examples/rocket-app examples/salvo-app examples/warp-app fuzzing \
|
||||||
rinja rinja_derive rinja_derive_standalone rinja_parser \
|
askama askama_derive askama_derive_standalone askama_parser \
|
||||||
testing testing-alloc testing-no-std testing-renamed
|
testing testing-alloc testing-no-std testing-renamed
|
||||||
do
|
do
|
||||||
cd "$PKG"
|
cd "$PKG"
|
||||||
@ -39,7 +39,7 @@ jobs:
|
|||||||
Docs:
|
Docs:
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
package: [rinja, rinja_derive, rinja_parser]
|
package: [askama, askama_derive, askama_parser]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
@ -117,7 +117,7 @@ jobs:
|
|||||||
set -eu
|
set -eu
|
||||||
for PKG in \
|
for PKG in \
|
||||||
bench-build examples/actix-web-app examples/axum-app examples/poem-app examples/rocket-app examples/salvo-app examples/warp-app fuzzing \
|
bench-build examples/actix-web-app examples/axum-app examples/poem-app examples/rocket-app examples/salvo-app examples/warp-app fuzzing \
|
||||||
rinja rinja_derive rinja_derive_standalone rinja_parser \
|
askama askama_derive askama_derive_standalone askama_parser \
|
||||||
testing testing-alloc testing-no-std testing-renamed
|
testing testing-alloc testing-no-std testing-renamed
|
||||||
do
|
do
|
||||||
cd "$PKG"
|
cd "$PKG"
|
||||||
@ -160,7 +160,7 @@ jobs:
|
|||||||
matrix:
|
matrix:
|
||||||
package: [
|
package: [
|
||||||
bench-build, examples/actix-web-app, examples/axum-app, examples/poem-app, examples/rocket-app, examples/salvo-app, examples/warp-app, fuzzing,
|
bench-build, examples/actix-web-app, examples/axum-app, examples/poem-app, examples/rocket-app, examples/salvo-app, examples/warp-app, fuzzing,
|
||||||
rinja, rinja_derive, rinja_derive_standalone, rinja_parser,
|
askama, askama_derive, askama_derive_standalone, askama_parser,
|
||||||
testing, testing-alloc, testing-no-std, testing-renamed,
|
testing, testing-alloc, testing-no-std, testing-renamed,
|
||||||
]
|
]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@ -185,7 +185,7 @@ jobs:
|
|||||||
- uses: dtolnay/rust-toolchain@master
|
- uses: dtolnay/rust-toolchain@master
|
||||||
with:
|
with:
|
||||||
toolchain: "1.81.0"
|
toolchain: "1.81.0"
|
||||||
- run: cargo check --lib -p rinja --all-features
|
- run: cargo check --lib -p askama --all-features
|
||||||
|
|
||||||
####################################################################################################
|
####################################################################################################
|
||||||
# STEP 2: SLOW
|
# STEP 2: SLOW
|
||||||
@ -228,12 +228,12 @@ jobs:
|
|||||||
id: build
|
id: build
|
||||||
uses: google/oss-fuzz/infra/cifuzz/actions/build_fuzzers@master
|
uses: google/oss-fuzz/infra/cifuzz/actions/build_fuzzers@master
|
||||||
with:
|
with:
|
||||||
oss-fuzz-project-name: rinja
|
oss-fuzz-project-name: askama
|
||||||
language: rust
|
language: rust
|
||||||
- name: Run Fuzzers
|
- name: Run Fuzzers
|
||||||
uses: google/oss-fuzz/infra/cifuzz/actions/run_fuzzers@master
|
uses: google/oss-fuzz/infra/cifuzz/actions/run_fuzzers@master
|
||||||
with:
|
with:
|
||||||
oss-fuzz-project-name: rinja
|
oss-fuzz-project-name: askama
|
||||||
language: rust
|
language: rust
|
||||||
fuzz-seconds: 600
|
fuzz-seconds: 600
|
||||||
output-sarif: true
|
output-sarif: true
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
[workspace]
|
[workspace]
|
||||||
members = [
|
members = [
|
||||||
"rinja",
|
"askama",
|
||||||
"rinja_derive",
|
"askama_derive",
|
||||||
"rinja_parser",
|
"askama_parser",
|
||||||
"testing",
|
"testing",
|
||||||
"testing-alloc",
|
"testing-alloc",
|
||||||
"testing-no-std",
|
"testing-no-std",
|
||||||
|
32
README.md
32
README.md
@ -1,25 +1,25 @@
|
|||||||
# rinja
|
# askama
|
||||||
|
|
||||||
[](https://crates.io/crates/rinja)
|
[](https://crates.io/crates/askama)
|
||||||
[](https://github.com/rinja-rs/rinja/actions/workflows/rust.yml)
|
[](https://github.com/askama-rs/askama/actions/workflows/rust.yml)
|
||||||
[](https://rinja.readthedocs.io/)
|
[](https://askama.readthedocs.io/)
|
||||||
[](https://docs.rs/rinja/)
|
[](https://docs.rs/askama/)
|
||||||
|
|
||||||
**Rinja** implements a template rendering engine based on [Jinja](https://jinja.palletsprojects.com/),
|
**Askama** implements a template rendering engine based on [Jinja](https://jinja.palletsprojects.com/),
|
||||||
and generates type-safe Rust code from your templates at compile time
|
and generates type-safe Rust code from your templates at compile time
|
||||||
based on a user-defined `struct` to hold the template's context.
|
based on a user-defined `struct` to hold the template's context.
|
||||||
See below for an example. It is a fork of [Askama](https://crates.io/crates/askama), please have a look at our
|
|
||||||
[blog post](https://blog.guillaume-gomez.fr/articles/2024-07-31+docs.rs+switching+jinja+template+framework+from+tera+to+rinja)
|
At some point, **Askama** got forked into **Rinja** (explained [here](https://blog.guillaume-gomez.fr/articles/2024-07-31+docs.rs+switching+jinja+template+framework+from+tera+to+rinja))
|
||||||
highlighting differences between the two crates.
|
before getting merged back into **Askama**.
|
||||||
|
|
||||||
All feedback welcome! Feel free to file bugs, requests for documentation and
|
All feedback welcome! Feel free to file bugs, requests for documentation and
|
||||||
any other feedback to the [issue tracker][issues].
|
any other feedback to the [issue tracker][issues].
|
||||||
|
|
||||||
You can find the documentation about our syntax, features, configuration in our book:
|
You can find the documentation about our syntax, features, configuration in our book:
|
||||||
[rinja.readthedocs.io](https://rinja.readthedocs.io/).
|
[askama.readthedocs.io](https://askama.readthedocs.io/).
|
||||||
|
|
||||||
Have a look at our [*Rinja Playground*](https://rinja-rs.github.io/play-rinja/),
|
Have a look at our [*Askama Playground*](https://askama-rs.github.io/play-askama/),
|
||||||
if you want to try out rinja's code generation online.
|
if you want to try out askama's code generation online.
|
||||||
|
|
||||||
### Feature highlights
|
### Feature highlights
|
||||||
|
|
||||||
@ -41,16 +41,16 @@ if you want to try out rinja's code generation online.
|
|||||||
* Opt-out HTML escaping
|
* Opt-out HTML escaping
|
||||||
* Syntax customization
|
* Syntax customization
|
||||||
|
|
||||||
[issues]: https://github.com/rinja-rs/rinja/issues
|
[issues]: https://github.com/askama-rs/askama/issues
|
||||||
|
|
||||||
|
|
||||||
How to get started
|
How to get started
|
||||||
------------------
|
------------------
|
||||||
|
|
||||||
First, add the rinja dependency to your crate's `Cargo.toml`:
|
First, add the askama dependency to your crate's `Cargo.toml`:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
cargo add rinja
|
cargo add askama
|
||||||
```
|
```
|
||||||
|
|
||||||
Now create a directory called `templates` in your crate root.
|
Now create a directory called `templates` in your crate root.
|
||||||
@ -63,7 +63,7 @@ Hello, {{ name }}!
|
|||||||
In any Rust file inside your crate, add the following:
|
In any Rust file inside your crate, add the following:
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
use rinja::Template; // bring trait in scope
|
use askama::Template; // bring trait in scope
|
||||||
|
|
||||||
#[derive(Template)] // this will generate the code...
|
#[derive(Template)] // this will generate the code...
|
||||||
#[template(path = "hello.html")] // using the template in this path, relative
|
#[template(path = "hello.html")] // using the template in this path, relative
|
||||||
|
@ -8,10 +8,10 @@ extend-exclude = [
|
|||||||
"fuzzing/fuzz/artifacts/",
|
"fuzzing/fuzz/artifacts/",
|
||||||
"fuzzing/fuzz/corpus/",
|
"fuzzing/fuzz/corpus/",
|
||||||
"target/",
|
"target/",
|
||||||
"rinja_parser/tests/*.txt",
|
"askama_parser/tests/*.txt",
|
||||||
"testing/templates/fuzzed-*",
|
"testing/templates/fuzzed-*",
|
||||||
# filler texts
|
# filler texts
|
||||||
"rinja/benches/strings.inc",
|
"askama/benches/strings.inc",
|
||||||
# too many false positives
|
# too many false positives
|
||||||
"testing/tests/gen_ws_tests.py",
|
"testing/tests/gen_ws_tests.py",
|
||||||
]
|
]
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "rinja"
|
name = "askama"
|
||||||
version = "0.3.5"
|
version = "0.3.5"
|
||||||
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"]
|
||||||
homepage = "https://rinja.readthedocs.io/"
|
homepage = "https://askama.readthedocs.io/"
|
||||||
repository = "https://github.com/rinja-rs/rinja"
|
repository = "https://github.com/askama-rs/askama"
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
rust-version = "1.81"
|
rust-version = "1.81"
|
||||||
@ -27,7 +27,7 @@ harness = false
|
|||||||
itoa = "1.0.11"
|
itoa = "1.0.11"
|
||||||
|
|
||||||
# needed by feature "derive"
|
# needed by feature "derive"
|
||||||
rinja_derive = { version = "=0.3.5", path = "../rinja_derive", default-features = false, optional = true }
|
askama_derive = { version = "=0.3.5", 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 }
|
||||||
@ -44,25 +44,25 @@ criterion = "0.5"
|
|||||||
maintenance = { status = "actively-developed" }
|
maintenance = { status = "actively-developed" }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["config", "derive", "std", "urlencode", "rinja_derive?/default"]
|
default = ["config", "derive", "std", "urlencode", "askama_derive?/default"]
|
||||||
full = ["default", "blocks", "code-in-doc", "serde_json", "rinja_derive?/full"]
|
full = ["default", "blocks", "code-in-doc", "serde_json", "askama_derive?/full"]
|
||||||
|
|
||||||
alloc = [
|
alloc = [
|
||||||
"rinja_derive?/alloc",
|
"askama_derive?/alloc",
|
||||||
"serde?/alloc",
|
"serde?/alloc",
|
||||||
"serde_json?/alloc",
|
"serde_json?/alloc",
|
||||||
"percent-encoding?/alloc",
|
"percent-encoding?/alloc",
|
||||||
]
|
]
|
||||||
blocks = ["rinja_derive?/blocks"]
|
blocks = ["askama_derive?/blocks"]
|
||||||
code-in-doc = ["rinja_derive?/code-in-doc"]
|
code-in-doc = ["askama_derive?/code-in-doc"]
|
||||||
config = ["rinja_derive?/config"]
|
config = ["askama_derive?/config"]
|
||||||
derive = ["rinja_derive"]
|
derive = ["askama_derive"]
|
||||||
serde_json = ["std", "rinja_derive?/serde_json", "dep:serde", "dep:serde_json"]
|
serde_json = ["std", "askama_derive?/serde_json", "dep:serde", "dep:serde_json"]
|
||||||
std = [
|
std = [
|
||||||
"alloc",
|
"alloc",
|
||||||
"rinja_derive?/std",
|
"askama_derive?/std",
|
||||||
"serde?/std",
|
"serde?/std",
|
||||||
"serde_json?/std",
|
"serde_json?/std",
|
||||||
"percent-encoding?/std",
|
"percent-encoding?/std",
|
||||||
]
|
]
|
||||||
urlencode = ["rinja_derive?/urlencode", "dep:percent-encoding"]
|
urlencode = ["askama_derive?/urlencode", "dep:percent-encoding"]
|
@ -1,5 +1,5 @@
|
|||||||
|
use askama::filters::{Html, escape};
|
||||||
use criterion::{Criterion, black_box, criterion_group, criterion_main};
|
use criterion::{Criterion, black_box, criterion_group, criterion_main};
|
||||||
use rinja::filters::{Html, escape};
|
|
||||||
|
|
||||||
criterion_main!(benches);
|
criterion_main!(benches);
|
||||||
criterion_group!(benches, functions);
|
criterion_group!(benches, functions);
|
@ -1,5 +1,5 @@
|
|||||||
|
use askama::Template;
|
||||||
use criterion::{Criterion, black_box, criterion_group, criterion_main};
|
use criterion::{Criterion, black_box, criterion_group, criterion_main};
|
||||||
use rinja::Template;
|
|
||||||
|
|
||||||
criterion_main!(benches);
|
criterion_main!(benches);
|
||||||
criterion_group!(benches, functions);
|
criterion_group!(benches, functions);
|
@ -10,7 +10,7 @@ use std::io;
|
|||||||
/// The [`Result`](std::result::Result) type with [`Error`] as default error type
|
/// The [`Result`](std::result::Result) type with [`Error`] as default error type
|
||||||
pub type Result<I, E = Error> = core::result::Result<I, E>;
|
pub type Result<I, E = Error> = core::result::Result<I, E>;
|
||||||
|
|
||||||
/// rinja's error type
|
/// askama's error type
|
||||||
///
|
///
|
||||||
/// Used as error value for e.g. [`Template::render()`][crate::Template::render()]
|
/// Used as error value for e.g. [`Template::render()`][crate::Template::render()]
|
||||||
/// and custom filters.
|
/// and custom filters.
|
||||||
@ -159,7 +159,7 @@ fn error_from_stderror(err: Box<dyn StdError + Send + Sync>, unwraps: usize) ->
|
|||||||
Ok(err) => error_from_io_error(*err, unwraps),
|
Ok(err) => error_from_io_error(*err, unwraps),
|
||||||
Err(_) => Error::Fmt, // unreachable
|
Err(_) => Error::Fmt, // unreachable
|
||||||
},
|
},
|
||||||
ErrorKind::Rinja => match err.downcast() {
|
ErrorKind::Askama => match err.downcast() {
|
||||||
Ok(err) => *err,
|
Ok(err) => *err,
|
||||||
Err(_) => Error::Fmt, // unreachable
|
Err(_) => Error::Fmt, // unreachable
|
||||||
},
|
},
|
||||||
@ -179,7 +179,7 @@ fn error_from_io_error(err: io::Error, unwraps: usize) -> Error {
|
|||||||
};
|
};
|
||||||
match ErrorKind::inspect(inner) {
|
match ErrorKind::inspect(inner) {
|
||||||
ErrorKind::Fmt => Error::Fmt,
|
ErrorKind::Fmt => Error::Fmt,
|
||||||
ErrorKind::Rinja => match err.downcast() {
|
ErrorKind::Askama => match err.downcast() {
|
||||||
Ok(err) => err,
|
Ok(err) => err,
|
||||||
Err(_) => Error::Fmt, // unreachable
|
Err(_) => Error::Fmt, // unreachable
|
||||||
},
|
},
|
||||||
@ -207,7 +207,7 @@ enum ErrorKind {
|
|||||||
Json,
|
Json,
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
Io,
|
Io,
|
||||||
Rinja,
|
Askama,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "alloc")]
|
#[cfg(feature = "alloc")]
|
||||||
@ -223,7 +223,7 @@ impl ErrorKind {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err.is::<Error>() {
|
if err.is::<Error>() {
|
||||||
return ErrorKind::Rinja;
|
return ErrorKind::Askama;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "serde_json")]
|
#[cfg(feature = "serde_json")]
|
||||||
@ -264,7 +264,7 @@ pub trait ResultConverter {
|
|||||||
type Input;
|
type Input;
|
||||||
|
|
||||||
/// Consume an interior mutable `self`, and turn it into a [`crate::Result`]
|
/// Consume an interior mutable `self`, and turn it into a [`crate::Result`]
|
||||||
fn rinja_conv_result(self, result: Self::Input) -> Result<Self::Value, Error>;
|
fn askama_conv_result(self, result: Self::Input) -> Result<Self::Value, Error>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Helper marker to be used with [`ResultConverter`]
|
/// Helper marker to be used with [`ResultConverter`]
|
||||||
@ -288,7 +288,7 @@ where
|
|||||||
type Input = Result<T, E>;
|
type Input = Result<T, E>;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn rinja_conv_result(self, result: Self::Input) -> Result<Self::Value, Error> {
|
fn askama_conv_result(self, result: Self::Input) -> Result<Self::Value, Error> {
|
||||||
result.map_err(Error::custom)
|
result.map_err(Error::custom)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -301,7 +301,7 @@ where
|
|||||||
type Input = Result<T, E>;
|
type Input = Result<T, E>;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn rinja_conv_result(self, result: Self::Input) -> Result<Self::Value, Error> {
|
fn askama_conv_result(self, result: Self::Input) -> Result<Self::Value, Error> {
|
||||||
result.map_err(Into::into)
|
result.map_err(Into::into)
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -32,7 +32,7 @@ macro_rules! try_to_str {
|
|||||||
/// The *second* argument to this filter must be a string literal (as in normal
|
/// The *second* argument to this filter must be a string literal (as in normal
|
||||||
/// Rust). The two arguments are passed through to the `format!()`
|
/// Rust). The two arguments are passed through to the `format!()`
|
||||||
/// [macro](https://doc.rust-lang.org/stable/std/macro.format.html) by
|
/// [macro](https://doc.rust-lang.org/stable/std/macro.format.html) by
|
||||||
/// the Rinja code generator, but the order is swapped to support filter
|
/// the Askama code generator, but the order is swapped to support filter
|
||||||
/// composition.
|
/// composition.
|
||||||
///
|
///
|
||||||
/// ```ignore
|
/// ```ignore
|
||||||
@ -41,7 +41,7 @@ macro_rules! try_to_str {
|
|||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # #[cfg(feature = "code-in-doc")] {
|
/// # #[cfg(feature = "code-in-doc")] {
|
||||||
/// # use rinja::Template;
|
/// # use askama::Template;
|
||||||
/// /// ```jinja
|
/// /// ```jinja
|
||||||
/// /// <div>{{ value|fmt("{:?}") }}</div>
|
/// /// <div>{{ value|fmt("{:?}") }}</div>
|
||||||
/// /// ```
|
/// /// ```
|
||||||
@ -66,7 +66,7 @@ pub fn fmt() {}
|
|||||||
/// The first argument to this filter must be a string literal (as in normal
|
/// The first argument to this filter must be a string literal (as in normal
|
||||||
/// Rust). All arguments are passed through to the `format!()`
|
/// Rust). All arguments are passed through to the `format!()`
|
||||||
/// [macro](https://doc.rust-lang.org/stable/std/macro.format.html) by
|
/// [macro](https://doc.rust-lang.org/stable/std/macro.format.html) by
|
||||||
/// the Rinja code generator.
|
/// the Askama code generator.
|
||||||
///
|
///
|
||||||
/// ```ignore
|
/// ```ignore
|
||||||
/// {{ "{:?}{:?}"|format(value, other_value) }}
|
/// {{ "{:?}{:?}"|format(value, other_value) }}
|
||||||
@ -74,7 +74,7 @@ pub fn fmt() {}
|
|||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # #[cfg(feature = "code-in-doc")] {
|
/// # #[cfg(feature = "code-in-doc")] {
|
||||||
/// # use rinja::Template;
|
/// # use askama::Template;
|
||||||
/// /// ```jinja
|
/// /// ```jinja
|
||||||
/// /// <div>{{ "{:?}"|format(value) }}</div>
|
/// /// <div>{{ "{:?}"|format(value) }}</div>
|
||||||
/// /// ```
|
/// /// ```
|
||||||
@ -101,7 +101,7 @@ pub fn format() {}
|
|||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # #[cfg(feature = "code-in-doc")] {
|
/// # #[cfg(feature = "code-in-doc")] {
|
||||||
/// # use rinja::Template;
|
/// # use askama::Template;
|
||||||
/// /// ```jinja
|
/// /// ```jinja
|
||||||
/// /// <div>{{ example|linebreaks }}</div>
|
/// /// <div>{{ example|linebreaks }}</div>
|
||||||
/// /// ```
|
/// /// ```
|
||||||
@ -132,7 +132,7 @@ pub fn linebreaks(s: impl fmt::Display) -> Result<HtmlSafeOutput<String>, fmt::E
|
|||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # #[cfg(feature = "code-in-doc")] {
|
/// # #[cfg(feature = "code-in-doc")] {
|
||||||
/// # use rinja::Template;
|
/// # use askama::Template;
|
||||||
/// /// ```jinja
|
/// /// ```jinja
|
||||||
/// /// <div>{{ lines|linebreaksbr }}</div>
|
/// /// <div>{{ lines|linebreaksbr }}</div>
|
||||||
/// /// ```
|
/// /// ```
|
||||||
@ -166,7 +166,7 @@ pub fn linebreaksbr(s: impl fmt::Display) -> Result<HtmlSafeOutput<String>, fmt:
|
|||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # #[cfg(feature = "code-in-doc")] {
|
/// # #[cfg(feature = "code-in-doc")] {
|
||||||
/// # use rinja::Template;
|
/// # use askama::Template;
|
||||||
/// /// ```jinja
|
/// /// ```jinja
|
||||||
/// /// {{ lines|paragraphbreaks }}
|
/// /// {{ lines|paragraphbreaks }}
|
||||||
/// /// ```
|
/// /// ```
|
||||||
@ -197,7 +197,7 @@ pub fn paragraphbreaks(s: impl fmt::Display) -> Result<HtmlSafeOutput<String>, f
|
|||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # #[cfg(feature = "code-in-doc")] {
|
/// # #[cfg(feature = "code-in-doc")] {
|
||||||
/// # use rinja::Template;
|
/// # use askama::Template;
|
||||||
/// /// ```jinja
|
/// /// ```jinja
|
||||||
/// /// <div>{{ word|lower }}</div>
|
/// /// <div>{{ word|lower }}</div>
|
||||||
/// /// ```
|
/// /// ```
|
||||||
@ -228,7 +228,7 @@ pub fn lower(s: impl fmt::Display) -> Result<String, fmt::Error> {
|
|||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # #[cfg(feature = "code-in-doc")] {
|
/// # #[cfg(feature = "code-in-doc")] {
|
||||||
/// # use rinja::Template;
|
/// # use askama::Template;
|
||||||
/// /// ```jinja
|
/// /// ```jinja
|
||||||
/// /// <div>{{ word|lowercase }}</div>
|
/// /// <div>{{ word|lowercase }}</div>
|
||||||
/// /// ```
|
/// /// ```
|
||||||
@ -258,7 +258,7 @@ pub fn lowercase(s: impl fmt::Display) -> Result<String, fmt::Error> {
|
|||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # #[cfg(feature = "code-in-doc")] {
|
/// # #[cfg(feature = "code-in-doc")] {
|
||||||
/// # use rinja::Template;
|
/// # use askama::Template;
|
||||||
/// /// ```jinja
|
/// /// ```jinja
|
||||||
/// /// <div>{{ word|upper }}</div>
|
/// /// <div>{{ word|upper }}</div>
|
||||||
/// /// ```
|
/// /// ```
|
||||||
@ -289,7 +289,7 @@ pub fn upper(s: impl fmt::Display) -> Result<String, fmt::Error> {
|
|||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # #[cfg(feature = "code-in-doc")] {
|
/// # #[cfg(feature = "code-in-doc")] {
|
||||||
/// # use rinja::Template;
|
/// # use askama::Template;
|
||||||
/// /// ```jinja
|
/// /// ```jinja
|
||||||
/// /// <div>{{ word|uppercase }}</div>
|
/// /// <div>{{ word|uppercase }}</div>
|
||||||
/// /// ```
|
/// /// ```
|
||||||
@ -319,7 +319,7 @@ pub fn uppercase(s: impl fmt::Display) -> Result<String, fmt::Error> {
|
|||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # #[cfg(feature = "code-in-doc")] {
|
/// # #[cfg(feature = "code-in-doc")] {
|
||||||
/// # use rinja::Template;
|
/// # use askama::Template;
|
||||||
/// /// ```jinja
|
/// /// ```jinja
|
||||||
/// /// <div>{{ example|trim }}</div>
|
/// /// <div>{{ example|trim }}</div>
|
||||||
/// /// ```
|
/// /// ```
|
||||||
@ -359,7 +359,7 @@ pub fn trim<T: fmt::Display>(s: T) -> Result<String> {
|
|||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # #[cfg(feature = "code-in-doc")] {
|
/// # #[cfg(feature = "code-in-doc")] {
|
||||||
/// # use rinja::Template;
|
/// # use askama::Template;
|
||||||
/// /// ```jinja
|
/// /// ```jinja
|
||||||
/// /// <div>{{ example|indent(4) }}</div>
|
/// /// <div>{{ example|indent(4) }}</div>
|
||||||
/// /// ```
|
/// /// ```
|
||||||
@ -415,7 +415,7 @@ pub fn indent(s: impl fmt::Display, width: usize) -> Result<String, fmt::Error>
|
|||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # #[cfg(feature = "code-in-doc")] {
|
/// # #[cfg(feature = "code-in-doc")] {
|
||||||
/// # use rinja::Template;
|
/// # use askama::Template;
|
||||||
/// /// ```jinja
|
/// /// ```jinja
|
||||||
/// /// <div>{{ example|capitalize }}</div>
|
/// /// <div>{{ example|capitalize }}</div>
|
||||||
/// /// ```
|
/// /// ```
|
||||||
@ -458,7 +458,7 @@ pub fn capitalize(s: impl fmt::Display) -> Result<String, fmt::Error> {
|
|||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # #[cfg(feature = "code-in-doc")] {
|
/// # #[cfg(feature = "code-in-doc")] {
|
||||||
/// # use rinja::Template;
|
/// # use askama::Template;
|
||||||
/// /// ```jinja
|
/// /// ```jinja
|
||||||
/// /// <div>{{ example|wordcount }}</div>
|
/// /// <div>{{ example|wordcount }}</div>
|
||||||
/// /// ```
|
/// /// ```
|
||||||
@ -469,7 +469,7 @@ pub fn capitalize(s: impl fmt::Display) -> Result<String, fmt::Error> {
|
|||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// assert_eq!(
|
/// assert_eq!(
|
||||||
/// Example { example: "rinja is sort of cool" }.to_string(),
|
/// Example { example: "askama is sort of cool" }.to_string(),
|
||||||
/// "<div>5</div>"
|
/// "<div>5</div>"
|
||||||
/// );
|
/// );
|
||||||
/// # }
|
/// # }
|
||||||
@ -484,7 +484,7 @@ pub fn wordcount(s: impl fmt::Display) -> Result<usize, fmt::Error> {
|
|||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # #[cfg(feature = "code-in-doc")] {
|
/// # #[cfg(feature = "code-in-doc")] {
|
||||||
/// # use rinja::Template;
|
/// # use askama::Template;
|
||||||
/// /// ```jinja
|
/// /// ```jinja
|
||||||
/// /// <div>{{ example|title }}</div>
|
/// /// <div>{{ example|title }}</div>
|
||||||
/// /// ```
|
/// /// ```
|
@ -12,7 +12,7 @@ use crate::{Error, Result};
|
|||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # #[cfg(feature = "code-in-doc")] {
|
/// # #[cfg(feature = "code-in-doc")] {
|
||||||
/// # use rinja::Template;
|
/// # use askama::Template;
|
||||||
/// /// ```jinja
|
/// /// ```jinja
|
||||||
/// /// <div>{{ example|truncate(2) }}</div>
|
/// /// <div>{{ example|truncate(2) }}</div>
|
||||||
/// /// ```
|
/// /// ```
|
||||||
@ -118,7 +118,7 @@ impl<W: fmt::Write> fmt::Write for TruncateWriter<W> {
|
|||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # #[cfg(feature = "code-in-doc")] {
|
/// # #[cfg(feature = "code-in-doc")] {
|
||||||
/// # use rinja::Template;
|
/// # use askama::Template;
|
||||||
/// /// ```jinja
|
/// /// ```jinja
|
||||||
/// /// <div>{{ example|join(", ") }}</div>
|
/// /// <div>{{ example|join(", ") }}</div>
|
||||||
/// /// ```
|
/// /// ```
|
||||||
@ -182,7 +182,7 @@ where
|
|||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # #[cfg(feature = "code-in-doc")] {
|
/// # #[cfg(feature = "code-in-doc")] {
|
||||||
/// # use rinja::Template;
|
/// # use askama::Template;
|
||||||
/// /// ```jinja
|
/// /// ```jinja
|
||||||
/// /// <div>-{{ example|center(5) }}-</div>
|
/// /// <div>-{{ example|center(5) }}-</div>
|
||||||
/// /// ```
|
/// /// ```
|
||||||
@ -226,7 +226,7 @@ impl<T: fmt::Display> fmt::Display for Center<T> {
|
|||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # #[cfg(feature = "code-in-doc")] {
|
/// # #[cfg(feature = "code-in-doc")] {
|
||||||
/// # use rinja::Template;
|
/// # use askama::Template;
|
||||||
/// /// ```jinja
|
/// /// ```jinja
|
||||||
/// /// I have {{dogs}} dog{{dogs|pluralize}} and {{cats}} cat{{cats|pluralize}}.
|
/// /// I have {{dogs}} dog{{dogs|pluralize}} and {{cats}} cat{{cats|pluralize}}.
|
||||||
/// /// ```
|
/// /// ```
|
||||||
@ -256,7 +256,7 @@ impl<T: fmt::Display> fmt::Display for Center<T> {
|
|||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # #[cfg(feature = "code-in-doc")] {
|
/// # #[cfg(feature = "code-in-doc")] {
|
||||||
/// # use rinja::Template;
|
/// # use askama::Template;
|
||||||
/// /// ```jinja
|
/// /// ```jinja
|
||||||
/// /// I have {{dogs}} dog{{ dogs|pluralize("go") }}.
|
/// /// I have {{dogs}} dog{{ dogs|pluralize("go") }}.
|
||||||
/// /// ```
|
/// /// ```
|
||||||
@ -281,7 +281,7 @@ impl<T: fmt::Display> fmt::Display for Center<T> {
|
|||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # #[cfg(feature = "code-in-doc")] {
|
/// # #[cfg(feature = "code-in-doc")] {
|
||||||
/// # use rinja::Template;
|
/// # use askama::Template;
|
||||||
/// /// ```jinja
|
/// /// ```jinja
|
||||||
/// /// I have {{mice}} {{ mice|pluralize("mouse", "mice") }}.
|
/// /// I have {{mice}} {{ mice|pluralize("mouse", "mice") }}.
|
||||||
/// /// ```
|
/// /// ```
|
||||||
@ -306,7 +306,7 @@ impl<T: fmt::Display> fmt::Display for Center<T> {
|
|||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # #[cfg(feature = "code-in-doc")] {
|
/// # #[cfg(feature = "code-in-doc")] {
|
||||||
/// # use rinja::Template;
|
/// # use askama::Template;
|
||||||
/// /// ```jinja
|
/// /// ```jinja
|
||||||
/// /// You are number {{ number|pluralize("<b>ONE</b>", number) }}!
|
/// /// You are number {{ number|pluralize("<b>ONE</b>", number) }}!
|
||||||
/// /// ```
|
/// /// ```
|
@ -11,13 +11,13 @@ use crate::Values;
|
|||||||
/// Use this if you want to allow markup in an expression, or if you know
|
/// Use this if you want to allow markup in an expression, or if you know
|
||||||
/// that the expression's contents don't need to be escaped.
|
/// that the expression's contents don't need to be escaped.
|
||||||
///
|
///
|
||||||
/// Rinja will automatically insert the first (`Escaper`) argument,
|
/// Askama will automatically insert the first (`Escaper`) argument,
|
||||||
/// so this filter only takes a single argument of any type that implements
|
/// so this filter only takes a single argument of any type that implements
|
||||||
/// `Display`.
|
/// `Display`.
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # #[cfg(feature = "code-in-doc")] {
|
/// # #[cfg(feature = "code-in-doc")] {
|
||||||
/// # use rinja::Template;
|
/// # use askama::Template;
|
||||||
/// /// ```jinja
|
/// /// ```jinja
|
||||||
/// /// <div>{{ example|safe }}</div>
|
/// /// <div>{{ example|safe }}</div>
|
||||||
/// /// ```
|
/// /// ```
|
||||||
@ -41,7 +41,7 @@ pub fn safe<T, E>(text: T, escaper: E) -> Result<Safe<T>, Infallible> {
|
|||||||
|
|
||||||
/// Escapes strings according to the escape mode.
|
/// Escapes strings according to the escape mode.
|
||||||
///
|
///
|
||||||
/// Rinja will automatically insert the first (`Escaper`) argument,
|
/// Askama will automatically insert the first (`Escaper`) argument,
|
||||||
/// so this filter only takes a single argument of any type that implements
|
/// so this filter only takes a single argument of any type that implements
|
||||||
/// `Display`.
|
/// `Display`.
|
||||||
///
|
///
|
||||||
@ -50,7 +50,7 @@ pub fn safe<T, E>(text: T, escaper: E) -> Result<Safe<T>, Infallible> {
|
|||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # #[cfg(feature = "code-in-doc")] {
|
/// # #[cfg(feature = "code-in-doc")] {
|
||||||
/// # use rinja::Template;
|
/// # use askama::Template;
|
||||||
/// /// ```jinja
|
/// /// ```jinja
|
||||||
/// /// <div>{{ example|escape }}</div>
|
/// /// <div>{{ example|escape }}</div>
|
||||||
/// /// ```
|
/// /// ```
|
||||||
@ -105,7 +105,7 @@ impl<W: Write, E: Escaper> Write for EscapeWriter<W, E> {
|
|||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # #[cfg(feature = "code-in-doc")] {
|
/// # #[cfg(feature = "code-in-doc")] {
|
||||||
/// # use rinja::Template;
|
/// # use askama::Template;
|
||||||
/// /// ```jinja
|
/// /// ```jinja
|
||||||
/// /// <div>{{ example|e }}</div>
|
/// /// <div>{{ example|e }}</div>
|
||||||
/// /// ```
|
/// /// ```
|
||||||
@ -179,18 +179,18 @@ pub trait Escaper: Copy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Used internally by rinja to select the appropriate escaper
|
/// Used internally by askama to select the appropriate escaper
|
||||||
pub trait AutoEscape {
|
pub trait AutoEscape {
|
||||||
/// The wrapped or converted result type
|
/// The wrapped or converted result type
|
||||||
type Escaped: fmt::Display;
|
type Escaped: fmt::Display;
|
||||||
/// Early error testing for the input value, usually [`Infallible`]
|
/// Early error testing for the input value, usually [`Infallible`]
|
||||||
type Error: Into<crate::Error>;
|
type Error: Into<crate::Error>;
|
||||||
|
|
||||||
/// Used internally by rinja to select the appropriate escaper
|
/// Used internally by askama to select the appropriate escaper
|
||||||
fn rinja_auto_escape(&self) -> Result<Self::Escaped, Self::Error>;
|
fn askama_auto_escape(&self) -> Result<Self::Escaped, Self::Error>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Used internally by rinja to select the appropriate escaper
|
/// Used internally by askama to select the appropriate escaper
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct AutoEscaper<'a, T: ?Sized, E> {
|
pub struct AutoEscaper<'a, T: ?Sized, E> {
|
||||||
text: &'a T,
|
text: &'a T,
|
||||||
@ -198,7 +198,7 @@ pub struct AutoEscaper<'a, T: ?Sized, E> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, T: ?Sized, E> AutoEscaper<'a, T, E> {
|
impl<'a, T: ?Sized, E> AutoEscaper<'a, T, E> {
|
||||||
/// Used internally by rinja to select the appropriate escaper
|
/// Used internally by askama to select the appropriate escaper
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new(text: &'a T, escaper: E) -> Self {
|
pub fn new(text: &'a T, escaper: E) -> Self {
|
||||||
Self { text, escaper }
|
Self { text, escaper }
|
||||||
@ -211,14 +211,14 @@ impl<'a, T: fmt::Display + ?Sized, E: Escaper> AutoEscape for &&AutoEscaper<'a,
|
|||||||
type Error = Infallible;
|
type Error = Infallible;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn rinja_auto_escape(&self) -> Result<Self::Escaped, Self::Error> {
|
fn askama_auto_escape(&self) -> Result<Self::Escaped, Self::Error> {
|
||||||
Ok(EscapeDisplay(self.text, self.escaper))
|
Ok(EscapeDisplay(self.text, self.escaper))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Types that implement this marker trait don't need to be HTML escaped
|
/// Types that implement this marker trait don't need to be HTML escaped
|
||||||
///
|
///
|
||||||
/// Please note that this trait is only meant as speed-up helper. In some odd circumcises rinja
|
/// Please note that this trait is only meant as speed-up helper. In some odd circumcises askama
|
||||||
/// might still decide to HTML escape the input, so if this must not happen, then you need to use
|
/// might still decide to HTML escape the input, so if this must not happen, then you need to use
|
||||||
/// the [`|safe`](super::safe) filter to prevent the auto escaping.
|
/// the [`|safe`](super::safe) filter to prevent the auto escaping.
|
||||||
///
|
///
|
||||||
@ -232,7 +232,7 @@ impl<'a, T: HtmlSafe + ?Sized> AutoEscape for &AutoEscaper<'a, T, Html> {
|
|||||||
type Error = Infallible;
|
type Error = Infallible;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn rinja_auto_escape(&self) -> Result<Self::Escaped, Self::Error> {
|
fn askama_auto_escape(&self) -> Result<Self::Escaped, Self::Error> {
|
||||||
Ok(self.text)
|
Ok(self.text)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -250,7 +250,7 @@ impl<'a, T: HtmlSafe + ?Sized> AutoEscape for &AutoEscaper<'a, T, Html> {
|
|||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// mod filters {
|
/// mod filters {
|
||||||
/// use rinja::{filters::MaybeSafe, Result};
|
/// use askama::{filters::MaybeSafe, Result};
|
||||||
///
|
///
|
||||||
/// // Do not actually use this filter! It's an intentionally bad example.
|
/// // Do not actually use this filter! It's an intentionally bad example.
|
||||||
/// pub fn backdoor<T: std::fmt::Display>(s: T, enable: &bool) -> Result<MaybeSafe<T>> {
|
/// pub fn backdoor<T: std::fmt::Display>(s: T, enable: &bool) -> Result<MaybeSafe<T>> {
|
||||||
@ -261,7 +261,7 @@ impl<'a, T: HtmlSafe + ?Sized> AutoEscape for &AutoEscaper<'a, T, Html> {
|
|||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// #[derive(rinja::Template)]
|
/// #[derive(askama::Template)]
|
||||||
/// #[template(
|
/// #[template(
|
||||||
/// source = "<div class='{{ klass|backdoor(enable_backdoor) }}'></div>",
|
/// source = "<div class='{{ klass|backdoor(enable_backdoor) }}'></div>",
|
||||||
/// ext = "html"
|
/// ext = "html"
|
||||||
@ -320,7 +320,7 @@ const _: () = {
|
|||||||
type Error = Infallible;
|
type Error = Infallible;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn rinja_auto_escape(&self) -> Result<Self::Escaped, Self::Error> {
|
fn askama_auto_escape(&self) -> Result<Self::Escaped, Self::Error> {
|
||||||
match self.text {
|
match self.text {
|
||||||
MaybeSafe::Safe(t) => Ok(Wrapped::Safe(t)),
|
MaybeSafe::Safe(t) => Ok(Wrapped::Safe(t)),
|
||||||
MaybeSafe::NeedsEscaping(t) => Ok(Wrapped::NeedsEscaping(t, self.escaper)),
|
MaybeSafe::NeedsEscaping(t) => Ok(Wrapped::NeedsEscaping(t, self.escaper)),
|
||||||
@ -368,7 +368,7 @@ const _: () = {
|
|||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// mod filters {
|
/// mod filters {
|
||||||
/// use rinja::{filters::Safe, Result};
|
/// use askama::{filters::Safe, Result};
|
||||||
///
|
///
|
||||||
/// // Do not actually use this filter! It's an intentionally bad example.
|
/// // Do not actually use this filter! It's an intentionally bad example.
|
||||||
/// pub fn strip_except_apos(s: impl ToString) -> Result<Safe<String>> {
|
/// pub fn strip_except_apos(s: impl ToString) -> Result<Safe<String>> {
|
||||||
@ -381,7 +381,7 @@ const _: () = {
|
|||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// #[derive(rinja::Template)]
|
/// #[derive(askama::Template)]
|
||||||
/// #[template(
|
/// #[template(
|
||||||
/// source = "<div class='{{ klass|strip_except_apos }}'></div>",
|
/// source = "<div class='{{ klass|strip_except_apos }}'></div>",
|
||||||
/// ext = "html"
|
/// ext = "html"
|
||||||
@ -421,7 +421,7 @@ const _: () = {
|
|||||||
type Error = Infallible;
|
type Error = Infallible;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn rinja_auto_escape(&self) -> Result<Self::Escaped, Self::Error> {
|
fn askama_auto_escape(&self) -> Result<Self::Escaped, Self::Error> {
|
||||||
Ok(&self.text.0)
|
Ok(&self.text.0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -485,24 +485,24 @@ crate::impl_for_ref! {
|
|||||||
|
|
||||||
impl<T: HtmlSafe> HtmlSafe for Pin<T> {}
|
impl<T: HtmlSafe> HtmlSafe for Pin<T> {}
|
||||||
|
|
||||||
/// Used internally by rinja to select the appropriate [`write!()`] mechanism
|
/// Used internally by askama to select the appropriate [`write!()`] mechanism
|
||||||
pub struct Writable<'a, S: ?Sized>(pub &'a S);
|
pub struct Writable<'a, S: ?Sized>(pub &'a S);
|
||||||
|
|
||||||
/// Used internally by rinja to select the appropriate [`write!()`] mechanism
|
/// Used internally by askama to select the appropriate [`write!()`] mechanism
|
||||||
pub trait WriteWritable {
|
pub trait WriteWritable {
|
||||||
/// Used internally by rinja to select the appropriate [`write!()`] mechanism
|
/// Used internally by askama to select the appropriate [`write!()`] mechanism
|
||||||
fn rinja_write<W: fmt::Write + ?Sized>(
|
fn askama_write<W: fmt::Write + ?Sized>(
|
||||||
&self,
|
&self,
|
||||||
dest: &mut W,
|
dest: &mut W,
|
||||||
values: &dyn Values,
|
values: &dyn Values,
|
||||||
) -> crate::Result<()>;
|
) -> crate::Result<()>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Used internally by rinja to speed up writing some types.
|
/// Used internally by askama to speed up writing some types.
|
||||||
///
|
///
|
||||||
/// Types implementing this trait can be written without needing to employ an [`fmt::Formatter`].
|
/// Types implementing this trait can be written without needing to employ an [`fmt::Formatter`].
|
||||||
pub trait FastWritable {
|
pub trait FastWritable {
|
||||||
/// Used internally by rinja to speed up writing some types.
|
/// Used internally by askama to speed up writing some types.
|
||||||
fn write_into<W: fmt::Write + ?Sized>(&self, dest: &mut W) -> crate::Result<()>;
|
fn write_into<W: fmt::Write + ?Sized>(&self, dest: &mut W) -> crate::Result<()>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -612,7 +612,7 @@ const _: () = {
|
|||||||
|
|
||||||
impl<S: crate::Template + ?Sized> WriteWritable for &Writable<'_, S> {
|
impl<S: crate::Template + ?Sized> WriteWritable for &Writable<'_, S> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn rinja_write<W: fmt::Write + ?Sized>(
|
fn askama_write<W: fmt::Write + ?Sized>(
|
||||||
&self,
|
&self,
|
||||||
dest: &mut W,
|
dest: &mut W,
|
||||||
values: &dyn Values,
|
values: &dyn Values,
|
||||||
@ -623,7 +623,7 @@ const _: () = {
|
|||||||
|
|
||||||
impl<S: FastWritable + ?Sized> WriteWritable for &&Writable<'_, S> {
|
impl<S: FastWritable + ?Sized> WriteWritable for &&Writable<'_, S> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn rinja_write<W: fmt::Write + ?Sized>(
|
fn askama_write<W: fmt::Write + ?Sized>(
|
||||||
&self,
|
&self,
|
||||||
dest: &mut W,
|
dest: &mut W,
|
||||||
_: &dyn Values,
|
_: &dyn Values,
|
||||||
@ -634,7 +634,7 @@ const _: () = {
|
|||||||
|
|
||||||
impl<S: fmt::Display + ?Sized> WriteWritable for &&&Writable<'_, S> {
|
impl<S: fmt::Display + ?Sized> WriteWritable for &&&Writable<'_, S> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn rinja_write<W: fmt::Write + ?Sized>(
|
fn askama_write<W: fmt::Write + ?Sized>(
|
||||||
&self,
|
&self,
|
||||||
dest: &mut W,
|
dest: &mut W,
|
||||||
_: &dyn Values,
|
_: &dyn Values,
|
||||||
@ -686,14 +686,14 @@ fn test_html_safe_marker() {
|
|||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
(&&AutoEscaper::new(&Script1, Html))
|
(&&AutoEscaper::new(&Script1, Html))
|
||||||
.rinja_auto_escape()
|
.askama_auto_escape()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_string(),
|
.to_string(),
|
||||||
"<script>",
|
"<script>",
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
(&&AutoEscaper::new(&Script2, Html))
|
(&&AutoEscaper::new(&Script2, Html))
|
||||||
.rinja_auto_escape()
|
.askama_auto_escape()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_string(),
|
.to_string(),
|
||||||
"<script>",
|
"<script>",
|
||||||
@ -701,14 +701,14 @@ fn test_html_safe_marker() {
|
|||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
(&&AutoEscaper::new(&Script1, Text))
|
(&&AutoEscaper::new(&Script1, Text))
|
||||||
.rinja_auto_escape()
|
.askama_auto_escape()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_string(),
|
.to_string(),
|
||||||
"<script>",
|
"<script>",
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
(&&AutoEscaper::new(&Script2, Text))
|
(&&AutoEscaper::new(&Script2, Text))
|
||||||
.rinja_auto_escape()
|
.askama_auto_escape()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_string(),
|
.to_string(),
|
||||||
"<script>",
|
"<script>",
|
||||||
@ -716,14 +716,14 @@ fn test_html_safe_marker() {
|
|||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
(&&AutoEscaper::new(&Safe(Script1), Html))
|
(&&AutoEscaper::new(&Safe(Script1), Html))
|
||||||
.rinja_auto_escape()
|
.askama_auto_escape()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_string(),
|
.to_string(),
|
||||||
"<script>",
|
"<script>",
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
(&&AutoEscaper::new(&Safe(Script2), Html))
|
(&&AutoEscaper::new(&Safe(Script2), Html))
|
||||||
.rinja_auto_escape()
|
.askama_auto_escape()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_string(),
|
.to_string(),
|
||||||
"<script>",
|
"<script>",
|
||||||
@ -731,14 +731,14 @@ fn test_html_safe_marker() {
|
|||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
(&&AutoEscaper::new(&Unsafe(Script1), Html))
|
(&&AutoEscaper::new(&Unsafe(Script1), Html))
|
||||||
.rinja_auto_escape()
|
.askama_auto_escape()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_string(),
|
.to_string(),
|
||||||
"<script>",
|
"<script>",
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
(&&AutoEscaper::new(&Unsafe(Script2), Html))
|
(&&AutoEscaper::new(&Unsafe(Script2), Html))
|
||||||
.rinja_auto_escape()
|
.askama_auto_escape()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_string(),
|
.to_string(),
|
||||||
"<script>",
|
"<script>",
|
||||||
@ -746,28 +746,28 @@ fn test_html_safe_marker() {
|
|||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
(&&AutoEscaper::new(&MaybeSafe::Safe(Script1), Html))
|
(&&AutoEscaper::new(&MaybeSafe::Safe(Script1), Html))
|
||||||
.rinja_auto_escape()
|
.askama_auto_escape()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_string(),
|
.to_string(),
|
||||||
"<script>",
|
"<script>",
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
(&&AutoEscaper::new(&MaybeSafe::Safe(Script2), Html))
|
(&&AutoEscaper::new(&MaybeSafe::Safe(Script2), Html))
|
||||||
.rinja_auto_escape()
|
.askama_auto_escape()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_string(),
|
.to_string(),
|
||||||
"<script>",
|
"<script>",
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
(&&AutoEscaper::new(&MaybeSafe::NeedsEscaping(Script1), Html))
|
(&&AutoEscaper::new(&MaybeSafe::NeedsEscaping(Script1), Html))
|
||||||
.rinja_auto_escape()
|
.askama_auto_escape()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_string(),
|
.to_string(),
|
||||||
"<script>",
|
"<script>",
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
(&&AutoEscaper::new(&MaybeSafe::NeedsEscaping(Script2), Html))
|
(&&AutoEscaper::new(&MaybeSafe::NeedsEscaping(Script2), Html))
|
||||||
.rinja_auto_escape()
|
.askama_auto_escape()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_string(),
|
.to_string(),
|
||||||
"<script>",
|
"<script>",
|
||||||
@ -775,14 +775,14 @@ fn test_html_safe_marker() {
|
|||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
(&&AutoEscaper::new(&Safe(std::pin::Pin::new(&Script1)), Html))
|
(&&AutoEscaper::new(&Safe(std::pin::Pin::new(&Script1)), Html))
|
||||||
.rinja_auto_escape()
|
.askama_auto_escape()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_string(),
|
.to_string(),
|
||||||
"<script>",
|
"<script>",
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
(&&AutoEscaper::new(&Safe(std::pin::Pin::new(&Script2)), Html))
|
(&&AutoEscaper::new(&Safe(std::pin::Pin::new(&Script2)), Html))
|
||||||
.rinja_auto_escape()
|
.askama_auto_escape()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_string(),
|
.to_string(),
|
||||||
"<script>",
|
"<script>",
|
@ -9,7 +9,7 @@ use crate::ascii_str::{AsciiChar, AsciiStr};
|
|||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
/// ```
|
/// ```
|
||||||
/// # use rinja::Template;
|
/// # use askama::Template;
|
||||||
/// #[derive(Template)]
|
/// #[derive(Template)]
|
||||||
/// #[template(
|
/// #[template(
|
||||||
/// source = "Filesize: {{ size_in_bytes|filesizeformat }}.",
|
/// source = "Filesize: {{ size_in_bytes|filesizeformat }}.",
|
@ -26,7 +26,7 @@ use crate::ascii_str::{AsciiChar, AsciiStr};
|
|||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # #[cfg(feature = "code-in-doc")] {
|
/// # #[cfg(feature = "code-in-doc")] {
|
||||||
/// # use rinja::Template;
|
/// # use askama::Template;
|
||||||
/// /// ```jinja
|
/// /// ```jinja
|
||||||
/// /// <div><li data-extra='{{data|json|safe}}'>Example</li></div>
|
/// /// <div><li data-extra='{{data|json|safe}}'>Example</li></div>
|
||||||
/// /// ```
|
/// /// ```
|
||||||
@ -57,12 +57,12 @@ pub fn json(value: impl Serialize) -> Result<impl fmt::Display, Infallible> {
|
|||||||
///
|
///
|
||||||
/// ### Note
|
/// ### Note
|
||||||
///
|
///
|
||||||
/// In rinja's template language, this filter is called `|json`, too. The right function is
|
/// In askama's template language, this filter is called `|json`, too. The right function is
|
||||||
/// automatically selected depending on whether an `indent` argument was provided or not.
|
/// automatically selected depending on whether an `indent` argument was provided or not.
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # #[cfg(feature = "code-in-doc")] {
|
/// # #[cfg(feature = "code-in-doc")] {
|
||||||
/// # use rinja::Template;
|
/// # use askama::Template;
|
||||||
/// /// ```jinja
|
/// /// ```jinja
|
||||||
/// /// <div>{{data|json(4)|safe}}</div>
|
/// /// <div>{{data|json(4)|safe}}</div>
|
||||||
/// /// ```
|
/// /// ```
|
||||||
@ -104,7 +104,7 @@ struct ToJsonPretty<S, I> {
|
|||||||
/// A prefix usable for indenting [prettified JSON data](json_pretty)
|
/// A prefix usable for indenting [prettified JSON data](json_pretty)
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # use rinja::filters::AsIndent;
|
/// # use askama::filters::AsIndent;
|
||||||
/// assert_eq!(4.as_indent(), " ");
|
/// assert_eq!(4.as_indent(), " ");
|
||||||
/// assert_eq!(" -> ".as_indent(), " -> ");
|
/// assert_eq!(" -> ".as_indent(), " -> ");
|
||||||
/// ```
|
/// ```
|
@ -7,7 +7,7 @@
|
|||||||
//!
|
//!
|
||||||
//! All **result types of any filter function** in this module is **subject to change** at any
|
//! All **result types of any filter function** in this module is **subject to change** at any
|
||||||
//! point, and is **not indicated by as semver breaking** version bump.
|
//! point, and is **not indicated by as semver breaking** version bump.
|
||||||
//! The traits [`AutoEscape`] and [`WriteWritable`] are used by [`rinja_derive`]'s generated code
|
//! The traits [`AutoEscape`] and [`WriteWritable`] are used by [`askama_derive`]'s generated code
|
||||||
//! to work with all compatible types.
|
//! to work with all compatible types.
|
||||||
|
|
||||||
#[cfg(feature = "alloc")]
|
#[cfg(feature = "alloc")]
|
@ -40,7 +40,7 @@ const URLENCODE_SET: &AsciiSet = &URLENCODE_STRICT_SET.remove(b'/');
|
|||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # #[cfg(feature = "code-in-doc")] {
|
/// # #[cfg(feature = "code-in-doc")] {
|
||||||
/// # use rinja::Template;
|
/// # use askama::Template;
|
||||||
/// /// ```jinja
|
/// /// ```jinja
|
||||||
/// /// <div>{{ example|urlencode }}</div>
|
/// /// <div>{{ example|urlencode }}</div>
|
||||||
/// /// ```
|
/// /// ```
|
||||||
@ -78,7 +78,7 @@ pub fn urlencode<T>(s: T) -> Result<HtmlSafeOutput<UrlencodeFilter<T>>, Infallib
|
|||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # #[cfg(feature = "code-in-doc")] {
|
/// # #[cfg(feature = "code-in-doc")] {
|
||||||
/// # use rinja::Template;
|
/// # use askama::Template;
|
||||||
/// /// ```jinja
|
/// /// ```jinja
|
||||||
/// /// <a href='{{ example|urlencode_strict }}'>Example</a>
|
/// /// <a href='{{ example|urlencode_strict }}'>Example</a>
|
||||||
/// /// ```
|
/// /// ```
|
@ -165,7 +165,7 @@ where
|
|||||||
/// # use std::num::{NonZeroI16, Saturating};
|
/// # use std::num::{NonZeroI16, Saturating};
|
||||||
/// # use std::rc::Rc;
|
/// # use std::rc::Rc;
|
||||||
/// # use std::pin::Pin;
|
/// # use std::pin::Pin;
|
||||||
/// # use rinja::Template;
|
/// # use askama::Template;
|
||||||
/// #[derive(Template)]
|
/// #[derive(Template)]
|
||||||
/// #[template(ext = "txt", source = "{{ value as u16 }}")]
|
/// #[template(ext = "txt", source = "{{ value as u16 }}")]
|
||||||
/// struct Test<'a> {
|
/// struct Test<'a> {
|
@ -1,6 +1,6 @@
|
|||||||
// The file is shared across many crates, not all have this feature.
|
// The file is shared across many crates, not all have this feature.
|
||||||
// If they don't then the tests won't be compiled in, but that's OK, because they are executed at
|
// If they don't then the tests won't be compiled in, but that's OK, because they are executed at
|
||||||
// least in the crate `rinja`. There's no need to run the test multiple times.
|
// least in the crate `askama`. There's no need to run the test multiple times.
|
||||||
#![allow(unexpected_cfgs)]
|
#![allow(unexpected_cfgs)]
|
||||||
|
|
||||||
use core::{fmt, str};
|
use core::{fmt, str};
|
@ -1,28 +1,28 @@
|
|||||||
//! [](https://crates.io/crates/rinja)
|
//! [](https://crates.io/crates/askama)
|
||||||
//! [](https://github.com/rinja-rs/rinja/actions/workflows/rust.yml)
|
//! [](https://github.com/askama-rs/askama/actions/workflows/rust.yml)
|
||||||
//! [](https://rinja.readthedocs.io/)
|
//! [](https://askama.readthedocs.io/)
|
||||||
//! [](https://docs.rs/rinja/)
|
//! [](https://docs.rs/askama/)
|
||||||
//!
|
//!
|
||||||
//! Rinja implements a type-safe compiler for Jinja-like templates.
|
//! Askama implements a type-safe compiler for Jinja-like templates.
|
||||||
//! It lets you write templates in a Jinja-like syntax,
|
//! It lets you write templates in a Jinja-like syntax,
|
||||||
//! which are linked to a `struct` defining the template context.
|
//! which are linked to a `struct` or an `enum` defining the template context.
|
||||||
//! This is done using a custom derive implementation (implemented
|
//! This is done using a custom derive implementation (implemented
|
||||||
//! in [`rinja_derive`](https://crates.io/crates/rinja_derive)).
|
//! in [`askama_derive`](https://crates.io/crates/askama_derive)).
|
||||||
//!
|
//!
|
||||||
//! For feature highlights and a quick start, please review the
|
//! For feature highlights and a quick start, please review the
|
||||||
//! [README](https://github.com/rinja-rs/rinja/blob/master/README.md).
|
//! [README](https://github.com/askama-rs/askama/blob/master/README.md).
|
||||||
//!
|
//!
|
||||||
//! You can find the documentation about our syntax, features, configuration in our book:
|
//! You can find the documentation about our syntax, features, configuration in our book:
|
||||||
//! [rinja.readthedocs.io](https://rinja.readthedocs.io/).
|
//! [askama.readthedocs.io](https://askama.readthedocs.io/).
|
||||||
//!
|
//!
|
||||||
//! # Creating Rinja templates
|
//! # Creating Askama templates
|
||||||
//!
|
//!
|
||||||
//! The main feature of Rinja is the [`Template`] derive macro
|
//! The main feature of Askama is the [`Template`] derive macro
|
||||||
//! which reads your template code, so your `struct` can implement
|
//! which reads your template code, so your `struct` or `enum` can implement
|
||||||
//! the [`Template`] trait and [`Display`][std::fmt::Display], type-safe and fast:
|
//! the [`Template`] trait and [`Display`][std::fmt::Display], type-safe and fast:
|
||||||
//!
|
//!
|
||||||
//! ```rust
|
//! ```rust
|
||||||
//! # use rinja::Template;
|
//! # use askama::Template;
|
||||||
//! #[derive(Template)]
|
//! #[derive(Template)]
|
||||||
//! #[template(
|
//! #[template(
|
||||||
//! ext = "html",
|
//! ext = "html",
|
||||||
@ -34,17 +34,17 @@
|
|||||||
//! }
|
//! }
|
||||||
//!
|
//!
|
||||||
//! assert_eq!(
|
//! assert_eq!(
|
||||||
//! Footer { year: 2025, enterprise: "<em>Rinja</em> developers" }.to_string(),
|
//! Footer { year: 2025, enterprise: "<em>Askama</em> developers" }.to_string(),
|
||||||
//! "<p>© 2025 <EM>RINJA</EM> DEVELOPERS</p>",
|
//! "<p>© 2025 <EM>RINJA</EM> DEVELOPERS</p>",
|
||||||
//! );
|
//! );
|
||||||
//! // In here you see can Rinja's auto-escaping. You, the developer,
|
//! // In here you see can Askama's auto-escaping. You, the developer,
|
||||||
//! // can easily disable the auto-escaping with the `|safe` filter,
|
//! // can easily disable the auto-escaping with the `|safe` filter,
|
||||||
//! // but a malicious user cannot insert e.g. HTML scripts this way.
|
//! // but a malicious user cannot insert e.g. HTML scripts this way.
|
||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
//! A Rinja template is a `struct` definition which provides the template
|
//! An Askama template is a `struct` or `enum` definition which provides the template
|
||||||
//! context combined with a UTF-8 encoded text file (or inline source).
|
//! context combined with a UTF-8 encoded text file (or inline source).
|
||||||
//! Rinja can be used to generate any kind of text-based format.
|
//! Askama can be used to generate any kind of text-based format.
|
||||||
//! The template file's extension may be used to provide content type hints.
|
//! The template file's extension may be used to provide content type hints.
|
||||||
//!
|
//!
|
||||||
//! A template consists of **text contents**, which are passed through as-is,
|
//! A template consists of **text contents**, which are passed through as-is,
|
||||||
@ -80,7 +80,7 @@ use core::fmt;
|
|||||||
use std::io;
|
use std::io;
|
||||||
|
|
||||||
#[cfg(feature = "derive")]
|
#[cfg(feature = "derive")]
|
||||||
pub use rinja_derive::Template;
|
pub use askama_derive::Template;
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub use crate as shared;
|
pub use crate as shared;
|
||||||
@ -94,7 +94,7 @@ pub use crate::values::{NO_VALUES, Value, Values, get_value};
|
|||||||
///
|
///
|
||||||
/// ## Rendering performance
|
/// ## Rendering performance
|
||||||
///
|
///
|
||||||
/// When rendering a rinja template, you should prefer the methods
|
/// When rendering a askama template, you should prefer the methods
|
||||||
///
|
///
|
||||||
/// * [`.render()`][Template::render] (to render the content into a new string),
|
/// * [`.render()`][Template::render] (to render the content into a new string),
|
||||||
/// * [`.render_into()`][Template::render_into] (to render the content into an [`fmt::Write`]
|
/// * [`.render_into()`][Template::render_into] (to render the content into an [`fmt::Write`]
|
||||||
@ -104,7 +104,7 @@ pub use crate::values::{NO_VALUES, Value, Values, get_value};
|
|||||||
///
|
///
|
||||||
/// over [`.to_string()`][std::string::ToString::to_string] or [`format!()`][alloc::format].
|
/// over [`.to_string()`][std::string::ToString::to_string] or [`format!()`][alloc::format].
|
||||||
/// While `.to_string()` and `format!()` give you the same result, they generally perform much worse
|
/// While `.to_string()` and `format!()` give you the same result, they generally perform much worse
|
||||||
/// than rinja's own methods, because [`fmt::Write`] uses [dynamic methods calls] instead of
|
/// than askama's own methods, because [`fmt::Write`] uses [dynamic methods calls] instead of
|
||||||
/// monomorphised code. On average, expect `.to_string()` to be 100% to 200% slower than
|
/// monomorphised code. On average, expect `.to_string()` to be 100% to 200% slower than
|
||||||
/// `.render()`.
|
/// `.render()`.
|
||||||
///
|
///
|
@ -1,9 +1,9 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "rinja_derive"
|
name = "askama_derive"
|
||||||
version = "0.3.5"
|
version = "0.3.5"
|
||||||
description = "Procedural macro package for Rinja"
|
description = "Procedural macro package for Askama"
|
||||||
homepage = "https://github.com/rinja-rs/rinja"
|
homepage = "https://github.com/askama-rs/askama"
|
||||||
repository = "https://github.com/rinja-rs/rinja"
|
repository = "https://github.com/askama-rs/askama"
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
@ -17,7 +17,7 @@ rustdoc-args = ["--generate-link-to-definition", "--cfg=docsrs"]
|
|||||||
proc-macro = true
|
proc-macro = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
parser = { package = "rinja_parser", version = "=0.3.5", path = "../rinja_parser" }
|
parser = { package = "askama_parser", version = "=0.3.5", path = "../askama_parser" }
|
||||||
|
|
||||||
basic-toml = { version = "0.1.1", optional = true }
|
basic-toml = { version = "0.1.1", optional = true }
|
||||||
pulldown-cmark = { version = "0.13.0", optional = true, default-features = false }
|
pulldown-cmark = { version = "0.13.0", optional = true, default-features = false }
|
||||||
@ -29,7 +29,7 @@ quote = { version = "1", default-features = false }
|
|||||||
rustc-hash = "2.0.0"
|
rustc-hash = "2.0.0"
|
||||||
syn = { version = "2.0.3", default-features = false, features = ["clone-impls", "derive", "parsing", "printing"] }
|
syn = { version = "2.0.3", default-features = false, features = ["clone-impls", "derive", "parsing", "printing"] }
|
||||||
|
|
||||||
# in `rinja_derive_standalone` we opt out of the default features, because we need no native `proc-macro` support
|
# in `askama_derive_standalone` we opt out of the default features, because we need no native `proc-macro` support
|
||||||
proc-macro2 = "1"
|
proc-macro2 = "1"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
@ -38,7 +38,7 @@ prettyplease = "0.2.20"
|
|||||||
similar = "2.6.0"
|
similar = "2.6.0"
|
||||||
syn = { version = "2.0.3", features = ["full"] }
|
syn = { version = "2.0.3", features = ["full"] }
|
||||||
|
|
||||||
# must be the same feature list as for rinja
|
# must be the same feature list as for askama
|
||||||
[features]
|
[features]
|
||||||
default = ["config", "derive", "std", "urlencode"]
|
default = ["config", "derive", "std", "urlencode"]
|
||||||
full = ["default", "blocks", "code-in-doc", "serde_json"]
|
full = ["default", "blocks", "code-in-doc", "serde_json"]
|
||||||
@ -53,5 +53,5 @@ std = ["alloc"]
|
|||||||
urlencode = []
|
urlencode = []
|
||||||
|
|
||||||
[lints.rust]
|
[lints.rust]
|
||||||
# Used in `rinja_derive_standalone` which uses the same source folder, but is not a proc-macro.
|
# Used in `askama_derive_standalone` which uses the same source folder, but is not a proc-macro.
|
||||||
unexpected_cfgs = { level = "allow", check-cfg = ['cfg(feature, values("__standalone"))'] }
|
unexpected_cfgs = { level = "allow", check-cfg = ['cfg(feature, values("__standalone"))'] }
|
9
askama_derive/README.md
Normal file
9
askama_derive/README.md
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
# askama_derive: procedural macros for the Askama templating engine
|
||||||
|
|
||||||
|
[](https://crates.io/crates/askama_derive)
|
||||||
|
[](https://github.com/askama-rs/askama/actions/workflows/rust.yml)
|
||||||
|
[](https://askama.readthedocs.io/)
|
||||||
|
[](https://docs.rs/askama_derive/)
|
||||||
|
|
||||||
|
This crate contains the procedural macros used by the
|
||||||
|
[Askama](https://github.com/askama-rs/askama) templating engine.
|
@ -162,7 +162,7 @@ impl Config {
|
|||||||
for (extensions, name) in DEFAULT_ESCAPERS {
|
for (extensions, name) in DEFAULT_ESCAPERS {
|
||||||
escapers.push((
|
escapers.push((
|
||||||
str_set(extensions),
|
str_set(extensions),
|
||||||
format!("rinja::filters::{name}").into(),
|
format!("askama::filters::{name}").into(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -364,7 +364,7 @@ fn str_set(vals: &[&'static str]) -> Vec<Cow<'static, str>> {
|
|||||||
vals.iter().map(|s| Cow::Borrowed(*s)).collect()
|
vals.iter().map(|s| Cow::Borrowed(*s)).collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
static CONFIG_FILE_NAME: &str = "rinja.toml";
|
static CONFIG_FILE_NAME: &str = "askama.toml";
|
||||||
static DEFAULT_SYNTAX_NAME: &str = "default";
|
static DEFAULT_SYNTAX_NAME: &str = "default";
|
||||||
static DEFAULT_ESCAPERS: &[(&[&str], &str)] = &[
|
static DEFAULT_ESCAPERS: &[(&[&str], &str)] = &[
|
||||||
(
|
(
|
||||||
@ -404,9 +404,9 @@ mod tests {
|
|||||||
let mut root = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap())
|
let mut root = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap())
|
||||||
.canonicalize()
|
.canonicalize()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
if root.ends_with("rinja_derive_standalone") {
|
if root.ends_with("askama_derive_standalone") {
|
||||||
root.pop();
|
root.pop();
|
||||||
root.push("rinja_derive");
|
root.push("askama_derive");
|
||||||
}
|
}
|
||||||
|
|
||||||
root.push("templates");
|
root.push("templates");
|
||||||
@ -653,11 +653,11 @@ mod tests {
|
|||||||
str_set(&[
|
str_set(&[
|
||||||
"askama", "html", "htm", "j2", "jinja", "jinja2", "rinja", "svg", "xml"
|
"askama", "html", "htm", "j2", "jinja", "jinja2", "rinja", "svg", "xml"
|
||||||
]),
|
]),
|
||||||
"rinja::filters::Html".into()
|
"askama::filters::Html".into()
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
str_set(&["md", "none", "txt", "yml", ""]),
|
str_set(&["md", "none", "txt", "yml", ""]),
|
||||||
"rinja::filters::Text".into()
|
"askama::filters::Text".into()
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
);
|
);
|
@ -52,9 +52,9 @@ pub(crate) fn template_to_string(
|
|||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
pub(crate) enum TmplKind<'a> {
|
pub(crate) enum TmplKind<'a> {
|
||||||
/// [`rinja::Template`]
|
/// [`askama::Template`]
|
||||||
Struct,
|
Struct,
|
||||||
/// [`rinja::helpers::EnumVariantTemplate`]
|
/// [`askama::helpers::EnumVariantTemplate`]
|
||||||
Variant,
|
Variant,
|
||||||
/// Used in `blocks` implementation
|
/// Used in `blocks` implementation
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
@ -122,22 +122,22 @@ impl<'a, 'h> Generator<'a, 'h> {
|
|||||||
let ctx = &self.contexts[&self.input.path];
|
let ctx = &self.contexts[&self.input.path];
|
||||||
|
|
||||||
let target = match tmpl_kind {
|
let target = match tmpl_kind {
|
||||||
TmplKind::Struct => "rinja::Template",
|
TmplKind::Struct => "askama::Template",
|
||||||
TmplKind::Variant => "rinja::helpers::EnumVariantTemplate",
|
TmplKind::Variant => "askama::helpers::EnumVariantTemplate",
|
||||||
TmplKind::Block(trait_name) => trait_name,
|
TmplKind::Block(trait_name) => trait_name,
|
||||||
};
|
};
|
||||||
write_header(self.input.ast, buf, target);
|
write_header(self.input.ast, buf, target);
|
||||||
buf.write(
|
buf.write(
|
||||||
"fn render_into_with_values<RinjaW>(\
|
"fn render_into_with_values<AskamaW>(\
|
||||||
&self,\
|
&self,\
|
||||||
__rinja_writer: &mut RinjaW,\
|
__askama_writer: &mut AskamaW,\
|
||||||
__rinja_values: &dyn rinja::Values\
|
__askama_values: &dyn askama::Values\
|
||||||
) -> rinja::Result<()>\
|
) -> askama::Result<()>\
|
||||||
where \
|
where \
|
||||||
RinjaW: rinja::helpers::core::fmt::Write + ?rinja::helpers::core::marker::Sized\
|
AskamaW: askama::helpers::core::fmt::Write + ?askama::helpers::core::marker::Sized\
|
||||||
{\
|
{\
|
||||||
#[allow(unused_imports)]\
|
#[allow(unused_imports)]\
|
||||||
use rinja::{\
|
use askama::{\
|
||||||
filters::{AutoEscape as _, WriteWritable as _},\
|
filters::{AutoEscape as _, WriteWritable as _},\
|
||||||
helpers::{ResultConverter as _, core::fmt::Write as _},\
|
helpers::{ResultConverter as _, core::fmt::Write as _},\
|
||||||
};",
|
};",
|
||||||
@ -158,8 +158,8 @@ impl<'a, 'h> Generator<'a, 'h> {
|
|||||||
};
|
};
|
||||||
if path_is_valid {
|
if path_is_valid {
|
||||||
buf.write(format_args!(
|
buf.write(format_args!(
|
||||||
"const _: &[rinja::helpers::core::primitive::u8] =\
|
"const _: &[askama::helpers::core::primitive::u8] =\
|
||||||
rinja::helpers::core::include_bytes!({:#?});",
|
askama::helpers::core::include_bytes!({:#?});",
|
||||||
path.canonicalize().as_deref().unwrap_or(path),
|
path.canonicalize().as_deref().unwrap_or(path),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@ -167,10 +167,10 @@ impl<'a, 'h> Generator<'a, 'h> {
|
|||||||
|
|
||||||
let size_hint = self.impl_template_inner(ctx, buf)?;
|
let size_hint = self.impl_template_inner(ctx, buf)?;
|
||||||
|
|
||||||
buf.write("rinja::Result::Ok(()) }");
|
buf.write("askama::Result::Ok(()) }");
|
||||||
if tmpl_kind == TmplKind::Struct {
|
if tmpl_kind == TmplKind::Struct {
|
||||||
buf.write(format_args!(
|
buf.write(format_args!(
|
||||||
"const SIZE_HINT: rinja::helpers::core::primitive::usize = {size_hint}usize;",
|
"const SIZE_HINT: askama::helpers::core::primitive::usize = {size_hint}usize;",
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,9 +192,9 @@ impl<'a, 'h> Generator<'a, 'h> {
|
|||||||
) -> Result<(), CompileError> {
|
) -> Result<(), CompileError> {
|
||||||
// RATIONALE: `*self` must be the input type, implementation details should not leak:
|
// RATIONALE: `*self` must be the input type, implementation details should not leak:
|
||||||
// - impl Self { fn as_block(self) } ->
|
// - impl Self { fn as_block(self) } ->
|
||||||
// - struct __Rinja__Self__as__block__Wrapper { this: self } ->
|
// - struct __Askama__Self__as__block__Wrapper { this: self } ->
|
||||||
// - impl Template for __Rinja__Self__as__block__Wrapper { fn render_into_with_values() } ->
|
// - impl Template for __Askama__Self__as__block__Wrapper { fn render_into_with_values() } ->
|
||||||
// - impl __Rinja__Self__as__block for Self { render_into_with_values() }
|
// - impl __Askama__Self__as__block for Self { render_into_with_values() }
|
||||||
|
|
||||||
use quote::quote_spanned;
|
use quote::quote_spanned;
|
||||||
use syn::{GenericParam, Ident, Lifetime, LifetimeParam, Token};
|
use syn::{GenericParam, Ident, Lifetime, LifetimeParam, Token};
|
||||||
@ -213,9 +213,9 @@ impl<'a, 'h> Generator<'a, 'h> {
|
|||||||
block.name
|
block.name
|
||||||
);
|
);
|
||||||
let method_name = format!("as_{}", block.name);
|
let method_name = format!("as_{}", block.name);
|
||||||
let trait_name = format!("__Rinja__{ident}__as__{}", block.name);
|
let trait_name = format!("__Askama__{ident}__as__{}", block.name);
|
||||||
let wrapper_name = format!("__Rinja__{ident}__as__{}__Wrapper", block.name);
|
let wrapper_name = format!("__Askama__{ident}__as__{}__Wrapper", block.name);
|
||||||
let self_lt_name = format!("'__Rinja__{ident}__as__{}__self", block.name);
|
let self_lt_name = format!("'__Askama__{ident}__as__{}__self", block.name);
|
||||||
|
|
||||||
let method_id = Ident::new(&method_name, span);
|
let method_id = Ident::new(&method_name, span);
|
||||||
let trait_id = Ident::new(&trait_name, span);
|
let trait_id = Ident::new(&trait_name, span);
|
||||||
@ -253,73 +253,73 @@ impl<'a, 'h> Generator<'a, 'h> {
|
|||||||
buf.write(quote_spanned! {
|
buf.write(quote_spanned! {
|
||||||
span =>
|
span =>
|
||||||
pub trait #trait_id {
|
pub trait #trait_id {
|
||||||
fn render_into_with_values<RinjaW>(
|
fn render_into_with_values<AskamaW>(
|
||||||
&self,
|
&self,
|
||||||
writer: &mut RinjaW,
|
writer: &mut AskamaW,
|
||||||
values: &dyn rinja::Values,
|
values: &dyn askama::Values,
|
||||||
) -> rinja::Result<()>
|
) -> askama::Result<()>
|
||||||
where
|
where
|
||||||
RinjaW:
|
AskamaW:
|
||||||
rinja::helpers::core::fmt::Write + ?rinja::helpers::core::marker::Sized;
|
askama::helpers::core::fmt::Write + ?askama::helpers::core::marker::Sized;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl #impl_generics #ident #ty_generics #where_clause {
|
impl #impl_generics #ident #ty_generics #where_clause {
|
||||||
#[inline]
|
#[inline]
|
||||||
#[doc = #doc]
|
#[doc = #doc]
|
||||||
pub fn #method_id(&self) -> impl rinja::Template + '_ {
|
pub fn #method_id(&self) -> impl askama::Template + '_ {
|
||||||
#wrapper_id {
|
#wrapper_id {
|
||||||
this: self,
|
this: self,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rinja::helpers::core::prelude::rust_2021::derive(
|
#[askama::helpers::core::prelude::rust_2021::derive(
|
||||||
rinja::helpers::core::prelude::rust_2021::Clone,
|
askama::helpers::core::prelude::rust_2021::Clone,
|
||||||
rinja::helpers::core::prelude::rust_2021::Copy
|
askama::helpers::core::prelude::rust_2021::Copy
|
||||||
)]
|
)]
|
||||||
pub struct #wrapper_id #wrapper_generics #wrapper_where_clause {
|
pub struct #wrapper_id #wrapper_generics #wrapper_where_clause {
|
||||||
this: &#self_lt #ident #ty_generics,
|
this: &#self_lt #ident #ty_generics,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl #wrapper_impl_generics rinja::Template
|
impl #wrapper_impl_generics askama::Template
|
||||||
for #wrapper_id #wrapper_ty_generics #wrapper_where_clause {
|
for #wrapper_id #wrapper_ty_generics #wrapper_where_clause {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn render_into_with_values<RinjaW>(
|
fn render_into_with_values<AskamaW>(
|
||||||
&self,
|
&self,
|
||||||
writer: &mut RinjaW,
|
writer: &mut AskamaW,
|
||||||
values: &dyn rinja::Values
|
values: &dyn askama::Values
|
||||||
) -> rinja::Result<()>
|
) -> askama::Result<()>
|
||||||
where
|
where
|
||||||
RinjaW: rinja::helpers::core::fmt::Write + ?rinja::helpers::core::marker::Sized
|
AskamaW: askama::helpers::core::fmt::Write + ?askama::helpers::core::marker::Sized
|
||||||
{
|
{
|
||||||
<_ as #trait_id>::render_into_with_values(self.this, writer, values)
|
<_ as #trait_id>::render_into_with_values(self.this, writer, values)
|
||||||
}
|
}
|
||||||
|
|
||||||
const SIZE_HINT: rinja::helpers::core::primitive::usize = #size_hint;
|
const SIZE_HINT: askama::helpers::core::primitive::usize = #size_hint;
|
||||||
}
|
}
|
||||||
|
|
||||||
// cannot use `crate::integrations::impl_fast_writable()` w/o cloning the struct
|
// cannot use `crate::integrations::impl_fast_writable()` w/o cloning the struct
|
||||||
impl #wrapper_impl_generics rinja::filters::FastWritable
|
impl #wrapper_impl_generics askama::filters::FastWritable
|
||||||
for #wrapper_id #wrapper_ty_generics #wrapper_where_clause {
|
for #wrapper_id #wrapper_ty_generics #wrapper_where_clause {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn write_into<RinjaW>(&self, dest: &mut RinjaW) -> rinja::Result<()>
|
fn write_into<AskamaW>(&self, dest: &mut AskamaW) -> askama::Result<()>
|
||||||
where
|
where
|
||||||
RinjaW: rinja::helpers::core::fmt::Write + ?rinja::helpers::core::marker::Sized
|
AskamaW: askama::helpers::core::fmt::Write + ?askama::helpers::core::marker::Sized
|
||||||
{
|
{
|
||||||
<_ as rinja::Template>::render_into(self, dest)
|
<_ as askama::Template>::render_into(self, dest)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// cannot use `crate::integrations::impl_display()` w/o cloning the struct
|
// cannot use `crate::integrations::impl_display()` w/o cloning the struct
|
||||||
impl #wrapper_impl_generics rinja::helpers::core::fmt::Display
|
impl #wrapper_impl_generics askama::helpers::core::fmt::Display
|
||||||
for #wrapper_id #wrapper_ty_generics #wrapper_where_clause {
|
for #wrapper_id #wrapper_ty_generics #wrapper_where_clause {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn fmt(
|
fn fmt(
|
||||||
&self,
|
&self,
|
||||||
f: &mut rinja::helpers::core::fmt::Formatter<'_>
|
f: &mut askama::helpers::core::fmt::Formatter<'_>
|
||||||
) -> rinja::helpers::core::fmt::Result {
|
) -> askama::helpers::core::fmt::Result {
|
||||||
<_ as rinja::Template>::render_into(self, f)
|
<_ as askama::Template>::render_into(self, f)
|
||||||
.map_err(|_| rinja::helpers::core::fmt::Error)
|
.map_err(|_| askama::helpers::core::fmt::Error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -366,7 +366,7 @@ fn compile_time_escape<'a>(expr: &Expr<'a>, escaper: &str) -> Option<Writable<'a
|
|||||||
}
|
}
|
||||||
|
|
||||||
// we only optimize for known escapers
|
// we only optimize for known escapers
|
||||||
let output = match escaper.strip_prefix("rinja::filters::")? {
|
let output = match escaper.strip_prefix("askama::filters::")? {
|
||||||
"Html" => OutputKind::Html,
|
"Html" => OutputKind::Html,
|
||||||
"Text" => OutputKind::Text,
|
"Text" => OutputKind::Text,
|
||||||
_ => return None,
|
_ => return None,
|
||||||
@ -591,7 +591,7 @@ fn is_attr_self(mut expr: &Expr<'_>) -> bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const FILTER_SOURCE: &str = "__rinja_filter_block";
|
const FILTER_SOURCE: &str = "__askama_filter_block";
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
enum DisplayWrap {
|
enum DisplayWrap {
|
||||||
@ -630,7 +630,7 @@ enum Writable<'a> {
|
|||||||
/// Identifiers to be replaced with raw identifiers, so as to avoid
|
/// Identifiers to be replaced with raw identifiers, so as to avoid
|
||||||
/// collisions between template syntax and Rust's syntax. In particular
|
/// collisions between template syntax and Rust's syntax. In particular
|
||||||
/// [Rust keywords](https://doc.rust-lang.org/reference/keywords.html)
|
/// [Rust keywords](https://doc.rust-lang.org/reference/keywords.html)
|
||||||
/// should be replaced, since they're not reserved words in Rinja
|
/// should be replaced, since they're not reserved words in Askama
|
||||||
/// syntax but have a high probability of causing problems in the
|
/// syntax but have a high probability of causing problems in the
|
||||||
/// generated code.
|
/// generated code.
|
||||||
///
|
///
|
@ -146,7 +146,7 @@ impl<'a> Generator<'a, '_> {
|
|||||||
self.visit_let_cond(ctx, buf, cond)?;
|
self.visit_let_cond(ctx, buf, cond)?;
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
buf.write("rinja::helpers::as_bool(&(");
|
buf.write("askama::helpers::as_bool(&(");
|
||||||
self.visit_expr(ctx, buf, expr)?;
|
self.visit_expr(ctx, buf, expr)?;
|
||||||
buf.write("))");
|
buf.write("))");
|
||||||
}
|
}
|
||||||
@ -174,10 +174,10 @@ impl<'a> Generator<'a, '_> {
|
|||||||
expr: &WithSpan<'_, Expr<'a>>,
|
expr: &WithSpan<'_, Expr<'a>>,
|
||||||
target: &str,
|
target: &str,
|
||||||
) -> Result<DisplayWrap, CompileError> {
|
) -> Result<DisplayWrap, CompileError> {
|
||||||
buf.write("rinja::helpers::get_primitive_value(&(");
|
buf.write("askama::helpers::get_primitive_value(&(");
|
||||||
self.visit_expr(ctx, buf, expr)?;
|
self.visit_expr(ctx, buf, expr)?;
|
||||||
buf.write(format_args!(
|
buf.write(format_args!(
|
||||||
")) as rinja::helpers::core::primitive::{target}"
|
")) as askama::helpers::core::primitive::{target}"
|
||||||
));
|
));
|
||||||
Ok(DisplayWrap::Unwrapped)
|
Ok(DisplayWrap::Unwrapped)
|
||||||
}
|
}
|
||||||
@ -193,7 +193,7 @@ impl<'a> Generator<'a, '_> {
|
|||||||
[expr] => self.visit_expr(ctx, buf, expr),
|
[expr] => self.visit_expr(ctx, buf, expr),
|
||||||
exprs => {
|
exprs => {
|
||||||
let (l, r) = exprs.split_at(exprs.len().div_ceil(2));
|
let (l, r) = exprs.split_at(exprs.len().div_ceil(2));
|
||||||
buf.write("rinja::helpers::Concat(&(");
|
buf.write("askama::helpers::Concat(&(");
|
||||||
self.visit_concat(ctx, buf, l)?;
|
self.visit_concat(ctx, buf, l)?;
|
||||||
buf.write("), &(");
|
buf.write("), &(");
|
||||||
self.visit_concat(ctx, buf, r)?;
|
self.visit_concat(ctx, buf, r)?;
|
||||||
@ -227,7 +227,9 @@ impl<'a> Generator<'a, '_> {
|
|||||||
) -> Result<DisplayWrap, CompileError> {
|
) -> Result<DisplayWrap, CompileError> {
|
||||||
buf.write("match (");
|
buf.write("match (");
|
||||||
self.visit_expr(ctx, buf, expr)?;
|
self.visit_expr(ctx, buf, expr)?;
|
||||||
buf.write(") { res => (&&rinja::helpers::ErrorMarker::of(&res)).rinja_conv_result(res)? }");
|
buf.write(
|
||||||
|
") { res => (&&askama::helpers::ErrorMarker::of(&res)).askama_conv_result(res)? }",
|
||||||
|
);
|
||||||
Ok(DisplayWrap::Unwrapped)
|
Ok(DisplayWrap::Unwrapped)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -312,7 +314,7 @@ impl<'a> Generator<'a, '_> {
|
|||||||
ctx.generate_error(format_args!("unexpected generics on filter `{name}`"), node)
|
ctx.generate_error(format_args!("unexpected generics on filter `{name}`"), node)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
buf.write(format_args!("rinja::filters::{name}"));
|
buf.write(format_args!("askama::filters::{name}"));
|
||||||
self.visit_call_generics(buf, generics);
|
self.visit_call_generics(buf, generics);
|
||||||
buf.write('(');
|
buf.write('(');
|
||||||
self._visit_args(ctx, buf, args)?;
|
self._visit_args(ctx, buf, args)?;
|
||||||
@ -357,7 +359,7 @@ impl<'a> Generator<'a, '_> {
|
|||||||
|
|
||||||
// Both filters return HTML-safe strings.
|
// Both filters return HTML-safe strings.
|
||||||
buf.write(format_args!(
|
buf.write(format_args!(
|
||||||
"rinja::filters::HtmlSafeOutput(rinja::filters::{name}(",
|
"askama::filters::HtmlSafeOutput(askama::filters::{name}(",
|
||||||
));
|
));
|
||||||
self._visit_args(ctx, buf, args)?;
|
self._visit_args(ctx, buf, args)?;
|
||||||
buf.write(")?)");
|
buf.write(")?)");
|
||||||
@ -373,11 +375,11 @@ impl<'a> Generator<'a, '_> {
|
|||||||
) -> Result<DisplayWrap, CompileError> {
|
) -> Result<DisplayWrap, CompileError> {
|
||||||
// All filters return numbers, and any default formatted number is HTML safe.
|
// All filters return numbers, and any default formatted number is HTML safe.
|
||||||
buf.write(format_args!(
|
buf.write(format_args!(
|
||||||
"rinja::filters::HtmlSafeOutput(rinja::filters::filesizeformat(\
|
"askama::filters::HtmlSafeOutput(askama::filters::filesizeformat(\
|
||||||
rinja::helpers::get_primitive_value(&("
|
askama::helpers::get_primitive_value(&("
|
||||||
));
|
));
|
||||||
self._visit_args(ctx, buf, args)?;
|
self._visit_args(ctx, buf, args)?;
|
||||||
buf.write(")) as rinja::helpers::core::primitive::f32)?)");
|
buf.write(")) as askama::helpers::core::primitive::f32)?)");
|
||||||
Ok(DisplayWrap::Unwrapped)
|
Ok(DisplayWrap::Unwrapped)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -413,7 +415,7 @@ impl<'a> Generator<'a, '_> {
|
|||||||
let value = if is_singular { sg } else { pl };
|
let value = if is_singular { sg } else { pl };
|
||||||
self._visit_auto_escaped_arg(ctx, buf, value)?;
|
self._visit_auto_escaped_arg(ctx, buf, value)?;
|
||||||
} else {
|
} else {
|
||||||
buf.write("rinja::filters::pluralize(");
|
buf.write("askama::filters::pluralize(");
|
||||||
self._visit_arg(ctx, buf, count)?;
|
self._visit_arg(ctx, buf, count)?;
|
||||||
for value in [sg, pl] {
|
for value in [sg, pl] {
|
||||||
buf.write(',');
|
buf.write(',');
|
||||||
@ -470,11 +472,11 @@ impl<'a> Generator<'a, '_> {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
buf.write(format_args!(
|
buf.write(format_args!(
|
||||||
"rinja::filters::{name}(&(&&rinja::filters::AutoEscaper::new(&(",
|
"askama::filters::{name}(&(&&askama::filters::AutoEscaper::new(&(",
|
||||||
));
|
));
|
||||||
self._visit_args(ctx, buf, args)?;
|
self._visit_args(ctx, buf, args)?;
|
||||||
// The input is always HTML escaped, regardless of the selected escaper:
|
// The input is always HTML escaped, regardless of the selected escaper:
|
||||||
buf.write("), rinja::filters::Html)).rinja_auto_escape()?)?");
|
buf.write("), askama::filters::Html)).askama_auto_escape()?)?");
|
||||||
// The output is marked as HTML safe, not safe in all contexts:
|
// The output is marked as HTML safe, not safe in all contexts:
|
||||||
Ok(DisplayWrap::Unwrapped)
|
Ok(DisplayWrap::Unwrapped)
|
||||||
}
|
}
|
||||||
@ -530,7 +532,7 @@ impl<'a> Generator<'a, '_> {
|
|||||||
2 => "json_pretty",
|
2 => "json_pretty",
|
||||||
_ => return Err(ctx.generate_error("unexpected argument(s) in `json` filter", node)),
|
_ => return Err(ctx.generate_error("unexpected argument(s) in `json` filter", node)),
|
||||||
};
|
};
|
||||||
buf.write(format_args!("rinja::filters::{filter}("));
|
buf.write(format_args!("askama::filters::{filter}("));
|
||||||
self._visit_args(ctx, buf, args)?;
|
self._visit_args(ctx, buf, args)?;
|
||||||
buf.write(")?");
|
buf.write(")?");
|
||||||
Ok(DisplayWrap::Unwrapped)
|
Ok(DisplayWrap::Unwrapped)
|
||||||
@ -546,7 +548,7 @@ impl<'a> Generator<'a, '_> {
|
|||||||
if args.len() != 1 {
|
if args.len() != 1 {
|
||||||
return Err(ctx.generate_error("unexpected argument(s) in `safe` filter", node));
|
return Err(ctx.generate_error("unexpected argument(s) in `safe` filter", node));
|
||||||
}
|
}
|
||||||
buf.write("rinja::filters::safe(");
|
buf.write("askama::filters::safe(");
|
||||||
self._visit_args(ctx, buf, args)?;
|
self._visit_args(ctx, buf, args)?;
|
||||||
buf.write(format_args!(", {})?", self.input.escaper));
|
buf.write(format_args!(", {})?", self.input.escaper));
|
||||||
Ok(DisplayWrap::Wrapped)
|
Ok(DisplayWrap::Wrapped)
|
||||||
@ -606,7 +608,7 @@ impl<'a> Generator<'a, '_> {
|
|||||||
})?,
|
})?,
|
||||||
None => self.input.escaper,
|
None => self.input.escaper,
|
||||||
};
|
};
|
||||||
buf.write("rinja::filters::escape(");
|
buf.write("askama::filters::escape(");
|
||||||
self._visit_args(ctx, buf, &args[..1])?;
|
self._visit_args(ctx, buf, &args[..1])?;
|
||||||
buf.write(format_args!(", {escaper})?"));
|
buf.write(format_args!(", {escaper})?"));
|
||||||
Ok(DisplayWrap::Wrapped)
|
Ok(DisplayWrap::Wrapped)
|
||||||
@ -622,7 +624,7 @@ impl<'a> Generator<'a, '_> {
|
|||||||
ensure_filter_has_feature_alloc(ctx, "format", node)?;
|
ensure_filter_has_feature_alloc(ctx, "format", node)?;
|
||||||
if !args.is_empty() {
|
if !args.is_empty() {
|
||||||
if let Expr::StrLit(ref fmt) = *args[0] {
|
if let Expr::StrLit(ref fmt) = *args[0] {
|
||||||
buf.write("rinja::helpers::alloc::format!(");
|
buf.write("askama::helpers::alloc::format!(");
|
||||||
self.visit_str_lit(buf, fmt);
|
self.visit_str_lit(buf, fmt);
|
||||||
if args.len() > 1 {
|
if args.len() > 1 {
|
||||||
buf.write(',');
|
buf.write(',');
|
||||||
@ -645,7 +647,7 @@ impl<'a> Generator<'a, '_> {
|
|||||||
ensure_filter_has_feature_alloc(ctx, "fmt", node)?;
|
ensure_filter_has_feature_alloc(ctx, "fmt", node)?;
|
||||||
if let [_, arg2] = args {
|
if let [_, arg2] = args {
|
||||||
if let Expr::StrLit(ref fmt) = **arg2 {
|
if let Expr::StrLit(ref fmt) = **arg2 {
|
||||||
buf.write("rinja::helpers::alloc::format!(");
|
buf.write("askama::helpers::alloc::format!(");
|
||||||
self.visit_str_lit(buf, fmt);
|
self.visit_str_lit(buf, fmt);
|
||||||
buf.write(',');
|
buf.write(',');
|
||||||
self._visit_args(ctx, buf, &args[..1])?;
|
self._visit_args(ctx, buf, &args[..1])?;
|
||||||
@ -664,7 +666,7 @@ impl<'a> Generator<'a, '_> {
|
|||||||
args: &[WithSpan<'_, Expr<'a>>],
|
args: &[WithSpan<'_, Expr<'a>>],
|
||||||
_node: Span<'_>,
|
_node: Span<'_>,
|
||||||
) -> Result<DisplayWrap, CompileError> {
|
) -> Result<DisplayWrap, CompileError> {
|
||||||
buf.write("rinja::filters::join((&");
|
buf.write("askama::filters::join((&");
|
||||||
for (i, arg) in args.iter().enumerate() {
|
for (i, arg) in args.iter().enumerate() {
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
buf.write(", &");
|
buf.write(", &");
|
||||||
@ -699,11 +701,11 @@ impl<'a> Generator<'a, '_> {
|
|||||||
node,
|
node,
|
||||||
));
|
));
|
||||||
};
|
};
|
||||||
buf.write("rinja::helpers::get_value");
|
buf.write("askama::helpers::get_value");
|
||||||
buf.write("::<");
|
buf.write("::<");
|
||||||
self.visit_ty_generic(buf, gen);
|
self.visit_ty_generic(buf, gen);
|
||||||
buf.write('>');
|
buf.write('>');
|
||||||
buf.write("(&__rinja_values, &(");
|
buf.write("(&__askama_values, &(");
|
||||||
self._visit_arg(ctx, buf, key)?;
|
self._visit_arg(ctx, buf, key)?;
|
||||||
buf.write("))");
|
buf.write("))");
|
||||||
Ok(DisplayWrap::Unwrapped)
|
Ok(DisplayWrap::Unwrapped)
|
||||||
@ -774,17 +776,17 @@ impl<'a> Generator<'a, '_> {
|
|||||||
) -> Result<(), CompileError> {
|
) -> Result<(), CompileError> {
|
||||||
if let Some(Writable::Lit(arg)) = compile_time_escape(arg, self.input.escaper) {
|
if let Some(Writable::Lit(arg)) = compile_time_escape(arg, self.input.escaper) {
|
||||||
if !arg.is_empty() {
|
if !arg.is_empty() {
|
||||||
buf.write("rinja::filters::Safe(");
|
buf.write("askama::filters::Safe(");
|
||||||
buf.write_escaped_str(&arg);
|
buf.write_escaped_str(&arg);
|
||||||
buf.write(')');
|
buf.write(')');
|
||||||
} else {
|
} else {
|
||||||
buf.write("rinja::helpers::Empty");
|
buf.write("askama::helpers::Empty");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
buf.write("(&&rinja::filters::AutoEscaper::new(");
|
buf.write("(&&askama::filters::AutoEscaper::new(");
|
||||||
self._visit_arg(ctx, buf, arg)?;
|
self._visit_arg(ctx, buf, arg)?;
|
||||||
buf.write(format_args!(
|
buf.write(format_args!(
|
||||||
", {})).rinja_auto_escape()?",
|
", {})).askama_auto_escape()?",
|
||||||
self.input.escaper
|
self.input.escaper
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@ -904,7 +906,7 @@ impl<'a> Generator<'a, '_> {
|
|||||||
);\
|
);\
|
||||||
let _len = _cycle.len();\
|
let _len = _cycle.len();\
|
||||||
if _len == 0 {\
|
if _len == 0 {\
|
||||||
return rinja::helpers::core::result::Result::Err(rinja::Error::Fmt);\
|
return askama::helpers::core::result::Result::Err(askama::Error::Fmt);\
|
||||||
}\
|
}\
|
||||||
_cycle[_loop_item.index % _len]\
|
_cycle[_loop_item.index % _len]\
|
||||||
})",
|
})",
|
||||||
@ -926,8 +928,8 @@ impl<'a> Generator<'a, '_> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// We special-case "rinja::get_value".
|
// We special-case "askama::get_value".
|
||||||
Expr::Path(path) if path == &["rinja", "get_value"] => {
|
Expr::Path(path) if path == &["askama", "get_value"] => {
|
||||||
self._visit_value(
|
self._visit_value(
|
||||||
ctx,
|
ctx,
|
||||||
buf,
|
buf,
|
||||||
@ -1088,7 +1090,7 @@ impl<'a> Generator<'a, '_> {
|
|||||||
fn visit_filter_source(&mut self, buf: &mut Buffer) -> DisplayWrap {
|
fn visit_filter_source(&mut self, buf: &mut Buffer) -> DisplayWrap {
|
||||||
// We can assume that the body of the `{% filter %}` was already escaped.
|
// We can assume that the body of the `{% filter %}` was already escaped.
|
||||||
// And if it's not, then this was done intentionally.
|
// And if it's not, then this was done intentionally.
|
||||||
buf.write(format_args!("rinja::filters::Safe(&{FILTER_SOURCE})"));
|
buf.write(format_args!("askama::filters::Safe(&{FILTER_SOURCE})"));
|
||||||
DisplayWrap::Wrapped
|
DisplayWrap::Wrapped
|
||||||
}
|
}
|
||||||
|
|
@ -555,7 +555,7 @@ impl<'a> Generator<'a, '_> {
|
|||||||
let size_hint1 = this.push_locals(|this| {
|
let size_hint1 = this.push_locals(|this| {
|
||||||
buf.write("for (");
|
buf.write("for (");
|
||||||
this.visit_target(buf, true, true, &loop_block.var);
|
this.visit_target(buf, true, true, &loop_block.var);
|
||||||
buf.write(", _loop_item) in rinja::helpers::TemplateLoop::new(_iter) {");
|
buf.write(", _loop_item) in askama::helpers::TemplateLoop::new(_iter) {");
|
||||||
|
|
||||||
if has_else_nodes {
|
if has_else_nodes {
|
||||||
buf.write("_did_loop = true;");
|
buf.write("_did_loop = true;");
|
||||||
@ -779,8 +779,8 @@ impl<'a> Generator<'a, '_> {
|
|||||||
|
|
||||||
// build `FmtCell` that contains the inner block
|
// build `FmtCell` that contains the inner block
|
||||||
buf.write(format_args!(
|
buf.write(format_args!(
|
||||||
"let {FILTER_SOURCE} = rinja::helpers::FmtCell::new(\
|
"let {FILTER_SOURCE} = askama::helpers::FmtCell::new(\
|
||||||
|__rinja_writer: &mut rinja::helpers::core::fmt::Formatter<'_>| -> rinja::Result<()> {{"
|
|__askama_writer: &mut askama::helpers::core::fmt::Formatter<'_>| -> askama::Result<()> {{"
|
||||||
));
|
));
|
||||||
let size_hint = self.push_locals(|this| {
|
let size_hint = self.push_locals(|this| {
|
||||||
this.prepare_ws(filter.ws1);
|
this.prepare_ws(filter.ws1);
|
||||||
@ -791,7 +791,7 @@ impl<'a> Generator<'a, '_> {
|
|||||||
})?;
|
})?;
|
||||||
buf.write(
|
buf.write(
|
||||||
"\
|
"\
|
||||||
rinja::Result::Ok(())\
|
askama::Result::Ok(())\
|
||||||
});",
|
});",
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -808,12 +808,12 @@ impl<'a> Generator<'a, '_> {
|
|||||||
let filter_buf = match display_wrap {
|
let filter_buf = match display_wrap {
|
||||||
DisplayWrap::Wrapped => fmt_left!("{filter_buf}"),
|
DisplayWrap::Wrapped => fmt_left!("{filter_buf}"),
|
||||||
DisplayWrap::Unwrapped => fmt_right!(
|
DisplayWrap::Unwrapped => fmt_right!(
|
||||||
"(&&rinja::filters::AutoEscaper::new(&({filter_buf}), {})).rinja_auto_escape()?",
|
"(&&askama::filters::AutoEscaper::new(&({filter_buf}), {})).askama_auto_escape()?",
|
||||||
self.input.escaper,
|
self.input.escaper,
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
buf.write(format_args!(
|
buf.write(format_args!(
|
||||||
"if rinja::helpers::core::write!(__rinja_writer, \"{{}}\", {filter_buf}).is_err() {{\
|
"if askama::helpers::core::write!(__askama_writer, \"{{}}\", {filter_buf}).is_err() {{\
|
||||||
return {FILTER_SOURCE}.take_err();\
|
return {FILTER_SOURCE}.take_err();\
|
||||||
}}"
|
}}"
|
||||||
));
|
));
|
||||||
@ -1148,8 +1148,8 @@ impl<'a> Generator<'a, '_> {
|
|||||||
let expr = match self.visit_expr(ctx, &mut expr_buf, s)? {
|
let expr = match self.visit_expr(ctx, &mut expr_buf, s)? {
|
||||||
DisplayWrap::Wrapped => expr_buf.into_string(),
|
DisplayWrap::Wrapped => expr_buf.into_string(),
|
||||||
DisplayWrap::Unwrapped => format!(
|
DisplayWrap::Unwrapped => format!(
|
||||||
"(&&rinja::filters::AutoEscaper::new(&({expr_buf}), {})).\
|
"(&&askama::filters::AutoEscaper::new(&({expr_buf}), {})).\
|
||||||
rinja_auto_escape()?",
|
askama_auto_escape()?",
|
||||||
self.input.escaper,
|
self.input.escaper,
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
@ -1169,8 +1169,8 @@ impl<'a> Generator<'a, '_> {
|
|||||||
idx
|
idx
|
||||||
};
|
};
|
||||||
lines.write(format_args!(
|
lines.write(format_args!(
|
||||||
"(&&&rinja::filters::Writable(expr{idx})).\
|
"(&&&askama::filters::Writable(expr{idx})).\
|
||||||
rinja_write(__rinja_writer, __rinja_values)?;",
|
askama_write(__askama_writer, __askama_values)?;",
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
1
askama_derive/src/html.rs
Symbolic link
1
askama_derive/src/html.rs
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../../askama/src/html.rs
|
@ -105,7 +105,7 @@ impl TemplateInput<'_> {
|
|||||||
CompileError::no_file_info(
|
CompileError::no_file_info(
|
||||||
format_args!(
|
format_args!(
|
||||||
"no escaper defined for extension '{escaping}'. You can define an escaper \
|
"no escaper defined for extension '{escaping}'. You can define an escaper \
|
||||||
in the config file (named `rinja.toml` by default). {}",
|
in the config file (named `askama.toml` by default). {}",
|
||||||
MsgValidEscapers(&config.escapers),
|
MsgValidEscapers(&config.escapers),
|
||||||
),
|
),
|
||||||
*ext_span,
|
*ext_span,
|
||||||
@ -458,7 +458,7 @@ impl TemplateArgs {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Try to find the source in the comment, in a `rinja` code block.
|
/// Try to find the source in the comment, in a `askama` code block.
|
||||||
///
|
///
|
||||||
/// This is only done if no path or source was given in the `#[template]` attribute.
|
/// This is only done if no path or source was given in the `#[template]` attribute.
|
||||||
#[cfg(feature = "code-in-doc")]
|
#[cfg(feature = "code-in-doc")]
|
||||||
@ -469,7 +469,7 @@ fn source_from_docs(
|
|||||||
) -> Result<(Source, Option<Span>), CompileError> {
|
) -> Result<(Source, Option<Span>), CompileError> {
|
||||||
let (source_span, source) = collect_comment_blocks(span, docs, ast)?;
|
let (source_span, source) = collect_comment_blocks(span, docs, ast)?;
|
||||||
let source = strip_common_ws_prefix(source);
|
let source = strip_common_ws_prefix(source);
|
||||||
let source = collect_rinja_code_blocks(span, ast, source)?;
|
let source = collect_askama_code_blocks(span, ast, source)?;
|
||||||
Ok((source, source_span))
|
Ok((source, source_span))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -521,14 +521,14 @@ fn collect_comment_blocks(
|
|||||||
source.push('\n');
|
source.push('\n');
|
||||||
}
|
}
|
||||||
if source.is_empty() {
|
if source.is_empty() {
|
||||||
return Err(no_rinja_code_block(span, ast));
|
return Err(no_askama_code_block(span, ast));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok((source_span, source))
|
Ok((source_span, source))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "code-in-doc")]
|
#[cfg(feature = "code-in-doc")]
|
||||||
fn no_rinja_code_block(span: Span, ast: &syn::DeriveInput) -> CompileError {
|
fn no_askama_code_block(span: Span, ast: &syn::DeriveInput) -> CompileError {
|
||||||
let kind = match &ast.data {
|
let kind = match &ast.data {
|
||||||
syn::Data::Struct(_) => "struct",
|
syn::Data::Struct(_) => "struct",
|
||||||
syn::Data::Enum(_) => "enum",
|
syn::Data::Enum(_) => "enum",
|
||||||
@ -538,7 +538,7 @@ fn no_rinja_code_block(span: Span, ast: &syn::DeriveInput) -> CompileError {
|
|||||||
CompileError::no_file_info(
|
CompileError::no_file_info(
|
||||||
format_args!(
|
format_args!(
|
||||||
"when using `in_doc` with the value `true`, the {kind}'s documentation needs a \
|
"when using `in_doc` with the value `true`, the {kind}'s documentation needs a \
|
||||||
`rinja` code block"
|
`askama` code block"
|
||||||
),
|
),
|
||||||
Some(span),
|
Some(span),
|
||||||
)
|
)
|
||||||
@ -573,7 +573,7 @@ fn strip_common_ws_prefix(source: String) -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "code-in-doc")]
|
#[cfg(feature = "code-in-doc")]
|
||||||
fn collect_rinja_code_blocks(
|
fn collect_askama_code_blocks(
|
||||||
span: Span,
|
span: Span,
|
||||||
ast: &syn::DeriveInput,
|
ast: &syn::DeriveInput,
|
||||||
source: String,
|
source: String,
|
||||||
@ -581,25 +581,25 @@ fn collect_rinja_code_blocks(
|
|||||||
use pulldown_cmark::{CodeBlockKind, Event, Parser, Tag, TagEnd};
|
use pulldown_cmark::{CodeBlockKind, Event, Parser, Tag, TagEnd};
|
||||||
|
|
||||||
let mut tmpl_source = String::new();
|
let mut tmpl_source = String::new();
|
||||||
let mut in_rinja_code = false;
|
let mut in_askama_code = false;
|
||||||
let mut had_rinja_code = false;
|
let mut had_askama_code = false;
|
||||||
for e in Parser::new(&source) {
|
for e in Parser::new(&source) {
|
||||||
match (in_rinja_code, e) {
|
match (in_askama_code, e) {
|
||||||
(false, Event::Start(Tag::CodeBlock(CodeBlockKind::Fenced(s)))) => {
|
(false, Event::Start(Tag::CodeBlock(CodeBlockKind::Fenced(s)))) => {
|
||||||
if s.split(",")
|
if s.split(",")
|
||||||
.any(|s| JINJA_EXTENSIONS.contains(&s.trim_ascii()))
|
.any(|s| JINJA_EXTENSIONS.contains(&s.trim_ascii()))
|
||||||
{
|
{
|
||||||
in_rinja_code = true;
|
in_askama_code = true;
|
||||||
had_rinja_code = true;
|
had_askama_code = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(true, Event::End(TagEnd::CodeBlock)) => in_rinja_code = false,
|
(true, Event::End(TagEnd::CodeBlock)) => in_askama_code = false,
|
||||||
(true, Event::Text(text)) => tmpl_source.push_str(&text),
|
(true, Event::Text(text)) => tmpl_source.push_str(&text),
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !had_rinja_code {
|
if !had_askama_code {
|
||||||
return Err(no_rinja_code_block(span, ast));
|
return Err(no_askama_code_block(span, ast));
|
||||||
}
|
}
|
||||||
|
|
||||||
if tmpl_source.ends_with('\n') {
|
if tmpl_source.ends_with('\n') {
|
||||||
@ -763,7 +763,7 @@ const _: () = {
|
|||||||
// FIXME: implement once <https://github.com/rust-lang/rfcs/pull/3715> is stable
|
// FIXME: implement once <https://github.com/rust-lang/rfcs/pull/3715> is stable
|
||||||
if let syn::Data::Union(data) = &ast.data {
|
if let syn::Data::Union(data) = &ast.data {
|
||||||
return Err(CompileError::new_with_span(
|
return Err(CompileError::new_with_span(
|
||||||
"rinja templates are not supported for `union` types, only `struct` and `enum`",
|
"askama templates are not supported for `union` types, only `struct` and `enum`",
|
||||||
None,
|
None,
|
||||||
Some(data.union_token.span),
|
Some(data.union_token.span),
|
||||||
));
|
));
|
||||||
@ -826,10 +826,10 @@ const _: () = {
|
|||||||
None => unreachable!("not possible in syn::Meta::NameValue(…)"),
|
None => unreachable!("not possible in syn::Meta::NameValue(…)"),
|
||||||
};
|
};
|
||||||
|
|
||||||
if ident == "rinja" {
|
if ident == "askama" {
|
||||||
if is_enum_variant {
|
if is_enum_variant {
|
||||||
return Err(CompileError::no_file_info(
|
return Err(CompileError::no_file_info(
|
||||||
"template attribute `rinja` can only be used on the `enum`, \
|
"template attribute `askama` can only be used on the `enum`, \
|
||||||
not its variants",
|
not its variants",
|
||||||
Some(ident.span()),
|
Some(ident.span()),
|
||||||
));
|
));
|
@ -36,23 +36,23 @@ fn impl_display(ast: &DeriveInput, buf: &mut Buffer) {
|
|||||||
let ident = &ast.ident;
|
let ident = &ast.ident;
|
||||||
buf.write(format_args!(
|
buf.write(format_args!(
|
||||||
"\
|
"\
|
||||||
/// Implement the [`format!()`][rinja::helpers::std::format] trait for [`{}`]\n\
|
/// Implement the [`format!()`][askama::helpers::std::format] trait for [`{}`]\n\
|
||||||
///\n\
|
///\n\
|
||||||
/// Please be aware of the rendering performance notice in the \
|
/// Please be aware of the rendering performance notice in the \
|
||||||
[`Template`][rinja::Template] trait.\n\
|
[`Template`][askama::Template] trait.\n\
|
||||||
",
|
",
|
||||||
quote!(#ident),
|
quote!(#ident),
|
||||||
));
|
));
|
||||||
write_header(ast, buf, "rinja::helpers::core::fmt::Display");
|
write_header(ast, buf, "askama::helpers::core::fmt::Display");
|
||||||
buf.write(
|
buf.write(
|
||||||
"\
|
"\
|
||||||
#[inline]\
|
#[inline]\
|
||||||
fn fmt(\
|
fn fmt(\
|
||||||
&self,\
|
&self,\
|
||||||
f: &mut rinja::helpers::core::fmt::Formatter<'_>\
|
f: &mut askama::helpers::core::fmt::Formatter<'_>\
|
||||||
) -> rinja::helpers::core::fmt::Result {\
|
) -> askama::helpers::core::fmt::Result {\
|
||||||
rinja::Template::render_into(self, f)\
|
askama::Template::render_into(self, f)\
|
||||||
.map_err(|_| rinja::helpers::core::fmt::Error)\
|
.map_err(|_| askama::helpers::core::fmt::Error)\
|
||||||
}\
|
}\
|
||||||
}",
|
}",
|
||||||
);
|
);
|
||||||
@ -60,15 +60,15 @@ fn impl_display(ast: &DeriveInput, buf: &mut Buffer) {
|
|||||||
|
|
||||||
/// Implement `FastWritable` for the given item.
|
/// Implement `FastWritable` for the given item.
|
||||||
fn impl_fast_writable(ast: &DeriveInput, buf: &mut Buffer) {
|
fn impl_fast_writable(ast: &DeriveInput, buf: &mut Buffer) {
|
||||||
write_header(ast, buf, "rinja::filters::FastWritable");
|
write_header(ast, buf, "askama::filters::FastWritable");
|
||||||
buf.write(
|
buf.write(
|
||||||
"\
|
"\
|
||||||
#[inline]\
|
#[inline]\
|
||||||
fn write_into<RinjaW>(&self, dest: &mut RinjaW) -> rinja::Result<()> \
|
fn write_into<AskamaW>(&self, dest: &mut AskamaW) -> askama::Result<()> \
|
||||||
where \
|
where \
|
||||||
RinjaW: rinja::helpers::core::fmt::Write + ?rinja::helpers::core::marker::Sized,\
|
AskamaW: askama::helpers::core::fmt::Write + ?askama::helpers::core::marker::Sized,\
|
||||||
{\
|
{\
|
||||||
rinja::Template::render_into(self, dest)\
|
askama::Template::render_into(self, dest)\
|
||||||
}\
|
}\
|
||||||
}",
|
}",
|
||||||
);
|
);
|
||||||
@ -145,7 +145,7 @@ impl Buffer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn write_writer(&mut self, s: &str) -> usize {
|
pub(crate) fn write_writer(&mut self, s: &str) -> usize {
|
||||||
const OPEN: &str = r#"__rinja_writer.write_str(""#;
|
const OPEN: &str = r#"__askama_writer.write_str(""#;
|
||||||
const CLOSE: &str = r#"")?;"#;
|
const CLOSE: &str = r#"")?;"#;
|
||||||
|
|
||||||
if !s.is_empty() && !self.discard {
|
if !s.is_empty() && !self.discard {
|
||||||
@ -254,7 +254,7 @@ pub(crate) fn build_template_enum(
|
|||||||
|
|
||||||
let enum_id = &enum_ast.ident;
|
let enum_id = &enum_ast.ident;
|
||||||
let enum_span = enum_id.span();
|
let enum_span = enum_id.span();
|
||||||
let lifetime = Lifetime::new(&format!("'__Rinja_{enum_id}"), enum_span);
|
let lifetime = Lifetime::new(&format!("'__Askama_{enum_id}"), enum_span);
|
||||||
|
|
||||||
let mut generics = enum_ast.generics.clone();
|
let mut generics = enum_ast.generics.clone();
|
||||||
if generics.lt_token.is_none() {
|
if generics.lt_token.is_none() {
|
||||||
@ -315,11 +315,11 @@ pub(crate) fn build_template_enum(
|
|||||||
biggest_size_hint = biggest_size_hint.max(size_hint);
|
biggest_size_hint = biggest_size_hint.max(size_hint);
|
||||||
|
|
||||||
render_into_arms.extend(quote! {
|
render_into_arms.extend(quote! {
|
||||||
ref __rinja_arg => {
|
ref __askama_arg => {
|
||||||
<_ as rinja::helpers::EnumVariantTemplate>::render_into_with_values(
|
<_ as askama::helpers::EnumVariantTemplate>::render_into_with_values(
|
||||||
__rinja_arg,
|
__askama_arg,
|
||||||
__rinja_writer,
|
__askama_writer,
|
||||||
__rinja_values,
|
__askama_values,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -330,16 +330,16 @@ pub(crate) fn build_template_enum(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
write_header(enum_ast, buf, "rinja::Template");
|
write_header(enum_ast, buf, "askama::Template");
|
||||||
buf.write(format_args!(
|
buf.write(format_args!(
|
||||||
"\
|
"\
|
||||||
fn render_into_with_values<RinjaW>(\
|
fn render_into_with_values<AskamaW>(\
|
||||||
&self,\
|
&self,\
|
||||||
__rinja_writer: &mut RinjaW,\
|
__askama_writer: &mut AskamaW,\
|
||||||
__rinja_values: &dyn rinja::Values,\
|
__askama_values: &dyn askama::Values,\
|
||||||
) -> rinja::Result<()>\
|
) -> askama::Result<()>\
|
||||||
where \
|
where \
|
||||||
RinjaW: rinja::helpers::core::fmt::Write + ?rinja::helpers::core::marker::Sized\
|
AskamaW: askama::helpers::core::fmt::Write + ?askama::helpers::core::marker::Sized\
|
||||||
{{\
|
{{\
|
||||||
match *self {{\
|
match *self {{\
|
||||||
{render_into_arms}\
|
{render_into_arms}\
|
||||||
@ -352,21 +352,21 @@ pub(crate) fn build_template_enum(
|
|||||||
"\
|
"\
|
||||||
fn render_with_values(\
|
fn render_with_values(\
|
||||||
&self,\
|
&self,\
|
||||||
__rinja_values: &dyn rinja::Values,\
|
__askama_values: &dyn askama::Values,\
|
||||||
) -> rinja::Result<rinja::helpers::alloc::string::String> {{\
|
) -> askama::Result<askama::helpers::alloc::string::String> {{\
|
||||||
let size_hint = match self {{\
|
let size_hint = match self {{\
|
||||||
{size_hint_arms}\
|
{size_hint_arms}\
|
||||||
}};\
|
}};\
|
||||||
let mut buf = rinja::helpers::alloc::string::String::new();\
|
let mut buf = askama::helpers::alloc::string::String::new();\
|
||||||
let _ = buf.try_reserve(size_hint);\
|
let _ = buf.try_reserve(size_hint);\
|
||||||
self.render_into_with_values(&mut buf, __rinja_values)?;\
|
self.render_into_with_values(&mut buf, __askama_values)?;\
|
||||||
rinja::Result::Ok(buf)\
|
askama::Result::Ok(buf)\
|
||||||
}}",
|
}}",
|
||||||
));
|
));
|
||||||
|
|
||||||
buf.write(format_args!(
|
buf.write(format_args!(
|
||||||
"\
|
"\
|
||||||
const SIZE_HINT: rinja::helpers::core::primitive::usize = {biggest_size_hint}usize;\
|
const SIZE_HINT: askama::helpers::core::primitive::usize = {biggest_size_hint}usize;\
|
||||||
}}",
|
}}",
|
||||||
));
|
));
|
||||||
Ok(biggest_size_hint)
|
Ok(biggest_size_hint)
|
||||||
@ -397,10 +397,10 @@ fn type_for_enum_variant(
|
|||||||
|
|
||||||
let id = &var.ident;
|
let id = &var.ident;
|
||||||
let span = id.span();
|
let span = id.span();
|
||||||
let id = Ident::new(&format!("__Rinja__{enum_id}__{id}"), span);
|
let id = Ident::new(&format!("__Askama__{enum_id}__{id}"), span);
|
||||||
|
|
||||||
let phantom: Type = parse_quote! {
|
let phantom: Type = parse_quote! {
|
||||||
rinja::helpers::core::marker::PhantomData < &#lt #enum_id #ty_generics >
|
askama::helpers::core::marker::PhantomData < &#lt #enum_id #ty_generics >
|
||||||
};
|
};
|
||||||
let fields = match &var.fields {
|
let fields = match &var.fields {
|
||||||
Fields::Named(fields) => {
|
Fields::Named(fields) => {
|
||||||
@ -409,7 +409,7 @@ fn type_for_enum_variant(
|
|||||||
let ty = &f.ty;
|
let ty = &f.ty;
|
||||||
f.ty = parse_quote!(&#lt #ty);
|
f.ty = parse_quote!(&#lt #ty);
|
||||||
}
|
}
|
||||||
let id = Ident::new(&format!("__Rinja__{enum_id}__phantom"), span);
|
let id = Ident::new(&format!("__Askama__{enum_id}__phantom"), span);
|
||||||
fields.named.push(parse_quote!(#id: #phantom));
|
fields.named.push(parse_quote!(#id: #phantom));
|
||||||
Fields::Named(fields)
|
Fields::Named(fields)
|
||||||
}
|
}
|
||||||
@ -430,10 +430,10 @@ fn type_for_enum_variant(
|
|||||||
};
|
};
|
||||||
|
|
||||||
parse_quote! {
|
parse_quote! {
|
||||||
#[rinja::helpers::core::prelude::rust_2021::derive(
|
#[askama::helpers::core::prelude::rust_2021::derive(
|
||||||
rinja::helpers::core::prelude::rust_2021::Clone,
|
askama::helpers::core::prelude::rust_2021::Clone,
|
||||||
rinja::helpers::core::prelude::rust_2021::Copy,
|
askama::helpers::core::prelude::rust_2021::Copy,
|
||||||
rinja::helpers::core::prelude::rust_2021::Debug
|
askama::helpers::core::prelude::rust_2021::Debug
|
||||||
)]
|
)]
|
||||||
#[allow(dead_code, non_camel_case_types, non_snake_case)]
|
#[allow(dead_code, non_camel_case_types, non_snake_case)]
|
||||||
struct #id #enum_generics #fields #semicolon
|
struct #id #enum_generics #fields #semicolon
|
||||||
@ -461,7 +461,7 @@ fn variant_as_arm(
|
|||||||
.into_iter()
|
.into_iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(idx, token)| match idx {
|
.map(|(idx, token)| match idx {
|
||||||
// 0 1 2 3 4 => : : < ' __Rinja_Foo
|
// 0 1 2 3 4 => : : < ' __Askama_Foo
|
||||||
4 => TokenTree::Ident(Ident::new("_", span)),
|
4 => TokenTree::Ident(Ident::new("_", span)),
|
||||||
_ => token,
|
_ => token,
|
||||||
})
|
})
|
||||||
@ -475,7 +475,7 @@ fn variant_as_arm(
|
|||||||
match &var.fields {
|
match &var.fields {
|
||||||
Fields::Named(fields) => {
|
Fields::Named(fields) => {
|
||||||
for (idx, field) in fields.named.iter().enumerate() {
|
for (idx, field) in fields.named.iter().enumerate() {
|
||||||
let arg = Ident::new(&format!("__rinja_arg_{idx}"), field.span());
|
let arg = Ident::new(&format!("__askama_arg_{idx}"), field.span());
|
||||||
let id = field.ident.as_ref().unwrap();
|
let id = field.ident.as_ref().unwrap();
|
||||||
src.extend(quote!(#id: ref #arg,));
|
src.extend(quote!(#id: ref #arg,));
|
||||||
this.extend(quote!(#id: #arg,));
|
this.extend(quote!(#id: #arg,));
|
||||||
@ -492,31 +492,31 @@ fn variant_as_arm(
|
|||||||
.unwrap(),
|
.unwrap(),
|
||||||
Fields::Unnamed(_) | Fields::Unit => unreachable!(),
|
Fields::Unnamed(_) | Fields::Unit => unreachable!(),
|
||||||
};
|
};
|
||||||
this.extend(quote!(#phantom: rinja::helpers::core::marker::PhantomData {},));
|
this.extend(quote!(#phantom: askama::helpers::core::marker::PhantomData {},));
|
||||||
}
|
}
|
||||||
|
|
||||||
Fields::Unnamed(fields) => {
|
Fields::Unnamed(fields) => {
|
||||||
for (idx, field) in fields.unnamed.iter().enumerate() {
|
for (idx, field) in fields.unnamed.iter().enumerate() {
|
||||||
let span = field.ident.span();
|
let span = field.ident.span();
|
||||||
let arg = Ident::new(&format!("__rinja_arg_{idx}"), span);
|
let arg = Ident::new(&format!("__askama_arg_{idx}"), span);
|
||||||
let idx = syn::LitInt::new(&format!("{idx}"), span);
|
let idx = syn::LitInt::new(&format!("{idx}"), span);
|
||||||
src.extend(quote!(#idx: ref #arg,));
|
src.extend(quote!(#idx: ref #arg,));
|
||||||
this.extend(quote!(#idx: #arg,));
|
this.extend(quote!(#idx: #arg,));
|
||||||
}
|
}
|
||||||
let idx = syn::LitInt::new(&format!("{}", fields.unnamed.len()), span);
|
let idx = syn::LitInt::new(&format!("{}", fields.unnamed.len()), span);
|
||||||
this.extend(quote!(#idx: rinja::helpers::core::marker::PhantomData {},));
|
this.extend(quote!(#idx: askama::helpers::core::marker::PhantomData {},));
|
||||||
}
|
}
|
||||||
|
|
||||||
Fields::Unit => {
|
Fields::Unit => {
|
||||||
this.extend(quote!(0: rinja::helpers::core::marker::PhantomData {},));
|
this.extend(quote!(0: askama::helpers::core::marker::PhantomData {},));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
render_into_arms.extend(quote! {
|
render_into_arms.extend(quote! {
|
||||||
Self :: #ident { #src } => {
|
Self :: #ident { #src } => {
|
||||||
<_ as rinja::helpers::EnumVariantTemplate>::render_into_with_values(
|
<_ as askama::helpers::EnumVariantTemplate>::render_into_with_values(
|
||||||
& #var_id #ty_generics { #this },
|
& #var_id #ty_generics { #this },
|
||||||
__rinja_writer,
|
__askama_writer,
|
||||||
__rinja_values,
|
__askama_values,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
});
|
});
|
@ -35,7 +35,7 @@ use crate::integration::{Buffer, build_template_enum};
|
|||||||
|
|
||||||
/// The `Template` derive macro and its `template()` attribute.
|
/// The `Template` derive macro and its `template()` attribute.
|
||||||
///
|
///
|
||||||
/// Rinja works by generating one or more trait implementations for any
|
/// Askama works by generating one or more trait implementations for any
|
||||||
/// `struct` type decorated with the `#[derive(Template)]` attribute. The
|
/// `struct` type decorated with the `#[derive(Template)]` attribute. The
|
||||||
/// code generation process takes some options that can be specified through
|
/// code generation process takes some options that can be specified through
|
||||||
/// the `template()` attribute.
|
/// the `template()` attribute.
|
||||||
@ -80,10 +80,10 @@ use crate::integration::{Buffer, build_template_enum};
|
|||||||
/// of the template `struct`.
|
/// of the template `struct`.
|
||||||
///
|
///
|
||||||
/// Instead of `path = "…"` or `source = "…"`, specify `in_doc = true` in the `#[template]`
|
/// Instead of `path = "…"` or `source = "…"`, specify `in_doc = true` in the `#[template]`
|
||||||
/// attribute, and in the struct's documentation add a `rinja` code block:
|
/// attribute, and in the struct's documentation add a `askama` code block:
|
||||||
///
|
///
|
||||||
/// ```rust,ignore
|
/// ```rust,ignore
|
||||||
/// /// ```rinja
|
/// /// ```askama
|
||||||
/// /// <div>{{ lines|linebreaksbr }}</div>
|
/// /// <div>{{ lines|linebreaksbr }}</div>
|
||||||
/// /// ```
|
/// /// ```
|
||||||
/// #[derive(Template)]
|
/// #[derive(Template)]
|
||||||
@ -163,30 +163,30 @@ use crate::integration::{Buffer, build_template_enum};
|
|||||||
/// E.g. `syntax = "foo"`
|
/// E.g. `syntax = "foo"`
|
||||||
///
|
///
|
||||||
/// Set the syntax name for a parser defined in the configuration file.
|
/// Set the syntax name for a parser defined in the configuration file.
|
||||||
/// The default syntax, `"default"`, is the one provided by Rinja.
|
/// The default syntax, `"default"`, is the one provided by Askama.
|
||||||
///
|
///
|
||||||
/// ### rinja
|
/// ### askama
|
||||||
///
|
///
|
||||||
/// E.g. `rinja = rinja`
|
/// E.g. `askama = askama`
|
||||||
///
|
///
|
||||||
/// If you are using rinja in a subproject, a library or a [macro][book-macro], it might be
|
/// If you are using askama in a subproject, a library or a [macro][book-macro], it might be
|
||||||
/// necessary to specify the [path][book-tree] where to find the module `rinja`:
|
/// necessary to specify the [path][book-tree] where to find the module `askama`:
|
||||||
///
|
///
|
||||||
/// [book-macro]: https://doc.rust-lang.org/book/ch19-06-macros.html
|
/// [book-macro]: https://doc.rust-lang.org/book/ch19-06-macros.html
|
||||||
/// [book-tree]: https://doc.rust-lang.org/book/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.html
|
/// [book-tree]: https://doc.rust-lang.org/book/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.html
|
||||||
///
|
///
|
||||||
/// ```rust,ignore
|
/// ```rust,ignore
|
||||||
/// #[doc(hidden)]
|
/// #[doc(hidden)]
|
||||||
/// use rinja as __rinja;
|
/// use askama as __askama;
|
||||||
///
|
///
|
||||||
/// #[macro_export]
|
/// #[macro_export]
|
||||||
/// macro_rules! new_greeter {
|
/// macro_rules! new_greeter {
|
||||||
/// ($name:ident) => {
|
/// ($name:ident) => {
|
||||||
/// #[derive(Debug, $crate::rinja::Template)]
|
/// #[derive(Debug, $crate::askama::Template)]
|
||||||
/// #[template(
|
/// #[template(
|
||||||
/// ext = "txt",
|
/// ext = "txt",
|
||||||
/// source = "Hello, world!",
|
/// source = "Hello, world!",
|
||||||
/// rinja = $crate::__rinja
|
/// askama = $crate::__askama
|
||||||
/// )]
|
/// )]
|
||||||
/// struct $name;
|
/// struct $name;
|
||||||
/// }
|
/// }
|
||||||
@ -227,7 +227,7 @@ pub fn derive_template(input: TokenStream12) -> TokenStream12 {
|
|||||||
let ts = if let Err(CompileError { msg, span }) = result {
|
let ts = if let Err(CompileError { msg, span }) = result {
|
||||||
let mut ts = quote_spanned! {
|
let mut ts = quote_spanned! {
|
||||||
span.unwrap_or(ast.ident.span()) =>
|
span.unwrap_or(ast.ident.span()) =>
|
||||||
rinja::helpers::core::compile_error!(#msg);
|
askama::helpers::core::compile_error!(#msg);
|
||||||
};
|
};
|
||||||
buf.clear();
|
buf.clear();
|
||||||
if build_skeleton(&mut buf, &ast).is_ok() {
|
if build_skeleton(&mut buf, &ast).is_ok() {
|
||||||
@ -243,14 +243,14 @@ pub fn derive_template(input: TokenStream12) -> TokenStream12 {
|
|||||||
let ts = if let Some(crate_name) = crate_name {
|
let ts = if let Some(crate_name) = crate_name {
|
||||||
quote! {
|
quote! {
|
||||||
const _: () = {
|
const _: () = {
|
||||||
use #crate_name as rinja;
|
use #crate_name as askama;
|
||||||
#ts
|
#ts
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
quote! {
|
quote! {
|
||||||
const _: () = {
|
const _: () = {
|
||||||
extern crate rinja;
|
extern crate askama;
|
||||||
#ts
|
#ts
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -598,7 +598,7 @@ macro_rules! fmt_right {
|
|||||||
pub(crate) use {fmt_left, fmt_right};
|
pub(crate) use {fmt_left, fmt_right};
|
||||||
|
|
||||||
// This is used by the code generator to decide whether a named filter is part of
|
// This is used by the code generator to decide whether a named filter is part of
|
||||||
// Rinja or should refer to a local `filters` module.
|
// Askama or should refer to a local `filters` module.
|
||||||
const BUILTIN_FILTERS: &[&str] = &[
|
const BUILTIN_FILTERS: &[&str] = &[
|
||||||
"capitalize",
|
"capitalize",
|
||||||
"center",
|
"center",
|
@ -26,43 +26,43 @@ fn compare(jinja: &str, expected: &str, fields: &[(&str, &str)], size_hint: usiz
|
|||||||
|
|
||||||
let expected: proc_macro2::TokenStream = expected.parse().unwrap();
|
let expected: proc_macro2::TokenStream = expected.parse().unwrap();
|
||||||
let expected: syn::File = syn::parse_quote! {
|
let expected: syn::File = syn::parse_quote! {
|
||||||
impl rinja::Template for Foo {
|
impl askama::Template for Foo {
|
||||||
fn render_into_with_values<RinjaW>(
|
fn render_into_with_values<AskamaW>(
|
||||||
&self,
|
&self,
|
||||||
__rinja_writer: &mut RinjaW,
|
__askama_writer: &mut AskamaW,
|
||||||
__rinja_values: &dyn rinja::Values,
|
__askama_values: &dyn askama::Values,
|
||||||
) -> rinja::Result<()>
|
) -> askama::Result<()>
|
||||||
where
|
where
|
||||||
RinjaW: rinja::helpers::core::fmt::Write + ?rinja::helpers::core::marker::Sized,
|
AskamaW: askama::helpers::core::fmt::Write + ?askama::helpers::core::marker::Sized,
|
||||||
{
|
{
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
use rinja::{
|
use askama::{
|
||||||
filters::{AutoEscape as _, WriteWritable as _},
|
filters::{AutoEscape as _, WriteWritable as _},
|
||||||
helpers::{ResultConverter as _, core::fmt::Write as _},
|
helpers::{ResultConverter as _, core::fmt::Write as _},
|
||||||
};
|
};
|
||||||
#expected
|
#expected
|
||||||
rinja::Result::Ok(())
|
askama::Result::Ok(())
|
||||||
}
|
}
|
||||||
const SIZE_HINT: rinja::helpers::core::primitive::usize = #size_hint;
|
const SIZE_HINT: askama::helpers::core::primitive::usize = #size_hint;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Implement the [`format!()`][rinja::helpers::std::format] trait for [`Foo`]
|
/// Implement the [`format!()`][askama::helpers::std::format] trait for [`Foo`]
|
||||||
///
|
///
|
||||||
/// Please be aware of the rendering performance notice in the [`Template`][rinja::Template] trait.
|
/// Please be aware of the rendering performance notice in the [`Template`][askama::Template] trait.
|
||||||
impl rinja::helpers::core::fmt::Display for Foo {
|
impl askama::helpers::core::fmt::Display for Foo {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn fmt(&self, f: &mut rinja::helpers::core::fmt::Formatter<'_>) -> rinja::helpers::core::fmt::Result {
|
fn fmt(&self, f: &mut askama::helpers::core::fmt::Formatter<'_>) -> askama::helpers::core::fmt::Result {
|
||||||
rinja::Template::render_into(self, f).map_err(|_| rinja::helpers::core::fmt::Error)
|
askama::Template::render_into(self, f).map_err(|_| askama::helpers::core::fmt::Error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl rinja::filters::FastWritable for Foo {
|
impl askama::filters::FastWritable for Foo {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn write_into<RinjaW>(&self, dest: &mut RinjaW) -> rinja::Result<()>
|
fn write_into<AskamaW>(&self, dest: &mut AskamaW) -> askama::Result<()>
|
||||||
where
|
where
|
||||||
RinjaW: rinja::helpers::core::fmt::Write + ?rinja::helpers::core::marker::Sized,
|
AskamaW: askama::helpers::core::fmt::Write + ?askama::helpers::core::marker::Sized,
|
||||||
{
|
{
|
||||||
rinja::Template::render_into(self, dest)
|
askama::Template::render_into(self, dest)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -153,12 +153,12 @@ fn check_if_let() {
|
|||||||
// In this test, we ensure that `query` never is `self.query`.
|
// In this test, we ensure that `query` never is `self.query`.
|
||||||
compare(
|
compare(
|
||||||
"{% if let Some(query) = s && !query.is_empty() %}{{query}}{% endif %}",
|
"{% if let Some(query) = s && !query.is_empty() %}{{query}}{% endif %}",
|
||||||
r"if let Some(query,) = &self.s && !rinja::helpers::as_bool(&(query.is_empty())) {
|
r"if let Some(query,) = &self.s && !askama::helpers::as_bool(&(query.is_empty())) {
|
||||||
match (
|
match (
|
||||||
&((&&rinja::filters::AutoEscaper::new(&(query), rinja::filters::Text)).rinja_auto_escape()?),
|
&((&&askama::filters::AutoEscaper::new(&(query), askama::filters::Text)).askama_auto_escape()?),
|
||||||
) {
|
) {
|
||||||
(expr0,) => {
|
(expr0,) => {
|
||||||
(&&&rinja::filters::Writable(expr0)).rinja_write(__rinja_writer, __rinja_values)?;
|
(&&&askama::filters::Writable(expr0)).askama_write(__askama_writer, __askama_values)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}",
|
}",
|
||||||
@ -172,10 +172,10 @@ fn check_if_let() {
|
|||||||
"{% if let Some(s) = s %}{{ s }}{% endif %}",
|
"{% if let Some(s) = s %}{{ s }}{% endif %}",
|
||||||
r"if let Some(s,) = &self.s {
|
r"if let Some(s,) = &self.s {
|
||||||
match (
|
match (
|
||||||
&((&&rinja::filters::AutoEscaper::new(&(s), rinja::filters::Text)).rinja_auto_escape()?),
|
&((&&askama::filters::AutoEscaper::new(&(s), askama::filters::Text)).askama_auto_escape()?),
|
||||||
) {
|
) {
|
||||||
(expr0,) => {
|
(expr0,) => {
|
||||||
(&&&rinja::filters::Writable(expr0)).rinja_write(__rinja_writer, __rinja_values)?;
|
(&&&askama::filters::Writable(expr0)).askama_write(__askama_writer, __askama_values)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}",
|
}",
|
||||||
@ -187,12 +187,12 @@ fn check_if_let() {
|
|||||||
// condition.
|
// condition.
|
||||||
compare(
|
compare(
|
||||||
"{% if let Some(s) = s && !s.is_empty() %}{{s}}{% endif %}",
|
"{% if let Some(s) = s && !s.is_empty() %}{{s}}{% endif %}",
|
||||||
r"if let Some(s,) = &self.s && !rinja::helpers::as_bool(&(s.is_empty())) {
|
r"if let Some(s,) = &self.s && !askama::helpers::as_bool(&(s.is_empty())) {
|
||||||
match (
|
match (
|
||||||
&((&&rinja::filters::AutoEscaper::new(&(s), rinja::filters::Text)).rinja_auto_escape()?),
|
&((&&askama::filters::AutoEscaper::new(&(s), askama::filters::Text)).askama_auto_escape()?),
|
||||||
) {
|
) {
|
||||||
(expr0,) => {
|
(expr0,) => {
|
||||||
(&&&rinja::filters::Writable(expr0)).rinja_write(__rinja_writer, __rinja_values)?;
|
(&&&askama::filters::Writable(expr0)).askama_write(__askama_writer, __askama_values)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}",
|
}",
|
||||||
@ -208,17 +208,17 @@ fn check_if_let_chain() {
|
|||||||
// Both `bla` and `blob` variables must exist in this `if`.
|
// Both `bla` and `blob` variables must exist in this `if`.
|
||||||
compare(
|
compare(
|
||||||
"{% if let Some(bla) = y && x && let Some(blob) = y %}{{bla}} {{blob}}{% endif %}",
|
"{% if let Some(bla) = y && x && let Some(blob) = y %}{{bla}} {{blob}}{% endif %}",
|
||||||
r#"if let Some(bla) = &self.y && rinja::helpers::as_bool(&(self.x)) && let Some(blob) = &self.y {
|
r#"if let Some(bla) = &self.y && askama::helpers::as_bool(&(self.x)) && let Some(blob) = &self.y {
|
||||||
match (
|
match (
|
||||||
&((&&rinja::filters::AutoEscaper::new(&(bla), rinja::filters::Text))
|
&((&&askama::filters::AutoEscaper::new(&(bla), askama::filters::Text))
|
||||||
.rinja_auto_escape()?),
|
.askama_auto_escape()?),
|
||||||
&((&&rinja::filters::AutoEscaper::new(&(blob), rinja::filters::Text))
|
&((&&askama::filters::AutoEscaper::new(&(blob), askama::filters::Text))
|
||||||
.rinja_auto_escape()?),
|
.askama_auto_escape()?),
|
||||||
) {
|
) {
|
||||||
(expr0, expr2) => {
|
(expr0, expr2) => {
|
||||||
(&&&rinja::filters::Writable(expr0)).rinja_write(__rinja_writer, __rinja_values)?;
|
(&&&askama::filters::Writable(expr0)).askama_write(__askama_writer, __askama_values)?;
|
||||||
__rinja_writer.write_str(" ")?;
|
__askama_writer.write_str(" ")?;
|
||||||
(&&&rinja::filters::Writable(expr2)).rinja_write(__rinja_writer, __rinja_values)?;
|
(&&&askama::filters::Writable(expr2)).askama_write(__askama_writer, __askama_values)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}"#,
|
}"#,
|
||||||
@ -231,19 +231,19 @@ fn check_if_let_chain() {
|
|||||||
&& bla == "x"
|
&& bla == "x"
|
||||||
&& let Some(blob) = z
|
&& let Some(blob) = z
|
||||||
&& blob == "z" %}{{bla}} {{blob}}{% endif %}"#,
|
&& blob == "z" %}{{bla}} {{blob}}{% endif %}"#,
|
||||||
r#"if let Some(bla) = &self.y && rinja::helpers::as_bool(&(bla == "x"))
|
r#"if let Some(bla) = &self.y && askama::helpers::as_bool(&(bla == "x"))
|
||||||
&& let Some(blob) = &self.z && rinja::helpers::as_bool(&(blob == "z"))
|
&& let Some(blob) = &self.z && askama::helpers::as_bool(&(blob == "z"))
|
||||||
{
|
{
|
||||||
match (
|
match (
|
||||||
&((&&rinja::filters::AutoEscaper::new(&(bla), rinja::filters::Text))
|
&((&&askama::filters::AutoEscaper::new(&(bla), askama::filters::Text))
|
||||||
.rinja_auto_escape()?),
|
.askama_auto_escape()?),
|
||||||
&((&&rinja::filters::AutoEscaper::new(&(blob), rinja::filters::Text))
|
&((&&askama::filters::AutoEscaper::new(&(blob), askama::filters::Text))
|
||||||
.rinja_auto_escape()?),
|
.askama_auto_escape()?),
|
||||||
) {
|
) {
|
||||||
(expr0, expr2) => {
|
(expr0, expr2) => {
|
||||||
(&&&rinja::filters::Writable(expr0)).rinja_write(__rinja_writer, __rinja_values)?;
|
(&&&askama::filters::Writable(expr0)).askama_write(__askama_writer, __askama_values)?;
|
||||||
__rinja_writer.write_str(" ")?;
|
__askama_writer.write_str(" ")?;
|
||||||
(&&&rinja::filters::Writable(expr2)).rinja_write(__rinja_writer, __rinja_values)?;
|
(&&&askama::filters::Writable(expr2)).askama_write(__askama_writer, __askama_values)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}"#,
|
}"#,
|
||||||
@ -260,19 +260,19 @@ fn check_if_let_chain() {
|
|||||||
&& let Some(z) = z
|
&& let Some(z) = z
|
||||||
&& z == "z" %}{{y}} {{z}}{% endif %}"#,
|
&& z == "z" %}{{y}} {{z}}{% endif %}"#,
|
||||||
r#"if let Some(y) = &self.y && self.y == "x"
|
r#"if let Some(y) = &self.y && self.y == "x"
|
||||||
&& rinja::helpers::as_bool(&(self.w)) && let Some(z) = &self.z
|
&& askama::helpers::as_bool(&(self.w)) && let Some(z) = &self.z
|
||||||
&& rinja::helpers::as_bool(&(z == "z"))
|
&& askama::helpers::as_bool(&(z == "z"))
|
||||||
{
|
{
|
||||||
match (
|
match (
|
||||||
&((&&rinja::filters::AutoEscaper::new(&(y), rinja::filters::Text))
|
&((&&askama::filters::AutoEscaper::new(&(y), askama::filters::Text))
|
||||||
.rinja_auto_escape()?),
|
.askama_auto_escape()?),
|
||||||
&((&&rinja::filters::AutoEscaper::new(&(z), rinja::filters::Text))
|
&((&&askama::filters::AutoEscaper::new(&(z), askama::filters::Text))
|
||||||
.rinja_auto_escape()?),
|
.askama_auto_escape()?),
|
||||||
) {
|
) {
|
||||||
(expr0, expr2) => {
|
(expr0, expr2) => {
|
||||||
(&&&rinja::filters::Writable(expr0)).rinja_write(__rinja_writer, __rinja_values)?;
|
(&&&askama::filters::Writable(expr0)).askama_write(__askama_writer, __askama_values)?;
|
||||||
__rinja_writer.write_str(" ")?;
|
__askama_writer.write_str(" ")?;
|
||||||
(&&&rinja::filters::Writable(expr2)).rinja_write(__rinja_writer, __rinja_values)?;
|
(&&&askama::filters::Writable(expr2)).askama_write(__askama_writer, __askama_values)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}"#,
|
}"#,
|
||||||
@ -286,20 +286,20 @@ fn check_if_let_chain() {
|
|||||||
&& y == "x"
|
&& y == "x"
|
||||||
&& let Some(z) = z
|
&& let Some(z) = z
|
||||||
&& z == "z" %}{{y}} {{z}}{% endif %}"#,
|
&& z == "z" %}{{y}} {{z}}{% endif %}"#,
|
||||||
r#"if rinja::helpers::as_bool(&(self.w)) && let Some(y) = &self.y
|
r#"if askama::helpers::as_bool(&(self.w)) && let Some(y) = &self.y
|
||||||
&& self.y == "x" && let Some(z) = &self.z
|
&& self.y == "x" && let Some(z) = &self.z
|
||||||
&& rinja::helpers::as_bool(&(z == "z"))
|
&& askama::helpers::as_bool(&(z == "z"))
|
||||||
{
|
{
|
||||||
match (
|
match (
|
||||||
&((&&rinja::filters::AutoEscaper::new(&(y), rinja::filters::Text))
|
&((&&askama::filters::AutoEscaper::new(&(y), askama::filters::Text))
|
||||||
.rinja_auto_escape()?),
|
.askama_auto_escape()?),
|
||||||
&((&&rinja::filters::AutoEscaper::new(&(z), rinja::filters::Text))
|
&((&&askama::filters::AutoEscaper::new(&(z), askama::filters::Text))
|
||||||
.rinja_auto_escape()?),
|
.askama_auto_escape()?),
|
||||||
) {
|
) {
|
||||||
(expr0, expr2) => {
|
(expr0, expr2) => {
|
||||||
(&&&rinja::filters::Writable(expr0)).rinja_write(__rinja_writer, __rinja_values)?;
|
(&&&askama::filters::Writable(expr0)).askama_write(__askama_writer, __askama_values)?;
|
||||||
__rinja_writer.write_str(" ")?;
|
__askama_writer.write_str(" ")?;
|
||||||
(&&&rinja::filters::Writable(expr2)).rinja_write(__rinja_writer, __rinja_values)?;
|
(&&&askama::filters::Writable(expr2)).askama_write(__askama_writer, __askama_values)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}"#,
|
}"#,
|
||||||
@ -318,10 +318,10 @@ fn check_includes_only_once() {
|
|||||||
compare(
|
compare(
|
||||||
r#"{% include "include1.html" %}"#,
|
r#"{% include "include1.html" %}"#,
|
||||||
&format!(
|
&format!(
|
||||||
r#"const _: &[rinja::helpers::core::primitive::u8] = rinja::helpers::core::include_bytes!({path1:#?});
|
r#"const _: &[askama::helpers::core::primitive::u8] = askama::helpers::core::include_bytes!({path1:#?});
|
||||||
const _: &[rinja::helpers::core::primitive::u8] = rinja::helpers::core::include_bytes!({path2:#?});
|
const _: &[askama::helpers::core::primitive::u8] = askama::helpers::core::include_bytes!({path2:#?});
|
||||||
const _: &[rinja::helpers::core::primitive::u8] = rinja::helpers::core::include_bytes!({path3:#?});
|
const _: &[askama::helpers::core::primitive::u8] = askama::helpers::core::include_bytes!({path3:#?});
|
||||||
__rinja_writer.write_str("3333")?;"#
|
__askama_writer.write_str("3333")?;"#
|
||||||
),
|
),
|
||||||
&[],
|
&[],
|
||||||
4,
|
4,
|
||||||
@ -335,19 +335,19 @@ fn check_is_defined() {
|
|||||||
// We're forced to add `bla` otherwise `compare` assert fails in weird ways...
|
// We're forced to add `bla` otherwise `compare` assert fails in weird ways...
|
||||||
compare(
|
compare(
|
||||||
"{% if y is defined %}{{query}}{% endif %}bla",
|
"{% if y is defined %}{{query}}{% endif %}bla",
|
||||||
r#"__rinja_writer.write_str("bla")?;"#,
|
r#"__askama_writer.write_str("bla")?;"#,
|
||||||
&[],
|
&[],
|
||||||
3,
|
3,
|
||||||
);
|
);
|
||||||
compare(
|
compare(
|
||||||
"{% if x is not defined %}{{query}}{% endif %}bla",
|
"{% if x is not defined %}{{query}}{% endif %}bla",
|
||||||
r#"__rinja_writer.write_str("bla")?;"#,
|
r#"__askama_writer.write_str("bla")?;"#,
|
||||||
&[("x", "u32")],
|
&[("x", "u32")],
|
||||||
3,
|
3,
|
||||||
);
|
);
|
||||||
compare(
|
compare(
|
||||||
"{% if y is defined && x is not defined %}{{query}}{% endif %}bla",
|
"{% if y is defined && x is not defined %}{{query}}{% endif %}bla",
|
||||||
r#"__rinja_writer.write_str("bla")?;"#,
|
r#"__askama_writer.write_str("bla")?;"#,
|
||||||
&[("x", "u32")],
|
&[("x", "u32")],
|
||||||
3,
|
3,
|
||||||
);
|
);
|
||||||
@ -357,7 +357,7 @@ fn check_is_defined() {
|
|||||||
"{% set y = 12 %}
|
"{% set y = 12 %}
|
||||||
{%- if y is not defined %}{{query}}{% endif %}bla",
|
{%- if y is not defined %}{{query}}{% endif %}bla",
|
||||||
r#"let y = 12;
|
r#"let y = 12;
|
||||||
__rinja_writer.write_str("bla")?;"#,
|
__askama_writer.write_str("bla")?;"#,
|
||||||
&[],
|
&[],
|
||||||
3,
|
3,
|
||||||
);
|
);
|
||||||
@ -365,7 +365,7 @@ __rinja_writer.write_str("bla")?;"#,
|
|||||||
"{% set y = 12 %}
|
"{% set y = 12 %}
|
||||||
{%- if y is not defined && x is defined %}{{query}}{% endif %}bla",
|
{%- if y is not defined && x is defined %}{{query}}{% endif %}bla",
|
||||||
r#"let y = 12;
|
r#"let y = 12;
|
||||||
__rinja_writer.write_str("bla")?;"#,
|
__askama_writer.write_str("bla")?;"#,
|
||||||
&[],
|
&[],
|
||||||
3,
|
3,
|
||||||
);
|
);
|
||||||
@ -374,13 +374,13 @@ __rinja_writer.write_str("bla")?;"#,
|
|||||||
// remove the condition.
|
// remove the condition.
|
||||||
compare(
|
compare(
|
||||||
"{% if y is defined %}bla{% endif %}",
|
"{% if y is defined %}bla{% endif %}",
|
||||||
r#"__rinja_writer.write_str("bla")?;"#,
|
r#"__askama_writer.write_str("bla")?;"#,
|
||||||
&[("y", "u32")],
|
&[("y", "u32")],
|
||||||
3,
|
3,
|
||||||
);
|
);
|
||||||
compare(
|
compare(
|
||||||
"{% if x is not defined %}bla{% endif %}",
|
"{% if x is not defined %}bla{% endif %}",
|
||||||
r#"__rinja_writer.write_str("bla")?;"#,
|
r#"__askama_writer.write_str("bla")?;"#,
|
||||||
&[],
|
&[],
|
||||||
3,
|
3,
|
||||||
);
|
);
|
||||||
@ -389,7 +389,7 @@ __rinja_writer.write_str("bla")?;"#,
|
|||||||
"{% set y = 12 %}
|
"{% set y = 12 %}
|
||||||
{%- if y is defined %}bla{% endif %}",
|
{%- if y is defined %}bla{% endif %}",
|
||||||
r#"let y = 12;
|
r#"let y = 12;
|
||||||
__rinja_writer.write_str("bla")?;"#,
|
__askama_writer.write_str("bla")?;"#,
|
||||||
&[],
|
&[],
|
||||||
3,
|
3,
|
||||||
);
|
);
|
||||||
@ -399,7 +399,7 @@ __rinja_writer.write_str("bla")?;"#,
|
|||||||
compare(
|
compare(
|
||||||
"{% if x is defined %}bli
|
"{% if x is defined %}bli
|
||||||
{%- else if x == 12 %}12{% endif %}bla",
|
{%- else if x == 12 %}12{% endif %}bla",
|
||||||
r#"__rinja_writer.write_str("blibla")?;"#,
|
r#"__askama_writer.write_str("blibla")?;"#,
|
||||||
&[("x", "u32")],
|
&[("x", "u32")],
|
||||||
6,
|
6,
|
||||||
);
|
);
|
||||||
@ -407,7 +407,7 @@ __rinja_writer.write_str("bla")?;"#,
|
|||||||
"{% if x is defined %}bli
|
"{% if x is defined %}bli
|
||||||
{%- else if x == 12 %}12
|
{%- else if x == 12 %}12
|
||||||
{%- else %}nope{% endif %}bla",
|
{%- else %}nope{% endif %}bla",
|
||||||
r#"__rinja_writer.write_str("blibla")?;"#,
|
r#"__askama_writer.write_str("blibla")?;"#,
|
||||||
&[("x", "u32")],
|
&[("x", "u32")],
|
||||||
6,
|
6,
|
||||||
);
|
);
|
||||||
@ -416,10 +416,10 @@ __rinja_writer.write_str("bla")?;"#,
|
|||||||
"{% if x == 12 %}bli
|
"{% if x == 12 %}bli
|
||||||
{%- else if x is defined %}12
|
{%- else if x is defined %}12
|
||||||
{%- else %}nope{% endif %}",
|
{%- else %}nope{% endif %}",
|
||||||
r#"if rinja::helpers::as_bool(&(self.x == 12)) {
|
r#"if askama::helpers::as_bool(&(self.x == 12)) {
|
||||||
__rinja_writer.write_str("bli")?;
|
__askama_writer.write_str("bli")?;
|
||||||
} else {
|
} else {
|
||||||
__rinja_writer.write_str("12")?;
|
__askama_writer.write_str("12")?;
|
||||||
}"#,
|
}"#,
|
||||||
&[("x", "u32")],
|
&[("x", "u32")],
|
||||||
5,
|
5,
|
||||||
@ -429,12 +429,12 @@ __rinja_writer.write_str("12")?;
|
|||||||
// are present.
|
// are present.
|
||||||
compare(
|
compare(
|
||||||
"{% if y is defined || x == 12 %}{{x}}{% endif %}",
|
"{% if y is defined || x == 12 %}{{x}}{% endif %}",
|
||||||
r"if rinja::helpers::as_bool(&(self.x == 12)) {
|
r"if askama::helpers::as_bool(&(self.x == 12)) {
|
||||||
match (
|
match (
|
||||||
&((&&rinja::filters::AutoEscaper::new(&(self.x), rinja::filters::Text)).rinja_auto_escape()?),
|
&((&&askama::filters::AutoEscaper::new(&(self.x), askama::filters::Text)).askama_auto_escape()?),
|
||||||
) {
|
) {
|
||||||
(expr0,) => {
|
(expr0,) => {
|
||||||
(&&&rinja::filters::Writable(expr0)).rinja_write(__rinja_writer, __rinja_values)?;
|
(&&&askama::filters::Writable(expr0)).askama_write(__askama_writer, __askama_values)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -445,10 +445,10 @@ __rinja_writer.write_str("12")?;
|
|||||||
compare(
|
compare(
|
||||||
"{% if y is defined || x == 12 %}{{x}}{% endif %}",
|
"{% if y is defined || x == 12 %}{{x}}{% endif %}",
|
||||||
r"match (
|
r"match (
|
||||||
&((&&rinja::filters::AutoEscaper::new(&(self.x), rinja::filters::Text)).rinja_auto_escape()?),
|
&((&&askama::filters::AutoEscaper::new(&(self.x), askama::filters::Text)).askama_auto_escape()?),
|
||||||
) {
|
) {
|
||||||
(expr0,) => {
|
(expr0,) => {
|
||||||
(&&&rinja::filters::Writable(expr0)).rinja_write(__rinja_writer, __rinja_values)?;
|
(&&&askama::filters::Writable(expr0)).askama_write(__askama_writer, __askama_values)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
",
|
",
|
||||||
@ -463,27 +463,27 @@ __rinja_writer.write_str("12")?;
|
|||||||
);
|
);
|
||||||
compare(
|
compare(
|
||||||
"{% if y is defined && y == 12 %}{{y}}{% else %}bli{% endif %}",
|
"{% if y is defined && y == 12 %}{{y}}{% else %}bli{% endif %}",
|
||||||
r#"__rinja_writer.write_str("bli")?;"#,
|
r#"__askama_writer.write_str("bli")?;"#,
|
||||||
&[],
|
&[],
|
||||||
3,
|
3,
|
||||||
);
|
);
|
||||||
compare(
|
compare(
|
||||||
"{% if y is defined && y == 12 %}{{y}}{% else %}bli{% endif %}",
|
"{% if y is defined && y == 12 %}{{y}}{% else %}bli{% endif %}",
|
||||||
r#"
|
r#"
|
||||||
if rinja::helpers::as_bool(&(self.y == 12)) {
|
if askama::helpers::as_bool(&(self.y == 12)) {
|
||||||
match (
|
match (
|
||||||
&((&&rinja::filters::AutoEscaper::new(
|
&((&&askama::filters::AutoEscaper::new(
|
||||||
&(self.y),
|
&(self.y),
|
||||||
rinja::filters::Text,
|
askama::filters::Text,
|
||||||
))
|
))
|
||||||
.rinja_auto_escape()?),
|
.askama_auto_escape()?),
|
||||||
) {
|
) {
|
||||||
(expr0,) => {
|
(expr0,) => {
|
||||||
(&&&rinja::filters::Writable(expr0)).rinja_write(__rinja_writer, __rinja_values)?;
|
(&&&askama::filters::Writable(expr0)).askama_write(__askama_writer, __askama_values)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
__rinja_writer.write_str("bli")?;
|
__askama_writer.write_str("bli")?;
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
&[("y", "u32")],
|
&[("y", "u32")],
|
||||||
@ -494,14 +494,14 @@ if rinja::helpers::as_bool(&(self.y == 12)) {
|
|||||||
"{% if y is defined %}{{y}}{% else %}bli{% endif %}",
|
"{% if y is defined %}{{y}}{% else %}bli{% endif %}",
|
||||||
r"
|
r"
|
||||||
match (
|
match (
|
||||||
&((&&rinja::filters::AutoEscaper::new(
|
&((&&askama::filters::AutoEscaper::new(
|
||||||
&(self.y),
|
&(self.y),
|
||||||
rinja::filters::Text,
|
askama::filters::Text,
|
||||||
))
|
))
|
||||||
.rinja_auto_escape()?),
|
.askama_auto_escape()?),
|
||||||
) {
|
) {
|
||||||
(expr0,) => {
|
(expr0,) => {
|
||||||
(&&&rinja::filters::Writable(expr0)).rinja_write(__rinja_writer, __rinja_values)?;
|
(&&&askama::filters::Writable(expr0)).askama_write(__askama_writer, __askama_values)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
",
|
",
|
||||||
@ -515,25 +515,25 @@ match (
|
|||||||
// to encounter cases like that in the wild so better have a check.
|
// to encounter cases like that in the wild so better have a check.
|
||||||
compare(
|
compare(
|
||||||
"{% if !(y is defined) %}bla{% endif %}",
|
"{% if !(y is defined) %}bla{% endif %}",
|
||||||
r#"__rinja_writer.write_str("bla")?;"#,
|
r#"__askama_writer.write_str("bla")?;"#,
|
||||||
&[],
|
&[],
|
||||||
3,
|
3,
|
||||||
);
|
);
|
||||||
compare(
|
compare(
|
||||||
"{% if !(y is not defined) %}bli{% endif %}bla",
|
"{% if !(y is not defined) %}bli{% endif %}bla",
|
||||||
r#"__rinja_writer.write_str("bla")?;"#,
|
r#"__askama_writer.write_str("bla")?;"#,
|
||||||
&[],
|
&[],
|
||||||
3,
|
3,
|
||||||
);
|
);
|
||||||
compare(
|
compare(
|
||||||
"{% if !(y is defined) %}bli{% endif %}bla",
|
"{% if !(y is defined) %}bli{% endif %}bla",
|
||||||
r#"__rinja_writer.write_str("bla")?;"#,
|
r#"__askama_writer.write_str("bla")?;"#,
|
||||||
&[("y", "u32")],
|
&[("y", "u32")],
|
||||||
3,
|
3,
|
||||||
);
|
);
|
||||||
compare(
|
compare(
|
||||||
"{% if !(y is not defined) %}bla{% endif %}",
|
"{% if !(y is not defined) %}bla{% endif %}",
|
||||||
r#"__rinja_writer.write_str("bla")?;"#,
|
r#"__askama_writer.write_str("bla")?;"#,
|
||||||
&[("y", "u32")],
|
&[("y", "u32")],
|
||||||
3,
|
3,
|
||||||
);
|
);
|
||||||
@ -541,32 +541,32 @@ match (
|
|||||||
// Ensure that the `!` is kept .
|
// Ensure that the `!` is kept .
|
||||||
compare(
|
compare(
|
||||||
"{% if y is defined && !y %}bla{% endif %}",
|
"{% if y is defined && !y %}bla{% endif %}",
|
||||||
r#"if !rinja::helpers::as_bool(&(self.y)) {
|
r#"if !askama::helpers::as_bool(&(self.y)) {
|
||||||
__rinja_writer.write_str("bla")?;
|
__askama_writer.write_str("bla")?;
|
||||||
}"#,
|
}"#,
|
||||||
&[("y", "bool")],
|
&[("y", "bool")],
|
||||||
3,
|
3,
|
||||||
);
|
);
|
||||||
compare(
|
compare(
|
||||||
"{% if y is defined && !(y) %}bla{% endif %}",
|
"{% if y is defined && !(y) %}bla{% endif %}",
|
||||||
r#"if !(rinja::helpers::as_bool(&(self.y))) {
|
r#"if !(askama::helpers::as_bool(&(self.y))) {
|
||||||
__rinja_writer.write_str("bla")?;
|
__askama_writer.write_str("bla")?;
|
||||||
}"#,
|
}"#,
|
||||||
&[("y", "bool")],
|
&[("y", "bool")],
|
||||||
3,
|
3,
|
||||||
);
|
);
|
||||||
compare(
|
compare(
|
||||||
"{% if y is not defined || !y %}bla{% endif %}",
|
"{% if y is not defined || !y %}bla{% endif %}",
|
||||||
r#"if !rinja::helpers::as_bool(&(self.y)) {
|
r#"if !askama::helpers::as_bool(&(self.y)) {
|
||||||
__rinja_writer.write_str("bla")?;
|
__askama_writer.write_str("bla")?;
|
||||||
}"#,
|
}"#,
|
||||||
&[("y", "bool")],
|
&[("y", "bool")],
|
||||||
3,
|
3,
|
||||||
);
|
);
|
||||||
compare(
|
compare(
|
||||||
"{% if y is not defined || !(y) %}bla{% endif %}",
|
"{% if y is not defined || !(y) %}bla{% endif %}",
|
||||||
r#"if !(rinja::helpers::as_bool(&(self.y))) {
|
r#"if !(askama::helpers::as_bool(&(self.y))) {
|
||||||
__rinja_writer.write_str("bla")?;
|
__askama_writer.write_str("bla")?;
|
||||||
}"#,
|
}"#,
|
||||||
&[("y", "bool")],
|
&[("y", "bool")],
|
||||||
3,
|
3,
|
||||||
@ -580,37 +580,37 @@ fn check_bool_conditions() {
|
|||||||
// We're forced to add `bla` otherwise `compare` assert fails in weird ways...
|
// We're forced to add `bla` otherwise `compare` assert fails in weird ways...
|
||||||
compare(
|
compare(
|
||||||
"{% if false %}{{query}}{% endif %}bla",
|
"{% if false %}{{query}}{% endif %}bla",
|
||||||
r#"__rinja_writer.write_str("bla")?;"#,
|
r#"__askama_writer.write_str("bla")?;"#,
|
||||||
&[],
|
&[],
|
||||||
3,
|
3,
|
||||||
);
|
);
|
||||||
compare(
|
compare(
|
||||||
"{% if false && false %}{{query}}{% endif %}bla",
|
"{% if false && false %}{{query}}{% endif %}bla",
|
||||||
r#"__rinja_writer.write_str("bla")?;"#,
|
r#"__askama_writer.write_str("bla")?;"#,
|
||||||
&[],
|
&[],
|
||||||
3,
|
3,
|
||||||
);
|
);
|
||||||
compare(
|
compare(
|
||||||
"{% if false && true %}{{query}}{% endif %}bla",
|
"{% if false && true %}{{query}}{% endif %}bla",
|
||||||
r#"__rinja_writer.write_str("bla")?;"#,
|
r#"__askama_writer.write_str("bla")?;"#,
|
||||||
&[],
|
&[],
|
||||||
3,
|
3,
|
||||||
);
|
);
|
||||||
compare(
|
compare(
|
||||||
"{% if true && false %}{{query}}{% endif %}bla",
|
"{% if true && false %}{{query}}{% endif %}bla",
|
||||||
r#"__rinja_writer.write_str("bla")?;"#,
|
r#"__askama_writer.write_str("bla")?;"#,
|
||||||
&[],
|
&[],
|
||||||
3,
|
3,
|
||||||
);
|
);
|
||||||
compare(
|
compare(
|
||||||
"{% if false || true %}bli{% endif %}bla",
|
"{% if false || true %}bli{% endif %}bla",
|
||||||
r#"__rinja_writer.write_str("blibla")?;"#,
|
r#"__askama_writer.write_str("blibla")?;"#,
|
||||||
&[],
|
&[],
|
||||||
6,
|
6,
|
||||||
);
|
);
|
||||||
compare(
|
compare(
|
||||||
"{% if true || false %}bli{% endif %}bla",
|
"{% if true || false %}bli{% endif %}bla",
|
||||||
r#"__rinja_writer.write_str("blibla")?;"#,
|
r#"__askama_writer.write_str("blibla")?;"#,
|
||||||
&[],
|
&[],
|
||||||
6,
|
6,
|
||||||
);
|
);
|
||||||
@ -618,10 +618,10 @@ fn check_bool_conditions() {
|
|||||||
compare(
|
compare(
|
||||||
"{% if true || x == 12 %}{{x}}{% endif %}",
|
"{% if true || x == 12 %}{{x}}{% endif %}",
|
||||||
r"match (
|
r"match (
|
||||||
&((&&rinja::filters::AutoEscaper::new(&(self.x), rinja::filters::Text)).rinja_auto_escape()?),
|
&((&&askama::filters::AutoEscaper::new(&(self.x), askama::filters::Text)).askama_auto_escape()?),
|
||||||
) {
|
) {
|
||||||
(expr0,) => {
|
(expr0,) => {
|
||||||
(&&&rinja::filters::Writable(expr0)).rinja_write(__rinja_writer, __rinja_values)?;
|
(&&&askama::filters::Writable(expr0)).askama_write(__askama_writer, __askama_values)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
",
|
",
|
||||||
@ -630,16 +630,16 @@ fn check_bool_conditions() {
|
|||||||
);
|
);
|
||||||
compare(
|
compare(
|
||||||
"{% if false || x == 12 %}{{x}}{% endif %}",
|
"{% if false || x == 12 %}{{x}}{% endif %}",
|
||||||
r"if rinja::helpers::as_bool(&(self.x == 12)) {
|
r"if askama::helpers::as_bool(&(self.x == 12)) {
|
||||||
match (
|
match (
|
||||||
&((&&rinja::filters::AutoEscaper::new(
|
&((&&askama::filters::AutoEscaper::new(
|
||||||
&(self.x),
|
&(self.x),
|
||||||
rinja::filters::Text,
|
askama::filters::Text,
|
||||||
))
|
))
|
||||||
.rinja_auto_escape()?),
|
.askama_auto_escape()?),
|
||||||
) {
|
) {
|
||||||
(expr0,) => {
|
(expr0,) => {
|
||||||
(&&&rinja::filters::Writable(expr0)).rinja_write(__rinja_writer, __rinja_values)?;
|
(&&&askama::filters::Writable(expr0)).askama_write(__askama_writer, __askama_values)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -654,16 +654,16 @@ fn check_bool_conditions() {
|
|||||||
// condition.
|
// condition.
|
||||||
compare(
|
compare(
|
||||||
"{% if y == 3 || (true || x == 12) %}{{x}}{% endif %}",
|
"{% if y == 3 || (true || x == 12) %}{{x}}{% endif %}",
|
||||||
r"if rinja::helpers::as_bool(&(self.y == 3)) || (true) {
|
r"if askama::helpers::as_bool(&(self.y == 3)) || (true) {
|
||||||
match (
|
match (
|
||||||
&((&&rinja::filters::AutoEscaper::new(
|
&((&&askama::filters::AutoEscaper::new(
|
||||||
&(self.x),
|
&(self.x),
|
||||||
rinja::filters::Text,
|
askama::filters::Text,
|
||||||
))
|
))
|
||||||
.rinja_auto_escape()?),
|
.askama_auto_escape()?),
|
||||||
) {
|
) {
|
||||||
(expr0,) => {
|
(expr0,) => {
|
||||||
(&&&rinja::filters::Writable(expr0)).rinja_write(__rinja_writer, __rinja_values)?;
|
(&&&askama::filters::Writable(expr0)).askama_write(__askama_writer, __askama_values)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -676,14 +676,14 @@ fn check_bool_conditions() {
|
|||||||
compare(
|
compare(
|
||||||
"{% if (true || x == 12) || y == 3 %}{{x}}{% endif %}",
|
"{% if (true || x == 12) || y == 3 %}{{x}}{% endif %}",
|
||||||
r"match (
|
r"match (
|
||||||
&((&&rinja::filters::AutoEscaper::new(
|
&((&&askama::filters::AutoEscaper::new(
|
||||||
&(self.x),
|
&(self.x),
|
||||||
rinja::filters::Text,
|
askama::filters::Text,
|
||||||
))
|
))
|
||||||
.rinja_auto_escape()?),
|
.askama_auto_escape()?),
|
||||||
) {
|
) {
|
||||||
(expr0,) => {
|
(expr0,) => {
|
||||||
(&&&rinja::filters::Writable(expr0)).rinja_write(__rinja_writer, __rinja_values)?;
|
(&&&askama::filters::Writable(expr0)).askama_write(__askama_writer, __askama_values)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
",
|
",
|
||||||
@ -693,18 +693,18 @@ fn check_bool_conditions() {
|
|||||||
compare(
|
compare(
|
||||||
"{% if y == 3 || (x == 12 || true) %}{{x}}{% endif %}",
|
"{% if y == 3 || (x == 12 || true) %}{{x}}{% endif %}",
|
||||||
r"
|
r"
|
||||||
if rinja::helpers::as_bool(&(self.y == 3))
|
if askama::helpers::as_bool(&(self.y == 3))
|
||||||
|| (rinja::helpers::as_bool(&(self.x == 12)) || true)
|
|| (askama::helpers::as_bool(&(self.x == 12)) || true)
|
||||||
{
|
{
|
||||||
match (
|
match (
|
||||||
&((&&rinja::filters::AutoEscaper::new(
|
&((&&askama::filters::AutoEscaper::new(
|
||||||
&(self.x),
|
&(self.x),
|
||||||
rinja::filters::Text,
|
askama::filters::Text,
|
||||||
))
|
))
|
||||||
.rinja_auto_escape()?),
|
.askama_auto_escape()?),
|
||||||
) {
|
) {
|
||||||
(expr0,) => {
|
(expr0,) => {
|
||||||
(&&&rinja::filters::Writable(expr0)).rinja_write(__rinja_writer, __rinja_values)?;
|
(&&&askama::filters::Writable(expr0)).askama_write(__askama_writer, __askama_values)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -716,13 +716,13 @@ if rinja::helpers::as_bool(&(self.y == 3))
|
|||||||
// Some funny cases.
|
// Some funny cases.
|
||||||
compare(
|
compare(
|
||||||
"{% if !(false) %}bla{% endif %}",
|
"{% if !(false) %}bla{% endif %}",
|
||||||
r#"__rinja_writer.write_str("bla")?;"#,
|
r#"__askama_writer.write_str("bla")?;"#,
|
||||||
&[],
|
&[],
|
||||||
3,
|
3,
|
||||||
);
|
);
|
||||||
compare(
|
compare(
|
||||||
"{% if !(true) %}{{query}}{% endif %}bla",
|
"{% if !(true) %}{{query}}{% endif %}bla",
|
||||||
r#"__rinja_writer.write_str("bla")?;"#,
|
r#"__askama_writer.write_str("bla")?;"#,
|
||||||
&[],
|
&[],
|
||||||
3,
|
3,
|
||||||
);
|
);
|
||||||
@ -732,13 +732,13 @@ if rinja::helpers::as_bool(&(self.y == 3))
|
|||||||
"{% if (a || !b) && !(c || !d) %}x{% endif %}",
|
"{% if (a || !b) && !(c || !d) %}x{% endif %}",
|
||||||
r#"
|
r#"
|
||||||
if (
|
if (
|
||||||
rinja::helpers::as_bool(&(self.a))
|
askama::helpers::as_bool(&(self.a))
|
||||||
|| !rinja::helpers::as_bool(&(self.b))
|
|| !askama::helpers::as_bool(&(self.b))
|
||||||
) && !(
|
) && !(
|
||||||
rinja::helpers::as_bool(&(self.c))
|
askama::helpers::as_bool(&(self.c))
|
||||||
|| !rinja::helpers::as_bool(&(self.d))
|
|| !askama::helpers::as_bool(&(self.d))
|
||||||
) {
|
) {
|
||||||
__rinja_writer.write_str("x")?;
|
__askama_writer.write_str("x")?;
|
||||||
}"#,
|
}"#,
|
||||||
&[("a", "i32"), ("b", "i32"), ("c", "i32"), ("d", "i32")],
|
&[("a", "i32"), ("b", "i32"), ("c", "i32"), ("d", "i32")],
|
||||||
1,
|
1,
|
||||||
@ -755,13 +755,13 @@ fn check_escaping_at_compile_time() {
|
|||||||
{%- when Suit::Diamonds or Suit::Hearts -%}
|
{%- when Suit::Diamonds or Suit::Hearts -%}
|
||||||
{{ " red" }}
|
{{ " red" }}
|
||||||
{%- endmatch %}"#,
|
{%- endmatch %}"#,
|
||||||
r#"__rinja_writer.write_str("The card is")?;
|
r#"__askama_writer.write_str("The card is")?;
|
||||||
match &self.suit {
|
match &self.suit {
|
||||||
Suit::Clubs {} | Suit::Spades {} => {
|
Suit::Clubs {} | Suit::Spades {} => {
|
||||||
__rinja_writer.write_str(" black")?;
|
__askama_writer.write_str(" black")?;
|
||||||
}
|
}
|
||||||
Suit::Diamonds {} | Suit::Hearts {} => {
|
Suit::Diamonds {} | Suit::Hearts {} => {
|
||||||
__rinja_writer.write_str(" red")?;
|
__askama_writer.write_str(" red")?;
|
||||||
}
|
}
|
||||||
}"#,
|
}"#,
|
||||||
&[("suit", "Suit")],
|
&[("suit", "Suit")],
|
||||||
@ -771,7 +771,7 @@ fn check_escaping_at_compile_time() {
|
|||||||
compare(
|
compare(
|
||||||
r#"{{ '\x41' }}{{ '\n' }}{{ '\r' }}{{ '\t' }}{{ '\\' }}{{ '\u{2665}' }}{{ '\'' }}{{ '\"' }}{{ '"' }}
|
r#"{{ '\x41' }}{{ '\n' }}{{ '\r' }}{{ '\t' }}{{ '\\' }}{{ '\u{2665}' }}{{ '\'' }}{{ '\"' }}{{ '"' }}
|
||||||
{{ "\x41\n\r\t\\\u{2665}\'\"'" }}"#,
|
{{ "\x41\n\r\t\\\u{2665}\'\"'" }}"#,
|
||||||
r#"__rinja_writer.write_str("A
|
r#"__askama_writer.write_str("A
|
||||||
\r \\♥'\"\"
|
\r \\♥'\"\"
|
||||||
A
|
A
|
||||||
\r \\♥'\"'")?;"#,
|
\r \\♥'\"'")?;"#,
|
||||||
@ -781,7 +781,7 @@ A
|
|||||||
|
|
||||||
compare(
|
compare(
|
||||||
r"{{ 1_2_3_4 }} {{ 4e3 }} {{ false }}",
|
r"{{ 1_2_3_4 }} {{ 4e3 }} {{ false }}",
|
||||||
r#"__rinja_writer.write_str("1234 4000 false")?;"#,
|
r#"__askama_writer.write_str("1234 4000 false")?;"#,
|
||||||
&[],
|
&[],
|
||||||
15,
|
15,
|
||||||
);
|
);
|
||||||
@ -792,7 +792,7 @@ A
|
|||||||
fn test_code_in_comment() {
|
fn test_code_in_comment() {
|
||||||
let ts = r#"
|
let ts = r#"
|
||||||
#[template(ext = "txt", in_doc = true)]
|
#[template(ext = "txt", in_doc = true)]
|
||||||
/// ```rinja
|
/// ```askama
|
||||||
/// Hello world!
|
/// Hello world!
|
||||||
/// ```
|
/// ```
|
||||||
struct Tmpl;
|
struct Tmpl;
|
||||||
@ -804,7 +804,7 @@ fn test_code_in_comment() {
|
|||||||
|
|
||||||
let ts = r#"
|
let ts = r#"
|
||||||
#[template(ext = "txt", in_doc = true)]
|
#[template(ext = "txt", in_doc = true)]
|
||||||
/// ```rinja
|
/// ```askama
|
||||||
/// Hello
|
/// Hello
|
||||||
/// world!
|
/// world!
|
||||||
/// ```
|
/// ```
|
||||||
@ -816,7 +816,7 @@ fn test_code_in_comment() {
|
|||||||
assert!(!generated.contains("compile_error"));
|
assert!(!generated.contains("compile_error"));
|
||||||
|
|
||||||
let ts = r#"
|
let ts = r#"
|
||||||
/// ```rinja
|
/// ```askama
|
||||||
/// Hello
|
/// Hello
|
||||||
#[template(ext = "txt", in_doc = true)]
|
#[template(ext = "txt", in_doc = true)]
|
||||||
/// world!
|
/// world!
|
||||||
@ -831,7 +831,7 @@ fn test_code_in_comment() {
|
|||||||
let ts = r#"
|
let ts = r#"
|
||||||
/// This template greets the whole world
|
/// This template greets the whole world
|
||||||
///
|
///
|
||||||
/// ```rinja
|
/// ```askama
|
||||||
/// Hello
|
/// Hello
|
||||||
#[template(ext = "txt", in_doc = true)]
|
#[template(ext = "txt", in_doc = true)]
|
||||||
/// world!
|
/// world!
|
||||||
@ -847,7 +847,7 @@ fn test_code_in_comment() {
|
|||||||
|
|
||||||
let ts = "
|
let ts = "
|
||||||
#[template(ext = \"txt\", in_doc = true)]
|
#[template(ext = \"txt\", in_doc = true)]
|
||||||
#[doc = \"```rinja\nHello\nworld!\n```\"]
|
#[doc = \"```askama\nHello\nworld!\n```\"]
|
||||||
struct Tmpl;
|
struct Tmpl;
|
||||||
";
|
";
|
||||||
let ast = syn::parse_str(ts).unwrap();
|
let ast = syn::parse_str(ts).unwrap();
|
||||||
@ -858,7 +858,7 @@ fn test_code_in_comment() {
|
|||||||
let ts = "
|
let ts = "
|
||||||
#[template(ext = \"txt\", in_doc = true)]
|
#[template(ext = \"txt\", in_doc = true)]
|
||||||
/// `````
|
/// `````
|
||||||
/// ```rinja
|
/// ```askama
|
||||||
/// {{bla}}
|
/// {{bla}}
|
||||||
/// ```
|
/// ```
|
||||||
/// `````
|
/// `````
|
||||||
@ -868,13 +868,13 @@ fn test_code_in_comment() {
|
|||||||
let err = build_template(&ast).unwrap_err();
|
let err = build_template(&ast).unwrap_err();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
err.to_string(),
|
err.to_string(),
|
||||||
"when using `in_doc` with the value `true`, the struct's documentation needs a `rinja` \
|
"when using `in_doc` with the value `true`, the struct's documentation needs a `askama` \
|
||||||
code block"
|
code block"
|
||||||
);
|
);
|
||||||
|
|
||||||
let ts = "
|
let ts = "
|
||||||
#[template(ext = \"txt\", in_doc = true)]
|
#[template(ext = \"txt\", in_doc = true)]
|
||||||
/// ```rinja
|
/// ```askama
|
||||||
/// `````
|
/// `````
|
||||||
/// {{bla}}
|
/// {{bla}}
|
||||||
/// `````
|
/// `````
|
||||||
@ -892,21 +892,21 @@ fn test_pluralize() {
|
|||||||
r"{{dogs}} dog{{dogs|pluralize}}",
|
r"{{dogs}} dog{{dogs|pluralize}}",
|
||||||
r#"
|
r#"
|
||||||
match (
|
match (
|
||||||
&((&&rinja::filters::AutoEscaper::new(
|
&((&&askama::filters::AutoEscaper::new(
|
||||||
&(self.dogs),
|
&(self.dogs),
|
||||||
rinja::filters::Text,
|
askama::filters::Text,
|
||||||
))
|
))
|
||||||
.rinja_auto_escape()?),
|
.askama_auto_escape()?),
|
||||||
&(rinja::filters::pluralize(
|
&(askama::filters::pluralize(
|
||||||
&(self.dogs),
|
&(self.dogs),
|
||||||
rinja::helpers::Empty,
|
askama::helpers::Empty,
|
||||||
rinja::filters::Safe("s"),
|
askama::filters::Safe("s"),
|
||||||
)?),
|
)?),
|
||||||
) {
|
) {
|
||||||
(expr0, expr3) => {
|
(expr0, expr3) => {
|
||||||
(&&&rinja::filters::Writable(expr0)).rinja_write(__rinja_writer, __rinja_values)?;
|
(&&&askama::filters::Writable(expr0)).askama_write(__askama_writer, __askama_values)?;
|
||||||
__rinja_writer.write_str(" dog")?;
|
__askama_writer.write_str(" dog")?;
|
||||||
(&&&rinja::filters::Writable(expr3)).rinja_write(__rinja_writer, __rinja_values)?;
|
(&&&askama::filters::Writable(expr3)).askama_write(__askama_writer, __askama_values)?;
|
||||||
}
|
}
|
||||||
}"#,
|
}"#,
|
||||||
&[("dogs", "i8")],
|
&[("dogs", "i8")],
|
||||||
@ -916,21 +916,21 @@ fn test_pluralize() {
|
|||||||
r#"{{dogs}} dog{{dogs|pluralize("go")}}"#,
|
r#"{{dogs}} dog{{dogs|pluralize("go")}}"#,
|
||||||
r#"
|
r#"
|
||||||
match (
|
match (
|
||||||
&((&&rinja::filters::AutoEscaper::new(
|
&((&&askama::filters::AutoEscaper::new(
|
||||||
&(self.dogs),
|
&(self.dogs),
|
||||||
rinja::filters::Text,
|
askama::filters::Text,
|
||||||
))
|
))
|
||||||
.rinja_auto_escape()?),
|
.askama_auto_escape()?),
|
||||||
&(rinja::filters::pluralize(
|
&(askama::filters::pluralize(
|
||||||
&(self.dogs),
|
&(self.dogs),
|
||||||
rinja::filters::Safe("go"),
|
askama::filters::Safe("go"),
|
||||||
rinja::filters::Safe("s"),
|
askama::filters::Safe("s"),
|
||||||
)?),
|
)?),
|
||||||
) {
|
) {
|
||||||
(expr0, expr3) => {
|
(expr0, expr3) => {
|
||||||
(&&&rinja::filters::Writable(expr0)).rinja_write(__rinja_writer, __rinja_values)?;
|
(&&&askama::filters::Writable(expr0)).askama_write(__askama_writer, __askama_values)?;
|
||||||
__rinja_writer.write_str(" dog")?;
|
__askama_writer.write_str(" dog")?;
|
||||||
(&&&rinja::filters::Writable(expr3)).rinja_write(__rinja_writer, __rinja_values)?;
|
(&&&askama::filters::Writable(expr3)).askama_write(__askama_writer, __askama_values)?;
|
||||||
}
|
}
|
||||||
}"#,
|
}"#,
|
||||||
&[("dogs", "i8")],
|
&[("dogs", "i8")],
|
||||||
@ -940,21 +940,21 @@ fn test_pluralize() {
|
|||||||
r#"{{mice}} {{mice|pluralize("mouse", "mice")}}"#,
|
r#"{{mice}} {{mice|pluralize("mouse", "mice")}}"#,
|
||||||
r#"
|
r#"
|
||||||
match (
|
match (
|
||||||
&((&&rinja::filters::AutoEscaper::new(
|
&((&&askama::filters::AutoEscaper::new(
|
||||||
&(self.mice),
|
&(self.mice),
|
||||||
rinja::filters::Text,
|
askama::filters::Text,
|
||||||
))
|
))
|
||||||
.rinja_auto_escape()?),
|
.askama_auto_escape()?),
|
||||||
&(rinja::filters::pluralize(
|
&(askama::filters::pluralize(
|
||||||
&(self.mice),
|
&(self.mice),
|
||||||
rinja::filters::Safe("mouse"),
|
askama::filters::Safe("mouse"),
|
||||||
rinja::filters::Safe("mice"),
|
askama::filters::Safe("mice"),
|
||||||
)?),
|
)?),
|
||||||
) {
|
) {
|
||||||
(expr0, expr2) => {
|
(expr0, expr2) => {
|
||||||
(&&&rinja::filters::Writable(expr0)).rinja_write(__rinja_writer, __rinja_values)?;
|
(&&&askama::filters::Writable(expr0)).askama_write(__askama_writer, __askama_values)?;
|
||||||
__rinja_writer.write_str(" ")?;
|
__askama_writer.write_str(" ")?;
|
||||||
(&&&rinja::filters::Writable(expr2)).rinja_write(__rinja_writer, __rinja_values)?;
|
(&&&askama::filters::Writable(expr2)).askama_write(__askama_writer, __askama_values)?;
|
||||||
}
|
}
|
||||||
}"#,
|
}"#,
|
||||||
&[("dogs", "i8")],
|
&[("dogs", "i8")],
|
||||||
@ -965,22 +965,22 @@ fn test_pluralize() {
|
|||||||
r"{{count|pluralize(one, count)}}",
|
r"{{count|pluralize(one, count)}}",
|
||||||
r"
|
r"
|
||||||
match (
|
match (
|
||||||
&(rinja::filters::pluralize(
|
&(askama::filters::pluralize(
|
||||||
&(self.count),
|
&(self.count),
|
||||||
(&&rinja::filters::AutoEscaper::new(
|
(&&askama::filters::AutoEscaper::new(
|
||||||
&(self.one),
|
&(self.one),
|
||||||
rinja::filters::Text,
|
askama::filters::Text,
|
||||||
))
|
))
|
||||||
.rinja_auto_escape()?,
|
.askama_auto_escape()?,
|
||||||
(&&rinja::filters::AutoEscaper::new(
|
(&&askama::filters::AutoEscaper::new(
|
||||||
&(self.count),
|
&(self.count),
|
||||||
rinja::filters::Text,
|
askama::filters::Text,
|
||||||
))
|
))
|
||||||
.rinja_auto_escape()?,
|
.askama_auto_escape()?,
|
||||||
)?),
|
)?),
|
||||||
) {
|
) {
|
||||||
(expr0,) => {
|
(expr0,) => {
|
||||||
(&&&rinja::filters::Writable(expr0)).rinja_write(__rinja_writer, __rinja_values)?;
|
(&&&askama::filters::Writable(expr0)).askama_write(__askama_writer, __askama_values)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
",
|
",
|
||||||
@ -992,11 +992,11 @@ fn test_pluralize() {
|
|||||||
r"{{0|pluralize(sg, pl)}}",
|
r"{{0|pluralize(sg, pl)}}",
|
||||||
r"
|
r"
|
||||||
match (
|
match (
|
||||||
&((&&rinja::filters::AutoEscaper::new(&(self.pl), rinja::filters::Text))
|
&((&&askama::filters::AutoEscaper::new(&(self.pl), askama::filters::Text))
|
||||||
.rinja_auto_escape()?),
|
.askama_auto_escape()?),
|
||||||
) {
|
) {
|
||||||
(expr0,) => {
|
(expr0,) => {
|
||||||
(&&&rinja::filters::Writable(expr0)).rinja_write(__rinja_writer, __rinja_values)?;
|
(&&&askama::filters::Writable(expr0)).askama_write(__askama_writer, __askama_values)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
",
|
",
|
||||||
@ -1007,11 +1007,11 @@ fn test_pluralize() {
|
|||||||
r"{{1|pluralize(sg, pl)}}",
|
r"{{1|pluralize(sg, pl)}}",
|
||||||
r"
|
r"
|
||||||
match (
|
match (
|
||||||
&((&&rinja::filters::AutoEscaper::new(&(self.sg), rinja::filters::Text))
|
&((&&askama::filters::AutoEscaper::new(&(self.sg), askama::filters::Text))
|
||||||
.rinja_auto_escape()?),
|
.askama_auto_escape()?),
|
||||||
) {
|
) {
|
||||||
(expr0,) => {
|
(expr0,) => {
|
||||||
(&&&rinja::filters::Writable(expr0)).rinja_write(__rinja_writer, __rinja_values)?;
|
(&&&askama::filters::Writable(expr0)).askama_write(__askama_writer, __askama_values)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
",
|
",
|
||||||
@ -1022,9 +1022,9 @@ fn test_pluralize() {
|
|||||||
compare(
|
compare(
|
||||||
r#"{{0|pluralize("sg", "pl")}}"#,
|
r#"{{0|pluralize("sg", "pl")}}"#,
|
||||||
r#"
|
r#"
|
||||||
match (&(rinja::filters::Safe("pl")),) {
|
match (&(askama::filters::Safe("pl")),) {
|
||||||
(expr0,) => {
|
(expr0,) => {
|
||||||
(&&&rinja::filters::Writable(expr0)).rinja_write(__rinja_writer, __rinja_values)?;
|
(&&&askama::filters::Writable(expr0)).askama_write(__askama_writer, __askama_values)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
@ -1034,9 +1034,9 @@ fn test_pluralize() {
|
|||||||
compare(
|
compare(
|
||||||
r#"{{1|pluralize("sg", "pl")}}"#,
|
r#"{{1|pluralize("sg", "pl")}}"#,
|
||||||
r#"
|
r#"
|
||||||
match (&(rinja::filters::Safe("sg")),) {
|
match (&(askama::filters::Safe("sg")),) {
|
||||||
(expr0,) => {
|
(expr0,) => {
|
||||||
(&&&rinja::filters::Writable(expr0)).rinja_write(__rinja_writer, __rinja_values)?;
|
(&&&askama::filters::Writable(expr0)).askama_write(__askama_writer, __askama_values)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
@ -1047,9 +1047,9 @@ fn test_pluralize() {
|
|||||||
compare(
|
compare(
|
||||||
r"{{0|pluralize}}",
|
r"{{0|pluralize}}",
|
||||||
r#"
|
r#"
|
||||||
match (&(rinja::filters::Safe("s")),) {
|
match (&(askama::filters::Safe("s")),) {
|
||||||
(expr0,) => {
|
(expr0,) => {
|
||||||
(&&&rinja::filters::Writable(expr0)).rinja_write(__rinja_writer, __rinja_values)?;
|
(&&&askama::filters::Writable(expr0)).askama_write(__askama_writer, __askama_values)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
@ -1059,9 +1059,9 @@ fn test_pluralize() {
|
|||||||
compare(
|
compare(
|
||||||
r"{{1|pluralize}}",
|
r"{{1|pluralize}}",
|
||||||
r"
|
r"
|
||||||
match (&(rinja::helpers::Empty),) {
|
match (&(askama::helpers::Empty),) {
|
||||||
(expr0,) => {
|
(expr0,) => {
|
||||||
(&&&rinja::filters::Writable(expr0)).rinja_write(__rinja_writer, __rinja_values)?;
|
(&&&askama::filters::Writable(expr0)).askama_write(__askama_writer, __askama_values)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
",
|
",
|
||||||
@ -1075,20 +1075,20 @@ fn test_concat() {
|
|||||||
compare(
|
compare(
|
||||||
r#"{{ "<" ~ a ~ "|" ~ b ~ '>' }}"#,
|
r#"{{ "<" ~ a ~ "|" ~ b ~ '>' }}"#,
|
||||||
r#"
|
r#"
|
||||||
__rinja_writer.write_str("<")?;
|
__askama_writer.write_str("<")?;
|
||||||
match (
|
match (
|
||||||
&((&&rinja::filters::AutoEscaper::new(&(self.a), rinja::filters::Text))
|
&((&&askama::filters::AutoEscaper::new(&(self.a), askama::filters::Text))
|
||||||
.rinja_auto_escape()?),
|
.askama_auto_escape()?),
|
||||||
&((&&rinja::filters::AutoEscaper::new(&(self.b), rinja::filters::Text))
|
&((&&askama::filters::AutoEscaper::new(&(self.b), askama::filters::Text))
|
||||||
.rinja_auto_escape()?),
|
.askama_auto_escape()?),
|
||||||
) {
|
) {
|
||||||
(expr1, expr3) => {
|
(expr1, expr3) => {
|
||||||
(&&&rinja::filters::Writable(expr1)).rinja_write(__rinja_writer, __rinja_values)?;
|
(&&&askama::filters::Writable(expr1)).askama_write(__askama_writer, __askama_values)?;
|
||||||
__rinja_writer.write_str("|")?;
|
__askama_writer.write_str("|")?;
|
||||||
(&&&rinja::filters::Writable(expr3)).rinja_write(__rinja_writer, __rinja_values)?;
|
(&&&askama::filters::Writable(expr3)).askama_write(__askama_writer, __askama_values)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
__rinja_writer.write_str(">")?;
|
__askama_writer.write_str(">")?;
|
||||||
"#,
|
"#,
|
||||||
&[("a", "&'static str"), ("b", "u32")],
|
&[("a", "&'static str"), ("b", "u32")],
|
||||||
9,
|
9,
|
||||||
@ -1098,19 +1098,19 @@ fn test_concat() {
|
|||||||
r#"{{ ("a=" ~ a ~ " b=" ~ b)|upper }}"#,
|
r#"{{ ("a=" ~ a ~ " b=" ~ b)|upper }}"#,
|
||||||
r#"
|
r#"
|
||||||
match (
|
match (
|
||||||
&((&&rinja::filters::AutoEscaper::new(
|
&((&&askama::filters::AutoEscaper::new(
|
||||||
&(rinja::filters::upper(
|
&(askama::filters::upper(
|
||||||
&((rinja::helpers::Concat(
|
&((askama::helpers::Concat(
|
||||||
&(rinja::helpers::Concat(&("a="), &(self.a))),
|
&(askama::helpers::Concat(&("a="), &(self.a))),
|
||||||
&(rinja::helpers::Concat(&(" b="), &(self.b))),
|
&(askama::helpers::Concat(&(" b="), &(self.b))),
|
||||||
))),
|
))),
|
||||||
)?),
|
)?),
|
||||||
rinja::filters::Text,
|
askama::filters::Text,
|
||||||
))
|
))
|
||||||
.rinja_auto_escape()?),
|
.askama_auto_escape()?),
|
||||||
) {
|
) {
|
||||||
(expr0,) => {
|
(expr0,) => {
|
||||||
(&&&rinja::filters::Writable(expr0)).rinja_write(__rinja_writer, __rinja_values)?;
|
(&&&askama::filters::Writable(expr0)).askama_write(__askama_writer, __askama_values)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
@ -1,10 +1,9 @@
|
|||||||
|
|
||||||
[package]
|
[package]
|
||||||
name = "rinja_derive_standalone"
|
name = "askama_derive_standalone"
|
||||||
version = "0.3.5"
|
version = "0.3.5"
|
||||||
description = "Procedural macro package for Rinja"
|
description = "Procedural macro package for Askama"
|
||||||
homepage = "https://github.com/rinja-rs/rinja"
|
homepage = "https://github.com/askama-rs/askama"
|
||||||
repository = "https://github.com/rinja-rs/rinja"
|
repository = "https://github.com/askama-rs/askama"
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
@ -21,7 +20,7 @@ harness = false
|
|||||||
required-features = ["__standalone"]
|
required-features = ["__standalone"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
parser = { package = "rinja_parser", version = "=0.3.5", path = "../rinja_parser" }
|
parser = { package = "askama_parser", version = "=0.3.5", 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.12.0", optional = true, default-features = false }
|
||||||
@ -33,7 +32,7 @@ quote = { version = "1", default-features = false }
|
|||||||
rustc-hash = "2.0.0"
|
rustc-hash = "2.0.0"
|
||||||
syn = { version = "2.0.3", default-features = false, features = ["clone-impls", "derive", "parsing", "printing"] }
|
syn = { version = "2.0.3", default-features = false, features = ["clone-impls", "derive", "parsing", "printing"] }
|
||||||
|
|
||||||
# in `rinja_derive_standalone` we opt out of the default features, because we need no native `proc-macro` support
|
# in `askama_derive_standalone` we opt out of the default features, because we need no native `proc-macro` support
|
||||||
proc-macro2 = { version = "1", default-features = false }
|
proc-macro2 = { version = "1", default-features = false }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
@ -57,7 +56,7 @@ std = ["alloc"]
|
|||||||
urlencode = []
|
urlencode = []
|
||||||
|
|
||||||
[lints.rust]
|
[lints.rust]
|
||||||
# Used in `rinja_derive` which uses the same source folder, but is a proc-macro.
|
# Used in `askama_derive` which uses the same source folder, but is a proc-macro.
|
||||||
unexpected_cfgs = { level = "allow", check-cfg = ['cfg(feature, values("alloc"))'] }
|
unexpected_cfgs = { level = "allow", check-cfg = ['cfg(feature, values("alloc"))'] }
|
||||||
|
|
||||||
[workspace]
|
[workspace]
|
5
askama_derive_standalone/README.md
Normal file
5
askama_derive_standalone/README.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
This crate embeds the source of `askama_derive`, but is not a `proc_macro`.
|
||||||
|
This way we can more easily access the internals of the crate.
|
||||||
|
|
||||||
|
To run the benchmark, execute `cargo bench` in this folder, or
|
||||||
|
`cargo bench -p askama_derive_standalone` in the project root.
|
@ -18,7 +18,7 @@ fn hello_world(c: &mut Criterion) {
|
|||||||
c.bench_function("hello_world", |b| {
|
c.bench_function("hello_world", |b| {
|
||||||
b.iter_batched(
|
b.iter_batched(
|
||||||
|| ts.clone(),
|
|| ts.clone(),
|
||||||
rinja_derive_standalone::derive_template,
|
askama_derive_standalone::derive_template,
|
||||||
BatchSize::LargeInput,
|
BatchSize::LargeInput,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -28,7 +28,7 @@ fn librustdoc(c: &mut Criterion) {
|
|||||||
macro_rules! benches {
|
macro_rules! benches {
|
||||||
($($name:expr => $struct:item)*) => { $({
|
($($name:expr => $struct:item)*) => { $({
|
||||||
const SOURCE: &str =
|
const SOURCE: &str =
|
||||||
include_str!(concat!("../../rinja_parser/benches/librustdoc/", $name));
|
include_str!(concat!("../../askama_parser/benches/librustdoc/", $name));
|
||||||
|
|
||||||
let ts = quote! {
|
let ts = quote! {
|
||||||
#[derive(Template)]
|
#[derive(Template)]
|
||||||
@ -38,7 +38,7 @@ fn librustdoc(c: &mut Criterion) {
|
|||||||
c.bench_function($name, |b| {
|
c.bench_function($name, |b| {
|
||||||
b.iter_batched(
|
b.iter_batched(
|
||||||
|| ts.clone(),
|
|| ts.clone(),
|
||||||
rinja_derive_standalone::derive_template,
|
askama_derive_standalone::derive_template,
|
||||||
BatchSize::LargeInput,
|
BatchSize::LargeInput,
|
||||||
)
|
)
|
||||||
});
|
});
|
1
askama_derive_standalone/src
Symbolic link
1
askama_derive_standalone/src
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../askama_derive/src/
|
1
askama_derive_standalone/templates
Symbolic link
1
askama_derive_standalone/templates
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../askama_derive/templates/
|
@ -1,12 +1,12 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "rinja_parser"
|
name = "askama_parser"
|
||||||
version = "0.3.5"
|
version = "0.3.5"
|
||||||
description = "Parser for Rinja templates"
|
description = "Parser for Askama templates"
|
||||||
documentation = "https://docs.rs/rinja"
|
documentation = "https://docs.rs/askama"
|
||||||
keywords = ["markup", "template", "jinja2", "html"]
|
keywords = ["markup", "template", "jinja2", "html"]
|
||||||
categories = ["template-engine"]
|
categories = ["template-engine"]
|
||||||
homepage = "https://github.com/rinja-rs/rinja"
|
homepage = "https://github.com/askama-rs/askama"
|
||||||
repository = "https://github.com/rinja-rs/rinja"
|
repository = "https://github.com/askama-rs/askama"
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
edition = "2021"
|
edition = "2021"
|
9
askama_parser/README.md
Normal file
9
askama_parser/README.md
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
# askama_parser: template parser for the Askama templating engine
|
||||||
|
|
||||||
|
[](https://crates.io/crates/askama_parser)
|
||||||
|
[](https://github.com/askama-rs/askama/actions/workflows/rust.yml)
|
||||||
|
[](https://askama.readthedocs.io/)
|
||||||
|
[](https://docs.rs/askama_parser/)
|
||||||
|
|
||||||
|
This crate contains the procedural macros used by the
|
||||||
|
[Askama](https://github.com/askama-rs/askama) templating engine.
|
@ -1,5 +1,5 @@
|
|||||||
|
use askama_parser::{Ast, Syntax};
|
||||||
use criterion::{Criterion, Throughput, black_box, criterion_group, criterion_main};
|
use criterion::{Criterion, Throughput, black_box, criterion_group, criterion_main};
|
||||||
use rinja_parser::{Ast, Syntax};
|
|
||||||
|
|
||||||
criterion_main!(benches);
|
criterion_main!(benches);
|
||||||
criterion_group!(benches, librustdoc);
|
criterion_group!(benches, librustdoc);
|
1
askama_parser/src/ascii_str.rs
Symbolic link
1
askama_parser/src/ascii_str.rs
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../../askama/src/ascii_str.rs
|
@ -537,7 +537,7 @@ fn token_xor<'a>(i: &mut &'a str) -> ParseResult<'a> {
|
|||||||
Ok("^")
|
Ok("^")
|
||||||
} else {
|
} else {
|
||||||
Err(winnow::error::ErrMode::Cut(ErrorContext::new(
|
Err(winnow::error::ErrMode::Cut(ErrorContext::new(
|
||||||
"the binary XOR operator is called `xor` in rinja",
|
"the binary XOR operator is called `xor` in askama",
|
||||||
*i,
|
*i,
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
@ -549,7 +549,7 @@ fn token_bitand<'a>(i: &mut &'a str) -> ParseResult<'a> {
|
|||||||
Ok("&")
|
Ok("&")
|
||||||
} else {
|
} else {
|
||||||
Err(winnow::error::ErrMode::Cut(ErrorContext::new(
|
Err(winnow::error::ErrMode::Cut(ErrorContext::new(
|
||||||
"the binary AND operator is called `bitand` in rinja",
|
"the binary AND operator is called `bitand` in askama",
|
||||||
*i,
|
*i,
|
||||||
)))
|
)))
|
||||||
}
|
}
|
@ -292,7 +292,7 @@ pub(crate) type ParseResult<'a, T = &'a str> = Result<T, ParseErr<'a>>;
|
|||||||
/// It used to generate `ParserError`.
|
/// It used to generate `ParserError`.
|
||||||
///
|
///
|
||||||
/// It cannot be used to replace `ParseError` because it expects a generic, which would make
|
/// It cannot be used to replace `ParseError` because it expects a generic, which would make
|
||||||
/// `rinja`'s users experience less good (since this generic is only needed for `nom`).
|
/// `askama`'s users experience less good (since this generic is only needed for `nom`).
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) struct ErrorContext<'a> {
|
pub(crate) struct ErrorContext<'a> {
|
||||||
pub(crate) span: Span<'a>,
|
pub(crate) span: Span<'a>,
|
@ -61,7 +61,7 @@ impl<'a> Node<'a> {
|
|||||||
return Err(winnow::error::ErrMode::Cut(ErrorContext::new(
|
return Err(winnow::error::ErrMode::Cut(ErrorContext::new(
|
||||||
"cannot parse entire template\n\
|
"cannot parse entire template\n\
|
||||||
you should never encounter this error\n\
|
you should never encounter this error\n\
|
||||||
please report this error to <https://github.com/rinja-rs/rinja/issues>",
|
please report this error to <https://github.com/askama-rs/askama/issues>",
|
||||||
*i,
|
*i,
|
||||||
)));
|
)));
|
||||||
}
|
}
|
@ -204,9 +204,9 @@ fn verify_name<'a>(
|
|||||||
format!("cannot use `{name}` as a name: it is a rust keyword"),
|
format!("cannot use `{name}` as a name: it is a rust keyword"),
|
||||||
input,
|
input,
|
||||||
)))
|
)))
|
||||||
} else if name.starts_with("__rinja") {
|
} else if name.starts_with("__askama") {
|
||||||
Err(winnow::error::ErrMode::Cut(ErrorContext::new(
|
Err(winnow::error::ErrMode::Cut(ErrorContext::new(
|
||||||
format!("cannot use `{name}` as a name: it is reserved for `rinja`"),
|
format!("cannot use `{name}` as a name: it is reserved for `askama`"),
|
||||||
input,
|
input,
|
||||||
)))
|
)))
|
||||||
} else {
|
} else {
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user