aboutsummaryrefslogtreecommitdiffstats
path: root/askama_derive/src/input.rs
diff options
context:
space:
mode:
authorLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2018-06-21 12:13:56 +0200
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2018-06-21 12:13:56 +0200
commite09cdfaf1f9cca45ed320c3ad97f3502c48ff73d (patch)
treef2317f584defb86207ef4e404de1ec3e8a26f80b /askama_derive/src/input.rs
parent56c050275b0066d0eaa77264b1a3bfcbc370b2bb (diff)
downloadaskama-e09cdfaf1f9cca45ed320c3ad97f3502c48ff73d.tar.gz
askama-e09cdfaf1f9cca45ed320c3ad97f3502c48ff73d.tar.bz2
askama-e09cdfaf1f9cca45ed320c3ad97f3502c48ff73d.zip
Let build_template() own the template source
Diffstat (limited to 'askama_derive/src/input.rs')
-rw-r--r--askama_derive/src/input.rs24
1 files changed, 8 insertions, 16 deletions
diff --git a/askama_derive/src/input.rs b/askama_derive/src/input.rs
index c4bb0a3..62c1072 100644
--- a/askama_derive/src/input.rs
+++ b/askama_derive/src/input.rs
@@ -9,33 +9,25 @@ pub struct TemplateInput<'a> {
pub ast: &'a syn::DeriveInput,
pub meta: TemplateMeta,
pub path: PathBuf,
- pub source: String,
}
impl<'a> TemplateInput<'a> {
pub fn new(ast: &'a syn::DeriveInput) -> TemplateInput<'a> {
let meta = TemplateMeta::new(ast);
- let (path, source) = match meta.source {
- Source::Source(ref s) => {
- let path = match meta.ext {
- Some(ref v) => PathBuf::from(format!("{}.{}", ast.ident, v)),
- None => PathBuf::new(),
- };
- (path, s.clone())
- },
- Source::Path(ref s) => {
- let path = path::find_template_from_path(s, None);
- let src = path::get_template_source(&path);
- (path, src)
+ let path = match meta.source {
+ Source::Source(_) => match meta.ext {
+ Some(ref v) => PathBuf::from(format!("{}.{}", ast.ident, v)),
+ None => PathBuf::new(),
},
+ Source::Path(ref s) => path::find_template_from_path(s, None),
};
- TemplateInput { ast, meta, path, source }
+ TemplateInput { ast, meta, path }
}
}
// Holds metadata for the template, based on the `template()` attribute.
pub struct TemplateMeta {
- source: Source,
+ pub source: Source,
pub print: Print,
pub escaping: EscapeMode,
pub ext: Option<String>,
@@ -127,7 +119,7 @@ impl TemplateMeta {
}
}
-enum Source {
+pub enum Source {
Path(String),
Source(String),
}