You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

templates.rs 581B

12345678910111213141516171819202122
  1. use lazy_static::lazy_static;
  2. use tera::{Context, Tera};
  3. use tide::Result;
  4. lazy_static! {
  5. pub static ref TEMPLATES: Tera = {
  6. let mut tera = match Tera::new("templates/**/*.html") {
  7. Ok(t) => t,
  8. Err(e) => {
  9. println!("Parsing error(s): {}", e);
  10. ::std::process::exit(1);
  11. }
  12. };
  13. tera.autoescape_on(vec!["html", ".sql"]);
  14. tera
  15. };
  16. }
  17. pub fn render_template(template: &str, context: &Context) -> Result<String> {
  18. let html = TEMPLATES.render(template, &context)?;
  19. Ok(html)
  20. }