liquid_interpreter/
template.rs

1use std::io::Write;
2
3use liquid_error::Result;
4
5use super::Context;
6use super::Renderable;
7
8/// An executable template block.
9#[derive(Debug)]
10pub struct Template {
11    elements: Vec<Box<Renderable>>,
12}
13
14impl Template {
15    /// Create an executable template block.
16    pub fn new(elements: Vec<Box<Renderable>>) -> Template {
17        Template { elements }
18    }
19}
20
21impl Renderable for Template {
22    fn render_to(&self, writer: &mut Write, context: &mut Context) -> Result<()> {
23        for el in &self.elements {
24            el.render_to(writer, context)?;
25
26            // Did the last element we processed set an interrupt? If so, we
27            // need to abandon the rest of our child elements and just
28            // return what we've got. This is usually in response to a
29            // `break` or `continue` tag being rendered.
30            if context.interrupt().interrupted() {
31                break;
32            }
33        }
34        Ok(())
35    }
36}