|
|
@@ -1,3 +1,5 @@ |
|
|
|
use std::collections::HashMap; |
|
|
|
|
|
|
|
use tera::{Tera, Context}; |
|
|
|
|
|
|
|
use errors::Result; |
|
|
@@ -57,9 +59,12 @@ pub fn render_template(name: &str, tera: &Tera, context: &Context, theme: &Optio |
|
|
|
/// so themes shortcodes can be used. |
|
|
|
pub fn rewrite_theme_paths(tera: &mut Tera, theme: &str) { |
|
|
|
let mut shortcodes_to_move = vec![]; |
|
|
|
let mut templates = HashMap::new(); |
|
|
|
let old_templates = ::std::mem::replace(&mut tera.templates, HashMap::new()); |
|
|
|
|
|
|
|
// We want to match the paths in the templates to the new names |
|
|
|
for tpl in tera.templates.values_mut() { |
|
|
|
for (key, mut tpl) in old_templates{ |
|
|
|
tpl.name = format!("{}/templates/{}", theme, tpl.name); |
|
|
|
// First the parent if there is none |
|
|
|
if let Some(ref p) = tpl.parent.clone() { |
|
|
|
tpl.parent = Some(format!("{}/templates/{}", theme, p)); |
|
|
@@ -74,11 +79,15 @@ pub fn rewrite_theme_paths(tera: &mut Tera, theme: &str) { |
|
|
|
|
|
|
|
if tpl.name.starts_with(&format!("{}/templates/shortcodes", theme)) { |
|
|
|
let new_name = tpl.name.replace(&format!("{}/templates/", theme), ""); |
|
|
|
shortcodes_to_move.push((tpl.name.clone(), new_name.clone())); |
|
|
|
shortcodes_to_move.push((key, new_name.clone())); |
|
|
|
tpl.name = new_name; |
|
|
|
} |
|
|
|
|
|
|
|
templates.insert(tpl.name.clone(), tpl); |
|
|
|
} |
|
|
|
|
|
|
|
tera.templates = templates; |
|
|
|
|
|
|
|
// and then replace shortcodes in the Tera instance using the new names |
|
|
|
for (old_name, new_name) in shortcodes_to_move { |
|
|
|
let tpl = tera.templates.remove(&old_name).unwrap(); |
|
|
|