From d9fcd348d121b6dd0568314b28ec187f11e32c77 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 11 Apr 2022 16:16:36 +0200 Subject: Add config option to derive macro so we can specify config file location --- askama_shared/src/generator.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'askama_shared/src/generator.rs') diff --git a/askama_shared/src/generator.rs b/askama_shared/src/generator.rs index a09631c..9aec1d6 100644 --- a/askama_shared/src/generator.rs +++ b/askama_shared/src/generator.rs @@ -29,7 +29,7 @@ pub fn derive_template(input: TokenStream) -> TokenStream { /// value as passed to the `template()` attribute. fn build_template(ast: &syn::DeriveInput) -> Result { let template_args = TemplateArgs::new(ast)?; - let config_toml = read_config_file()?; + let config_toml = read_config_file(&template_args.config_path)?; let config = Config::new(&config_toml)?; let input = TemplateInput::new(ast, &config, template_args)?; let source: String = match input.source { @@ -82,6 +82,7 @@ pub(crate) struct TemplateArgs { pub(crate) escaping: Option, pub(crate) ext: Option, pub(crate) syntax: Option, + pub(crate) config_path: Option, } impl TemplateArgs { @@ -174,6 +175,12 @@ impl TemplateArgs { } else { return Err("syntax value must be string literal".into()); } + } else if ident == "config" { + if let syn::Lit::Str(ref s) = pair.lit { + args.config_path = Some(s.value()) + } else { + return Err("config value must be string literal".into()); + } } else { return Err(format!("unsupported attribute key {:?} found", ident).into()); } -- cgit