aboutsummaryrefslogtreecommitdiffstats
path: root/askama_derive/src/input.rs
diff options
context:
space:
mode:
authorLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2018-07-02 09:58:14 +0200
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2018-07-02 09:58:38 +0200
commitcf0c29a8cc1778821d45a725e9551cb1cf51c660 (patch)
tree966c1f60261b6116aebd6faf84bc30eb2e846c0b /askama_derive/src/input.rs
parent3011a7ff1610108dd0a2e4b531c4b1dac45d8673 (diff)
downloadaskama-cf0c29a8cc1778821d45a725e9551cb1cf51c660.tar.gz
askama-cf0c29a8cc1778821d45a725e9551cb1cf51c660.tar.bz2
askama-cf0c29a8cc1778821d45a725e9551cb1cf51c660.zip
Add some comments to TemplateInput::new() method
Diffstat (limited to '')
-rw-r--r--askama_derive/src/input.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/askama_derive/src/input.rs b/askama_derive/src/input.rs
index ce004a8..15a4a6d 100644
--- a/askama_derive/src/input.rs
+++ b/askama_derive/src/input.rs
@@ -19,7 +19,13 @@ pub struct TemplateInput<'a> {
}
impl<'a> TemplateInput<'a> {
+ /// Extract the template metadata from the `DeriveInput` structure. This
+ /// mostly recovers the data for the `TemplateInput` fields from the
+ /// `template()` attribute list fields; it also finds the of the `_parent`
+ /// field, if any.
pub fn new(ast: &'a syn::DeriveInput) -> TemplateInput<'a> {
+ // Check that an attribute called `template()` exists and that it is
+ // the proper type (list).
let mut meta = None;
for attr in &ast.attrs {
match attr.interpret_meta() {
@@ -39,6 +45,9 @@ impl<'a> TemplateInput<'a> {
_ => panic!("attribute 'template' has incorrect type"),
};
+ // Loop over the meta attributes and find everything that we
+ // understand. Raise panics if something is not right.
+ // `source` contains an enum that can represent `path` or `source`.
let mut source = None;
let mut print = Print::None;
let mut escaping = None;
@@ -84,6 +93,9 @@ impl<'a> TemplateInput<'a> {
}
}
+ // Validate the `source` and `ext` value together, since they are
+ // related. In case `source` was used instead of `path`, the value
+ // of `ext` is merged into a synthetic `path` value here.
let source = source.expect("template path or source not found in attributes");
let path = match (&source, &ext) {
(&Source::Path(ref path), None) => path::find_template_from_path(path, None),
@@ -96,6 +108,8 @@ impl<'a> TemplateInput<'a> {
}
};
+ // Check to see if a `_parent` field was defined on the context
+ // struct, and store the type for it for use in the code generator.
let parent = match ast.data {
syn::Data::Struct(syn::DataStruct {
fields: syn::Fields::Named(ref fields),