fn load_from_glob(&mut self) -> Result<()> {
        if self.glob.is_none() {
            bail!("Tera can only load from glob if a glob is provided");
        }
        // We want to preserve templates that have been added through
        // Tera::extend so we only keep those
        self.templates = self
            .templates
            .iter()
            .filter(|&(_, t)| t.from_extend)
            .map(|(n, t)| (n.clone(), t.clone())) // TODO: avoid that clone
            .collect();

        let mut errors = String::new();

        let dir = self.glob.clone().unwrap();
        // We are parsing all the templates on instantiation
        for entry in glob(&dir).unwrap().filter_map(|e| e.ok()) {
            let path = entry.as_path();
            // We only care about actual files
            if path.is_file() {
                // We clean the filename by removing the dir given
                // to Tera so users don't have to prefix everytime
                let mut parent_dir = dir.split_at(dir.find('*').unwrap()).0;
                // Remove `./` from the glob if used as it would cause an error in strip_prefix
                if parent_dir.starts_with("./") {
                    parent_dir = &parent_dir[2..];
                }
                let filepath = path
                    .strip_prefix(&parent_dir)
                    .unwrap()
                    .to_string_lossy()
                    // unify on forward slash
                    .replace("\\", "/");

                if let Err(e) = self.add_file(Some(&filepath), path) {
                    errors += &format!("\n* {}", e);
                    for e in e.iter().skip(1) {
                        errors += &format!("\n{}", e);
                    }
                }
            }
        }

        if !errors.is_empty() {
            bail!(errors);
        }

        Ok(())
    }
/// Loads all the templates found in the glob that was given to Tera::new
Loads all the templates found in the glob that was given to Tera::new
Loads all the templates found in the glob that was given to Tera :: new
fn load_from_glob(&mut self) -> Result<()> {
        if self.glob.is_none() {
            bail!("Tera can only load from glob if a glob is provided");
        }
        // We want to preserve templates that have been added through
        // Tera::extend so we only keep those
        self.templates = self
            .templates
            .iter()
            .filter(|&(_, t)| t.from_extend)
            .map(|(n, t)| (n.clone(), t.clone())) // TODO: avoid that clone
            .collect();
        let mut errors = String::new();
        let dir = self.glob.clone().unwrap();
        // We are parsing all the templates on instantiation
        for entry in glob(&dir).unwrap().filter_map(|e| e.ok()) {
            let path = entry.as_path();
            // We only care about actual files
            if path.is_file() {
                // We clean the filename by removing the dir given
                // to Tera so users don't have to prefix everytime
                let mut parent_dir = dir.split_at(dir.find('*').unwrap()).0;
                // Remove `./` from the glob if used as it would cause an error in strip_prefix
                if parent_dir.starts_with("./") {
                    parent_dir = &parent_dir[2..];
                }
                let filepath = path
                    .strip_prefix(&parent_dir)
                    .unwrap()
                    .to_string_lossy()
                    // unify on forward slash
                    .replace("\\", "/");
                if let Err(e) = self.add_file(Some(&filepath), path) {
                    errors += &format!("\n* {}", e);
                    for e in e.iter().skip(1) {
                        errors += &format!("\n{}", e);
                    }
                }
            }
        }
        if !errors.is_empty() {
            bail!(errors);
        }
        Ok(())
    }
fn load_from_glob ( & mut self ) -> Result < ( ) > { if self . glob . is_none ( ) { bail ! ( " " ) ; } // We want to preserve templates that have been added through // Tera::extend so we only keep those self . templates = self . templates . iter ( ) . filter ( | & ( _ , t ) | t . from_extend ) . map ( | ( n , t ) | ( n . clone ( ) , t . clone ( ) ) ) // TODO: avoid that clone . collect ( ) ; let mut errors = String :: new ( ) ; let dir = self . glob . clone ( ) . unwrap ( ) ; // We are parsing all the templates on instantiation for entry in glob ( & dir ) . unwrap ( ) . filter_map ( | e | e . ok ( ) ) { let path = entry . as_path ( ) ; // We only care about actual files if path . is_file ( ) { // We clean the filename by removing the dir given // to Tera so users don't have to prefix everytime let mut parent_dir = dir . split_at ( dir . find ( '*' ) . unwrap ( ) ) . 0 ; // Remove `./` from the glob if used as it would cause an error in strip_prefix if parent_dir . starts_with ( " " ) { parent_dir = & parent_dir [ 2 .. ] ; } let filepath = path . strip_prefix ( & parent_dir ) . unwrap ( ) . to_string_lossy ( ) // unify on forward slash . replace ( " \\ " , " " ) ; if let Err ( e ) = self . add_file ( Some ( & filepath ) , path ) { errors += & format ! ( " \n " e ) ; for e in e . iter ( ) . skip ( 1 ) { errors += & format ! ( " \n " e ) ; } } } } if ! errors . is_empty ( ) { bail ! ( errors ) ; } Ok ( ( ) ) }
Loads all the templates found in the glob that was given to Tera::new
Loads all the templates found in the glob that was given to Tera :: new
&mut self
&mut self