From 72c626ee554ac60a7d9e2d6b02e6694d6deaab9f Mon Sep 17 00:00:00 2001 From: Vincent Prouillet Date: Fri, 12 May 2017 23:27:22 +0900 Subject: [PATCH] Move all tera stuff into a templates mod --- src/lib.rs | 8 +++---- src/markdown.rs | 2 +- src/site.rs | 24 ++----------------- src/templates/{ => builtins}/anchor-link.html | 0 .../{ => builtins}/internal/alias.html | 0 src/templates/{ => builtins}/robots.txt | 0 src/templates/{ => builtins}/rss.xml | 0 .../{ => builtins}/shortcodes/gist.html | 0 .../{ => builtins}/shortcodes/vimeo.html | 0 .../{ => builtins}/shortcodes/youtube.html | 0 src/templates/{ => builtins}/sitemap.xml | 0 src/{ => templates}/filters.rs | 0 src/{ => templates}/global_fns.rs | 0 src/templates/mod.rs | 23 ++++++++++++++++++ 14 files changed, 29 insertions(+), 28 deletions(-) rename src/templates/{ => builtins}/anchor-link.html (100%) rename src/templates/{ => builtins}/internal/alias.html (100%) rename src/templates/{ => builtins}/robots.txt (100%) rename src/templates/{ => builtins}/rss.xml (100%) rename src/templates/{ => builtins}/shortcodes/gist.html (100%) rename src/templates/{ => builtins}/shortcodes/vimeo.html (100%) rename src/templates/{ => builtins}/shortcodes/youtube.html (100%) rename src/templates/{ => builtins}/sitemap.xml (100%) rename src/{ => templates}/filters.rs (100%) rename src/{ => templates}/global_fns.rs (100%) create mode 100644 src/templates/mod.rs diff --git a/src/lib.rs b/src/lib.rs index 6e79fbb..a84a891 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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}; diff --git a/src/markdown.rs b/src/markdown.rs index 9be64a7..f32cf89 100644 --- a/src/markdown.rs +++ b/src/markdown.rs @@ -340,7 +340,7 @@ pub fn markdown_to_html(content: &str, permalinks: &HashMap, ter mod tests { use std::collections::HashMap; - use site::GUTENBERG_TERA; + use templates::GUTENBERG_TERA; use tera::Tera; use config::Config; diff --git a/src/site.rs b/src/site.rs index 46c20f7..ee62500 100644 --- a/src/site.rs +++ b/src/site.rs @@ -15,28 +15,8 @@ use pagination::Paginator; use utils::{create_file, create_directory}; use section::{Section}; use front_matter::{SortBy}; -use filters; -use 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 - }; -} +use templates::{GUTENBERG_TERA, filters, global_fns}; + /// Renders the `internal/alias.html` template that will redirect /// via refresh to the url given diff --git a/src/templates/anchor-link.html b/src/templates/builtins/anchor-link.html similarity index 100% rename from src/templates/anchor-link.html rename to src/templates/builtins/anchor-link.html diff --git a/src/templates/internal/alias.html b/src/templates/builtins/internal/alias.html similarity index 100% rename from src/templates/internal/alias.html rename to src/templates/builtins/internal/alias.html diff --git a/src/templates/robots.txt b/src/templates/builtins/robots.txt similarity index 100% rename from src/templates/robots.txt rename to src/templates/builtins/robots.txt diff --git a/src/templates/rss.xml b/src/templates/builtins/rss.xml similarity index 100% rename from src/templates/rss.xml rename to src/templates/builtins/rss.xml diff --git a/src/templates/shortcodes/gist.html b/src/templates/builtins/shortcodes/gist.html similarity index 100% rename from src/templates/shortcodes/gist.html rename to src/templates/builtins/shortcodes/gist.html diff --git a/src/templates/shortcodes/vimeo.html b/src/templates/builtins/shortcodes/vimeo.html similarity index 100% rename from src/templates/shortcodes/vimeo.html rename to src/templates/builtins/shortcodes/vimeo.html diff --git a/src/templates/shortcodes/youtube.html b/src/templates/builtins/shortcodes/youtube.html similarity index 100% rename from src/templates/shortcodes/youtube.html rename to src/templates/builtins/shortcodes/youtube.html diff --git a/src/templates/sitemap.xml b/src/templates/builtins/sitemap.xml similarity index 100% rename from src/templates/sitemap.xml rename to src/templates/builtins/sitemap.xml diff --git a/src/filters.rs b/src/templates/filters.rs similarity index 100% rename from src/filters.rs rename to src/templates/filters.rs diff --git a/src/global_fns.rs b/src/templates/global_fns.rs similarity index 100% rename from src/global_fns.rs rename to src/templates/global_fns.rs diff --git a/src/templates/mod.rs b/src/templates/mod.rs new file mode 100644 index 0000000..11e5077 --- /dev/null +++ b/src/templates/mod.rs @@ -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 + }; +}