/// Renders the document to an HTML string.
///
/// Side effects:
///
/// * layout may be inserted to layouts cache
Renders the document to an HTML string.
Side effects.

layout may be inserted to layouts cache
Renders the document to an HTML string . Side effects . layout may be inserted to layouts cache
pub fn render(&mut self,
                  globals: &liquid::Object,
                  parser: &template::LiquidParser,
                  layouts_dir: &Path,
                  layouts_cache: &mut HashMap<String, String>)
                  -> Result<String> {
        if let Some(ref layout) = self.front.layout {
            let layout_data_ref = match layouts_cache.entry(layout.to_owned()) {
                Entry::Vacant(vacant) => {
                    let layout_data = files::read_file(layouts_dir.join(layout))
                        .map_err(|e| {
                                     format!("Layout {} can not be read (defined in {:?}): {}",
                                             layout,
                                             self.file_path,
                                             e)
                                 })?;
                    vacant.insert(layout_data)
                }
                Entry::Occupied(occupied) => occupied.into_mut(),
            };
            let template = parser
                .parse(layout_data_ref)
                .chain_err(|| format!("Failed to parse layout {:?}", layout))?;
            let content_html = template
                .render(globals)
                .chain_err(|| format!("Failed to render layout {:?}", layout))?;
            Ok(content_html)
        } else {
            let content_html = globals
                .get("page")
                .ok_or("Internal error: page isn't in globals")?
                .get(&liquid::Index::with_key("content"))
                .ok_or("Internal error: page.content isn't in globals")?
                .as_str()
                .ok_or("Internal error: bad content format")?
                .to_owned();
            Ok(content_html)
        }
    }
pub fn render ( & mut self , globals : & liquid :: Object , parser : & template :: LiquidParser , layouts_dir : & Path , layouts_cache : & mut HashMap < String , String > ) -> Result < String > { if let Some ( ref layout ) = self . front . layout { let layout_data_ref = match layouts_cache . entry ( layout . to_owned ( ) ) { Entry :: Vacant ( vacant ) => { let layout_data = files :: read_file ( layouts_dir . join ( layout ) ) . map_err ( | e | { format ! ( " " layout self file_path e ) } ) ? ; vacant . insert ( layout_data ) } Entry :: Occupied ( occupied ) => occupied . into_mut ( ) , } ; let template = parser . parse ( layout_data_ref ) . chain_err ( | | format ! ( " " layout ) ) ? ; let content_html = template . render ( globals ) . chain_err ( | | format ! ( " " layout ) ) ? ; Ok ( content_html ) } else { let content_html = globals . get ( " " ) . ok_or ( " " ) ? . get ( & liquid :: Index :: with_key ( " " ) ) . ok_or ( " " ) ? . as_str ( ) . ok_or ( " " ) ? . to_owned ( ) ; Ok ( content_html ) } }
Renders the document to an HTML string.
Renders the document to an HTML string .
&mut self
globals
&liquid::Object
parser
&template::LiquidParser
layouts_dir
&Path
layouts_cache
&mut HashMap<String, String>