aboutsummaryrefslogtreecommitdiffstats
path: root/askama_shared/src/lib.rs
diff options
context:
space:
mode:
authorLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2020-01-29 21:49:42 +0100
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2020-01-29 21:49:44 +0100
commit4587ba6ff7d4d65576a9125e067828a131ac0e4d (patch)
tree9bbe96c9cd07fc49353722afcd1242c1088bd382 /askama_shared/src/lib.rs
parent84a1960489c9c92ef898eb7617061035df39ac42 (diff)
downloadaskama-4587ba6ff7d4d65576a9125e067828a131ac0e4d.tar.gz
askama-4587ba6ff7d4d65576a9125e067828a131ac0e4d.tar.bz2
askama-4587ba6ff7d4d65576a9125e067828a131ac0e4d.zip
Move code generation into askama_shared
Diffstat (limited to '')
-rw-r--r--askama_shared/src/lib.rs39
1 files changed, 38 insertions, 1 deletions
diff --git a/askama_shared/src/lib.rs b/askama_shared/src/lib.rs
index fa4a9a0..0e8664d 100644
--- a/askama_shared/src/lib.rs
+++ b/askama_shared/src/lib.rs
@@ -15,8 +15,14 @@ pub use askama_escape::MarkupDisplay;
mod error;
pub use crate::error::{Error, Result};
pub mod filters;
+#[doc(hidden)]
+pub mod generator;
pub mod helpers;
+#[doc(hidden)]
+pub mod heritage;
+#[doc(hidden)]
pub mod input;
+#[doc(hidden)]
pub mod parser;
#[derive(Debug)]
@@ -240,6 +246,31 @@ where
vals.iter().map(|s| s.to_string()).collect()
}
+#[allow(clippy::match_wild_err_arm)]
+pub fn get_template_source(tpl_path: &Path) -> String {
+ match fs::read_to_string(tpl_path) {
+ Err(_) => panic!(
+ "unable to open template file '{}'",
+ tpl_path.to_str().unwrap()
+ ),
+ Ok(mut source) => {
+ if source.ends_with('\n') {
+ let _ = source.pop();
+ }
+ source
+ }
+ }
+}
+
+#[derive(Clone, Copy, Debug)]
+pub struct Integrations {
+ pub actix: bool,
+ pub gotham: bool,
+ pub iron: bool,
+ pub rocket: bool,
+ pub warp: bool,
+}
+
static CONFIG_FILE_NAME: &str = "askama.toml";
static DEFAULT_SYNTAX_NAME: &str = "default";
static DEFAULT_ESCAPERS: &[(&[&str], &str)] = &[
@@ -256,6 +287,12 @@ mod tests {
use std::path::{Path, PathBuf};
#[test]
+ fn get_source() {
+ let path = Config::new("").find_template("b.html", None);
+ assert_eq!(get_template_source(&path), "bar");
+ }
+
+ #[test]
fn test_default_config() {
let mut root = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
root.push("templates");
@@ -293,7 +330,7 @@ mod tests {
fn find_relative_nonexistent() {
let config = Config::new("");
let root = config.find_template("a.html", None);
- config.find_template("b.html", Some(&root));
+ config.find_template("c.html", Some(&root));
}
#[test]