mirror of
https://github.com/askama-rs/askama.git
synced 2025-09-30 14:31:36 +00:00
Add MsgValidEscapers
to show list of configured escapers
This commit is contained in:
parent
6b0ea27742
commit
9beca5ed10
@ -15,7 +15,7 @@ use quote::quote;
|
|||||||
use crate::config::WhitespaceHandling;
|
use crate::config::WhitespaceHandling;
|
||||||
use crate::heritage::{Context, Heritage};
|
use crate::heritage::{Context, Heritage};
|
||||||
use crate::input::{Source, TemplateInput};
|
use crate::input::{Source, TemplateInput};
|
||||||
use crate::{CompileError, CRATE};
|
use crate::{CompileError, MsgValidEscapers, CRATE};
|
||||||
|
|
||||||
pub(crate) struct Generator<'a> {
|
pub(crate) struct Generator<'a> {
|
||||||
// The template input state: original struct AST and attributes
|
// The template input state: original struct AST and attributes
|
||||||
@ -1429,7 +1429,10 @@ impl<'a> Generator<'a> {
|
|||||||
})
|
})
|
||||||
.ok_or_else(|| {
|
.ok_or_else(|| {
|
||||||
ctx.generate_error(
|
ctx.generate_error(
|
||||||
&format!("invalid escaper '{name}' for `escape` filter"),
|
&format!(
|
||||||
|
"invalid escaper '{name}' for `escape` filter. {}",
|
||||||
|
MsgValidEscapers(&self.input.config.escapers),
|
||||||
|
),
|
||||||
node,
|
node,
|
||||||
)
|
)
|
||||||
})?,
|
})?,
|
||||||
|
@ -10,7 +10,7 @@ use quote::ToTokens;
|
|||||||
use syn::punctuated::Punctuated;
|
use syn::punctuated::Punctuated;
|
||||||
|
|
||||||
use crate::config::{get_template_source, Config};
|
use crate::config::{get_template_source, Config};
|
||||||
use crate::CompileError;
|
use crate::{CompileError, MsgValidEscapers};
|
||||||
|
|
||||||
pub(crate) struct TemplateInput<'a> {
|
pub(crate) struct TemplateInput<'a> {
|
||||||
pub(crate) ast: &'a syn::DeriveInput,
|
pub(crate) ast: &'a syn::DeriveInput,
|
||||||
@ -87,7 +87,10 @@ impl TemplateInput<'_> {
|
|||||||
.then_some(path.as_ref())
|
.then_some(path.as_ref())
|
||||||
})
|
})
|
||||||
.ok_or_else(|| {
|
.ok_or_else(|| {
|
||||||
CompileError::no_file_info(format!("no escaper defined for extension '{escaping}'"))
|
CompileError::no_file_info(format!(
|
||||||
|
"no escaper defined for extension '{escaping}'. {}",
|
||||||
|
MsgValidEscapers(&config.escapers),
|
||||||
|
))
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let mime_type =
|
let mime_type =
|
||||||
|
@ -8,6 +8,7 @@ mod input;
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests;
|
mod tests;
|
||||||
|
|
||||||
|
use std::borrow::Cow;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
@ -231,6 +232,21 @@ impl fmt::Display for FileInfo<'_> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct MsgValidEscapers<'a>(&'a [(Vec<Cow<'a, str>>, Cow<'a, str>)]);
|
||||||
|
|
||||||
|
impl fmt::Display for MsgValidEscapers<'_> {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
let mut exts = self
|
||||||
|
.0
|
||||||
|
.iter()
|
||||||
|
.flat_map(|(exts, _)| exts)
|
||||||
|
.map(|x| format!("{x:?}"))
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
exts.sort();
|
||||||
|
write!(f, "The available extensions are: {}", exts.join(", "))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 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. It should contain all the
|
// Rinja or should refer to a local `filters` module. It should contain all the
|
||||||
// filters shipped with Rinja, even the optional ones (since optional inclusion
|
// filters shipped with Rinja, even the optional ones (since optional inclusion
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
error: invalid escaper 'latex' for `escape` filter
|
error: invalid escaper 'latex' for `escape` filter. The available extensions are: "", "htm", "html", "j2", "jinja", "jinja2", "md", "none", "svg", "txt", "xml", "yml"
|
||||||
--> LocalEscaper.html:1:38
|
--> LocalEscaper.html:1:38
|
||||||
"text|escape(\"latex\")}}`."
|
"text|escape(\"latex\")}}`."
|
||||||
--> tests/ui/no-such-escaper.rs:3:10
|
--> tests/ui/no-such-escaper.rs:3:10
|
||||||
@ -8,7 +8,7 @@ error: invalid escaper 'latex' for `escape` filter
|
|||||||
|
|
|
|
||||||
= note: this error originates in the derive macro `Template` (in Nightly builds, run with -Z macro-backtrace for more info)
|
= note: this error originates in the derive macro `Template` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
||||||
error: no escaper defined for extension 'tex'
|
error: no escaper defined for extension 'tex'. The available extensions are: "", "htm", "html", "j2", "jinja", "jinja2", "md", "none", "svg", "txt", "xml", "yml"
|
||||||
--> tests/ui/no-such-escaper.rs:12:10
|
--> tests/ui/no-such-escaper.rs:12:10
|
||||||
|
|
|
|
||||||
12 | #[derive(Template)]
|
12 | #[derive(Template)]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user