aboutsummaryrefslogtreecommitdiffstats
path: root/askama_derive/src/generator.rs
diff options
context:
space:
mode:
authorLibravatar Guillaume Gomez <guillaume1.gomez@gmail.com>2023-03-07 12:04:31 +0100
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2023-03-13 14:41:05 +0100
commit3ea521d6e88150dd4307ad610cabfe0fb8f30f9d (patch)
tree6949b64a1ae983486dfa1f8e8a5344a9a775d8cb /askama_derive/src/generator.rs
parentd83d6abe2b6e1d7bd87f44b02516a40b057e2179 (diff)
downloadaskama-3ea521d6e88150dd4307ad610cabfe0fb8f30f9d.tar.gz
askama-3ea521d6e88150dd4307ad610cabfe0fb8f30f9d.tar.bz2
askama-3ea521d6e88150dd4307ad610cabfe0fb8f30f9d.zip
Add whitespace argument in template derive proc-macro
Diffstat (limited to 'askama_derive/src/generator.rs')
-rw-r--r--askama_derive/src/generator.rs9
1 files changed, 8 insertions, 1 deletions
diff --git a/askama_derive/src/generator.rs b/askama_derive/src/generator.rs
index cad7909..2101feb 100644
--- a/askama_derive/src/generator.rs
+++ b/askama_derive/src/generator.rs
@@ -30,7 +30,7 @@ pub(crate) fn derive_template(input: TokenStream) -> TokenStream {
fn build_template(ast: &syn::DeriveInput) -> Result<String, CompileError> {
let template_args = TemplateArgs::new(ast)?;
let config_toml = read_config_file(template_args.config_path.as_deref())?;
- let config = Config::new(&config_toml)?;
+ let config = Config::new(&config_toml, template_args.whitespace.as_ref())?;
let input = TemplateInput::new(ast, &config, template_args)?;
let source: String = match input.source {
Source::Source(ref s) => s.clone(),
@@ -83,6 +83,7 @@ pub(crate) struct TemplateArgs {
pub(crate) ext: Option<String>,
pub(crate) syntax: Option<String>,
pub(crate) config_path: Option<String>,
+ pub(crate) whitespace: Option<String>,
}
impl TemplateArgs {
@@ -181,6 +182,12 @@ impl TemplateArgs {
} else {
return Err("config value must be string literal".into());
}
+ } else if ident == "whitespace" {
+ if let syn::Lit::Str(ref s) = pair.lit {
+ args.whitespace = Some(s.value())
+ } else {
+ return Err("whitespace value must be string literal".into());
+ }
} else {
return Err(format!("unsupported attribute key {ident:?} found").into());
}