Fix doc rendering for imports
parent
1c47888a05
commit
8afdfc71d6
@ -1,4 +1,3 @@
|
||||
pub mod elements;
|
||||
pub mod format;
|
||||
pub mod parser;
|
||||
pub mod tokens;
|
||||
pub mod parsing;
|
||||
pub use parsing::parser::Parser;
|
||||
|
@ -0,0 +1,4 @@
|
||||
pub mod elements;
|
||||
pub mod parser;
|
||||
pub mod placeholders;
|
||||
pub mod tokens;
|
@ -0,0 +1,62 @@
|
||||
use super::elements::*;
|
||||
use chrono::prelude::*;
|
||||
|
||||
macro_rules! block {
|
||||
($inner:expr) => {
|
||||
Element::Block(Box::new($inner))
|
||||
};
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
macro_rules! inline {
|
||||
($inner:expr) => {
|
||||
Element::Inline(Box::new($inner))
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! subtext {
|
||||
($inner:expr) => {
|
||||
Element::SubText(Box::new($inner))
|
||||
};
|
||||
}
|
||||
|
||||
pub(crate) trait ProcessPlaceholders {
|
||||
fn process_placeholders(&mut self);
|
||||
}
|
||||
|
||||
const P_TOC: &str = "toc";
|
||||
const P_DATE: &str = "date";
|
||||
const P_TIME: &str = "time";
|
||||
const P_DATETIME: &str = "datetime";
|
||||
|
||||
impl ProcessPlaceholders for Document {
|
||||
/// parses all placeholders and assigns values to them
|
||||
fn process_placeholders(&mut self) {
|
||||
self.placeholders.iter().for_each(|p| {
|
||||
let mut pholder = p.lock().unwrap();
|
||||
match pholder.name.to_ascii_lowercase().as_str() {
|
||||
P_TOC => pholder.set_value(block!(Block::List(self.create_toc()))),
|
||||
P_DATE => pholder.set_value(subtext!(SubText::Plain(PlainText {
|
||||
value: get_date_string()
|
||||
}))),
|
||||
P_TIME => pholder.set_value(subtext!(SubText::Plain(PlainText {
|
||||
value: get_time_string()
|
||||
}))),
|
||||
P_DATETIME => pholder.set_value(subtext!(SubText::Plain(PlainText {
|
||||
value: format!("{} {}", get_date_string(), get_time_string())
|
||||
}))),
|
||||
_ => {}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn get_time_string() -> String {
|
||||
let now = Local::now();
|
||||
format!("{:02}:{:02}:{02}", now.hour(), now.minute(), now.second())
|
||||
}
|
||||
|
||||
fn get_date_string() -> String {
|
||||
let now = Local::now();
|
||||
format!("{:02}.{:02}.{:04}", now.day(), now.month(), now.year())
|
||||
}
|
Loading…
Reference in New Issue