Move all tera stuff into a templates mod

This commit is contained in:
Vincent Prouillet 2017-05-12 23:27:22 +09:00
parent 2fb4e2b01d
commit 72c626ee55
14 changed files with 28 additions and 27 deletions

View file

@ -28,12 +28,10 @@ mod site;
mod markdown;
mod section;
mod pagination;
/// Additional filters for Tera
mod filters;
/// Global fns for Tera
mod global_fns;
// Filters, Global Fns and default instance of Tera
mod templates;
pub use site::{Site, GUTENBERG_TERA};
pub use site::{Site};
pub use config::{Config, get_config};
pub use front_matter::{FrontMatter, split_content, SortBy};
pub use page::{Page, populate_previous_and_next_pages};

View file

@ -340,7 +340,7 @@ pub fn markdown_to_html(content: &str, permalinks: &HashMap<String, String>, ter
mod tests {
use std::collections::HashMap;
use site::GUTENBERG_TERA;
use templates::GUTENBERG_TERA;
use tera::Tera;
use config::Config;

View file

@ -15,29 +15,9 @@ use pagination::Paginator;
use utils::{create_file, create_directory};
use section::{Section};
use front_matter::{SortBy};
use filters;
use global_fns;
use templates::{GUTENBERG_TERA, filters, global_fns};
lazy_static! {
pub static ref GUTENBERG_TERA: Tera = {
let mut tera = Tera::default();
tera.add_raw_templates(vec![
("rss.xml", include_str!("templates/rss.xml")),
("sitemap.xml", include_str!("templates/sitemap.xml")),
("robots.txt", include_str!("templates/robots.txt")),
("anchor-link.html", include_str!("templates/anchor-link.html")),
("shortcodes/youtube.html", include_str!("templates/shortcodes/youtube.html")),
("shortcodes/vimeo.html", include_str!("templates/shortcodes/vimeo.html")),
("shortcodes/gist.html", include_str!("templates/shortcodes/gist.html")),
("internal/alias.html", include_str!("templates/internal/alias.html")),
]).unwrap();
tera
};
}
/// Renders the `internal/alias.html` template that will redirect
/// via refresh to the url given
fn render_alias(url: &str, tera: &Tera) -> Result<String> {

23
src/templates/mod.rs Normal file
View file

@ -0,0 +1,23 @@
use tera::Tera;
pub mod filters;
pub mod global_fns;
lazy_static! {
pub static ref GUTENBERG_TERA: Tera = {
let mut tera = Tera::default();
tera.add_raw_templates(vec![
("rss.xml", include_str!("builtins/rss.xml")),
("sitemap.xml", include_str!("builtins/sitemap.xml")),
("robots.txt", include_str!("builtins/robots.txt")),
("anchor-link.html", include_str!("builtins/anchor-link.html")),
("shortcodes/youtube.html", include_str!("builtins/shortcodes/youtube.html")),
("shortcodes/vimeo.html", include_str!("builtins/shortcodes/vimeo.html")),
("shortcodes/gist.html", include_str!("builtins/shortcodes/gist.html")),
("internal/alias.html", include_str!("builtins/internal/alias.html")),
]).unwrap();
tera
};
}