fn templated(config: &Config, page: &Page) -> String {
	// starts with default template file
	let mut template_file = String::from("default.html");
	for header_var in &page.meta {
	    if header_var.name == "template" {
	        // if the granite meta header has a template value, sets `template_file` to that
	        template_file = header_var.value.clone();
	        template_file.push_str(".html");
	    }
	}
	let template_path = [config.template_path.clone(), template_file].concat();

	// gets the contents of the given template file
	let template_contents = match fs::read_to_string(&template_path) {
	    Ok(c) => c,
	    Err(_) => {
	        // if it can't be loaded, just load the default
	        let mut temp_path = config.template_path.clone();
	        temp_path.push_str("default.html");
	        fs::read_to_string(&temp_path)
	            .expect("couldn't load default template")
	    }
	};

	let template_lines: Vec<&str> = template_contents.as_str().lines().collect();

	// figures out how indented the content marker is (non-functional)
	let mut whitespace = String::new();
	for l in template_lines {
		let line = l.to_string();
	    if line.contains("{{content}}") {
	        whitespace = slice(&line, 0..first(&line).1);
	    }
	}

	// replaces content in template
	let mut con_w_space = String::from("{{content}}");
	con_w_space = insert(&con_w_space, 0, &whitespace);
	replace(&template_contents, &con_w_space, &page.content)
}
/*
Takes a config file (for the template path) and a page and outputs the html with everything
*/
Takes a config file (for the template path) and a page and outputs the html with everything
Takes a config file ( for the template path ) and a page and outputs the html with everything
fn templated(config: &Config, page: &Page) -> String {
	// starts with default template file
	let mut template_file = String::from("default.html");
	for header_var in &page.meta {
	    if header_var.name == "template" {
	        // if the granite meta header has a template value, sets `template_file` to that
	        template_file = header_var.value.clone();
	        template_file.push_str(".html");
	    }
	}
	let template_path = [config.template_path.clone(), template_file].concat();
	// gets the contents of the given template file
	let template_contents = match fs::read_to_string(&template_path) {
	    Ok(c) => c,
	    Err(_) => {
	        // if it can't be loaded, just load the default
	        let mut temp_path = config.template_path.clone();
	        temp_path.push_str("default.html");
	        fs::read_to_string(&temp_path)
	            .expect("couldn't load default template")
	    }
	};
	let template_lines: Vec<&str> = template_contents.as_str().lines().collect();
	// figures out how indented the content marker is (non-functional)
	let mut whitespace = String::new();
	for l in template_lines {
		let line = l.to_string();
	    if line.contains("{{content}}") {
	        whitespace = slice(&line, 0..first(&line).1);
	    }
	}
	// replaces content in template
	let mut con_w_space = String::from("{{content}}");
	con_w_space = insert(&con_w_space, 0, &whitespace);
	replace(&template_contents, &con_w_space, &page.content)
}
fn templated ( config : & Config , page : & Page ) -> String { // starts with default template file let mut template_file = String :: from ( " " ) ; for header_var in & page . meta { if header_var . name == " " { // if the granite meta header has a template value, sets `template_file` to that template_file = header_var . value . clone ( ) ; template_file . push_str ( " " ) ; } } let template_path = [ config . template_path . clone ( ) , template_file ] . concat ( ) ; // gets the contents of the given template file let template_contents = match fs :: read_to_string ( & template_path ) { Ok ( c ) => c , Err ( _ ) => { // if it can't be loaded, just load the default let mut temp_path = config . template_path . clone ( ) ; temp_path . push_str ( " " ) ; fs :: read_to_string ( & temp_path ) . expect ( " " ) } } ; let template_lines : Vec < & str > = template_contents . as_str ( ) . lines ( ) . collect ( ) ; // figures out how indented the content marker is (non-functional) let mut whitespace = String :: new ( ) ; for l in template_lines { let line = l . to_string ( ) ; if line . contains ( " " ) { whitespace = slice ( & line , 0 .. first ( & line ) . 1 ) ; } } // replaces content in template let mut con_w_space = String :: from ( " " ) ; con_w_space = insert ( & con_w_space , 0 , & whitespace ) ; replace ( & template_contents , & con_w_space , & page . content ) }
Takes a config file (for the template path) and a page and outputs the html with everything
Takes a config file ( for the template path ) and a page and outputs the html with everything
config
&Config
page
&Page
config
&Config
page
&Page