zola/components/rendering/src/context.rs

39 lines
1,001 B
Rust
Raw Normal View History

use std::collections::HashMap;
2018-02-02 20:35:04 +00:00
use tera::{Tera, Context};
use front_matter::InsertAnchor;
2018-05-06 20:58:39 +00:00
use config::Config;
/// All the information from the zola site that is needed to render HTML from markdown
#[derive(Debug)]
2018-05-06 20:58:39 +00:00
pub struct RenderContext<'a> {
pub tera: &'a Tera,
2018-05-06 20:58:39 +00:00
pub config: &'a Config,
2018-06-25 17:13:21 +00:00
pub tera_context: Context,
2018-05-06 20:58:39 +00:00
pub current_page_permalink: &'a str,
pub permalinks: &'a HashMap<String, String>,
pub insert_anchor: InsertAnchor,
}
2018-05-06 20:58:39 +00:00
impl<'a> RenderContext<'a> {
2017-06-16 04:00:48 +00:00
pub fn new(
tera: &'a Tera,
2018-05-06 20:58:39 +00:00
config: &'a Config,
current_page_permalink: &'a str,
2017-06-16 04:00:48 +00:00
permalinks: &'a HashMap<String, String>,
insert_anchor: InsertAnchor,
2018-05-06 20:58:39 +00:00
) -> RenderContext<'a> {
2018-06-25 17:13:21 +00:00
let mut tera_context = Context::new();
tera_context.insert("config", config);
2018-05-06 20:58:39 +00:00
RenderContext {
tera,
2018-06-25 17:13:21 +00:00
tera_context,
2018-05-06 20:58:39 +00:00
current_page_permalink,
permalinks,
insert_anchor,
2018-05-06 20:58:39 +00:00
config,
}
}
}