aboutsummaryrefslogtreecommitdiffstats
path: root/askama_derive
diff options
context:
space:
mode:
authorLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2017-08-25 13:23:55 +0200
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2017-08-25 13:23:55 +0200
commitfc7be3c927d2078a317797c0d5477ad608c4c625 (patch)
tree354ee6cc835420fce052d1dad02644af7d769634 /askama_derive
parent42e854809a4d7746b5191617bf31cce388c62967 (diff)
downloadaskama-fc7be3c927d2078a317797c0d5477ad608c4c625.tar.gz
askama-fc7be3c927d2078a317797c0d5477ad608c4c625.tar.bz2
askama-fc7be3c927d2078a317797c0d5477ad608c4c625.zip
Use block implementations in parent as defaults in trait
Diffstat (limited to '')
-rw-r--r--askama_derive/src/generator.rs14
1 files changed, 3 insertions, 11 deletions
diff --git a/askama_derive/src/generator.rs b/askama_derive/src/generator.rs
index c0986da..82f3994 100644
--- a/askama_derive/src/generator.rs
+++ b/askama_derive/src/generator.rs
@@ -12,7 +12,6 @@ use syn;
pub fn generate(ast: &syn::DeriveInput, path: &Path, mut nodes: Vec<Node>) -> String {
let mut base: Option<Expr> = None;
let mut blocks = Vec::new();
- let mut block_names = Vec::new();
let mut content = Vec::new();
let mut macros = HashMap::new();
for n in nodes.drain(..) {
@@ -25,7 +24,6 @@ pub fn generate(ast: &syn::DeriveInput, path: &Path, mut nodes: Vec<Node>) -> St
},
Node::BlockDef(ws1, name, _, ws2) => {
blocks.push(n);
- block_names.push(name);
content.push(Node::Block(ws1, name, ws2));
},
Node::Macro(ws1, name, params, contents, ws2) => {
@@ -39,7 +37,7 @@ pub fn generate(ast: &syn::DeriveInput, path: &Path, mut nodes: Vec<Node>) -> St
if !blocks.is_empty() {
let trait_name = trait_name_for_path(&base, path);
if base.is_none() {
- gen.define_trait(&trait_name, &block_names);
+ gen.define_trait(&trait_name, &blocks);
} else {
let parent_type = get_parent_type(ast)
.expect("expected field '_parent' in extending template struct");
@@ -625,15 +623,9 @@ impl<'a> Generator<'a> {
}
// Defines the `TraitFromPathName` trait.
- fn define_trait(&mut self, trait_name: &str, block_names: &[&str]) {
+ fn define_trait(&mut self, trait_name: &str, blocks: &'a [Node]) {
self.writeln(&format!("trait {} {{", &trait_name));
-
- for bname in block_names {
- self.writeln(&format!(
- "fn render_block_{}_into(&self, writer: &mut ::std::fmt::Write) \
- -> ::askama::Result<()>;",
- bname));
- }
+ self.handle(blocks);
self.writeln(&format!(
"fn render_trait_into(&self, timpl: &{}, writer: &mut ::std::fmt::Write) \
-> ::askama::Result<()>;",