2017-05-22 11:28:43 +00:00
|
|
|
use std::collections::HashMap;
|
|
|
|
|
2018-02-02 20:35:04 +00:00
|
|
|
use tera::{Tera, Context};
|
2017-05-22 11:28:43 +00:00
|
|
|
use front_matter::InsertAnchor;
|
2018-05-06 20:58:39 +00:00
|
|
|
use config::Config;
|
2017-05-22 11:28:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
/// All the information from the gutenberg site that is needed to render HTML from markdown
|
|
|
|
#[derive(Debug)]
|
2018-05-06 20:58:39 +00:00
|
|
|
pub struct RenderContext<'a> {
|
2017-05-22 11:28:43 +00:00
|
|
|
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,
|
2017-05-22 11:28:43 +00:00
|
|
|
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 {
|
2017-05-22 11:28:43 +00:00
|
|
|
tera,
|
2018-06-25 17:13:21 +00:00
|
|
|
tera_context,
|
2018-05-06 20:58:39 +00:00
|
|
|
current_page_permalink,
|
2017-05-22 11:28:43 +00:00
|
|
|
permalinks,
|
|
|
|
insert_anchor,
|
2018-05-06 20:58:39 +00:00
|
|
|
config,
|
2017-05-22 11:28:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|