1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use std::io::Write;

use liquid_error::Result;

use super::Context;
use super::Renderable;

/// An executable template block.
#[derive(Debug)]
pub struct Template {
    elements: Vec<Box<Renderable>>,
}

impl Template {
    /// Create an executable template block.
    pub fn new(elements: Vec<Box<Renderable>>) -> Template {
        Template { elements }
    }
}

impl Renderable for Template {
    fn render_to(&self, writer: &mut Write, context: &mut Context) -> Result<()> {
        for el in &self.elements {
            el.render_to(writer, context)?;

            // Did the last element we processed set an interrupt? If so, we
            // need to abandon the rest of our child elements and just
            // return what we've got. This is usually in response to a
            // `break` or `continue` tag being rendered.
            if context.interrupt().interrupted() {
                break;
            }
        }
        Ok(())
    }
}