mirror of
https://github.com/askama-rs/askama.git
synced 2025-10-02 23:35:07 +00:00
simplify handler
Signed-off-by: Michael Pollind <mpollind@gmail.com>
This commit is contained in:
parent
ef489b60f6
commit
b328a96ca4
@ -87,7 +87,7 @@ struct Generator<'a, 'h> {
|
|||||||
/// Set of called macros we are currently in. Used to prevent (indirect) recursions.
|
/// Set of called macros we are currently in. Used to prevent (indirect) recursions.
|
||||||
seen_macros: Vec<(&'a Macro<'a>, Option<FileInfo<'a>>)>,
|
seen_macros: Vec<(&'a Macro<'a>, Option<FileInfo<'a>>)>,
|
||||||
/// Set of callers to forward into the macro.
|
/// Set of callers to forward into the macro.
|
||||||
seen_callers: Vec<&'a Call<'a>>,
|
current_caller: Option<&'a Call<'a>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'h> Generator<'a, 'h> {
|
impl<'a, 'h> Generator<'a, 'h> {
|
||||||
@ -113,7 +113,7 @@ impl<'a, 'h> Generator<'a, 'h> {
|
|||||||
},
|
},
|
||||||
is_in_filter_block,
|
is_in_filter_block,
|
||||||
seen_macros: Vec::new(),
|
seen_macros: Vec::new(),
|
||||||
seen_callers: Vec::new(),
|
current_caller: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -649,7 +649,7 @@ impl<'a> Generator<'a, '_> {
|
|||||||
} else {
|
} else {
|
||||||
self.seen_macros.push((def, ctx.file_info_of(call.span())));
|
self.seen_macros.push((def, ctx.file_info_of(call.span())));
|
||||||
}
|
}
|
||||||
self.seen_callers.push(call);
|
self.current_caller = Some(call);
|
||||||
self.flush_ws(ws1); // Cannot handle_ws() here: whitespace from macro definition comes first
|
self.flush_ws(ws1); // Cannot handle_ws() here: whitespace from macro definition comes first
|
||||||
let size_hint = self.push_locals(|this| {
|
let size_hint = self.push_locals(|this| {
|
||||||
macro_call_ensure_arg_count(call, def, ctx)?;
|
macro_call_ensure_arg_count(call, def, ctx)?;
|
||||||
@ -773,7 +773,7 @@ impl<'a> Generator<'a, '_> {
|
|||||||
})?;
|
})?;
|
||||||
self.prepare_ws(ws1);
|
self.prepare_ws(ws1);
|
||||||
self.seen_macros.pop();
|
self.seen_macros.pop();
|
||||||
self.seen_callers.pop();
|
self.current_caller = None;
|
||||||
Ok(size_hint)
|
Ok(size_hint)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1119,9 +1119,10 @@ impl<'a> Generator<'a, '_> {
|
|||||||
if ***path == Expr::Var("super") {
|
if ***path == Expr::Var("super") {
|
||||||
return self.write_block(ctx, buf, None, ws, s.span());
|
return self.write_block(ctx, buf, None, ws, s.span());
|
||||||
} else if ***path == Expr::Var("caller") {
|
} else if ***path == Expr::Var("caller") {
|
||||||
let def = self.seen_callers.pop().ok_or_else(|| {
|
let def = self.current_caller.ok_or_else(|| {
|
||||||
ctx.generate_error(format_args!("block is not defined for caller"), s.span())
|
ctx.generate_error(format_args!("block is not defined for caller"), s.span())
|
||||||
})?;
|
})?;
|
||||||
|
self.current_caller = None;
|
||||||
self.handle_ws(ws);
|
self.handle_ws(ws);
|
||||||
let size_hint = self.push_locals(|this| {
|
let size_hint = self.push_locals(|this| {
|
||||||
this.write_buf_writable(ctx, buf)?;
|
this.write_buf_writable(ctx, buf)?;
|
||||||
@ -1188,7 +1189,7 @@ impl<'a> Generator<'a, '_> {
|
|||||||
buf.write('}');
|
buf.write('}');
|
||||||
Ok(size_hint)
|
Ok(size_hint)
|
||||||
})?;
|
})?;
|
||||||
self.seen_callers.push(def);
|
self.current_caller = Some(def);
|
||||||
return Ok(size_hint);
|
return Ok(size_hint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user