diff options
author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2022-04-11 16:16:36 +0200 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2022-04-21 10:08:42 +0200 |
commit | d9fcd348d121b6dd0568314b28ec187f11e32c77 (patch) | |
tree | e5bf64890cba10eeb6150033d3f43e35600b1a9e /askama_shared/src/generator.rs | |
parent | a51433677d98ebdba2008315b6d79565530fdf7e (diff) | |
download | askama-d9fcd348d121b6dd0568314b28ec187f11e32c77.tar.gz askama-d9fcd348d121b6dd0568314b28ec187f11e32c77.tar.bz2 askama-d9fcd348d121b6dd0568314b28ec187f11e32c77.zip |
Add config option to derive macro so we can specify config file location
Diffstat (limited to 'askama_shared/src/generator.rs')
-rw-r--r-- | askama_shared/src/generator.rs | 9 |
1 files changed, 8 insertions, 1 deletions
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<String, CompileError> { 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<String>, pub(crate) ext: Option<String>, pub(crate) syntax: Option<String>, + pub(crate) config_path: Option<String>, } 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()); } |