aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--askama_derive/src/lib.rs3
-rw-r--r--askama_derive/src/parser.rs3
-rw-r--r--askama_derive/src/path.rs6
3 files changed, 7 insertions, 5 deletions
diff --git a/askama_derive/src/lib.rs b/askama_derive/src/lib.rs
index 153e352..5ee5a4c 100644
--- a/askama_derive/src/lib.rs
+++ b/askama_derive/src/lib.rs
@@ -66,7 +66,8 @@ fn get_template_meta(ast: &syn::DeriveInput) -> TemplateMeta {
/// value as passed to the `template()` attribute.
fn build_template(ast: &syn::DeriveInput) -> String {
let meta = get_template_meta(ast);
- let src = path::get_template_source(&meta.path);
+ let path = path::find_template_from_path(&meta.path, None);
+ let src = path::get_template_source(&path);
let nodes = parser::parse(&src);
if meta.print == "ast" || meta.print == "all" {
println!("{:?}", nodes);
diff --git a/askama_derive/src/parser.rs b/askama_derive/src/parser.rs
index ad23cce..767371b 100644
--- a/askama_derive/src/parser.rs
+++ b/askama_derive/src/parser.rs
@@ -1,5 +1,6 @@
use nom::{self, IResult};
use path;
+use std::path::Path;
use std::str;
#[derive(Debug)]
@@ -324,7 +325,7 @@ named!(block_include<Node>, do_parse!(
name: ws!(expr_str_lit) >>
nws: opt!(tag_s!("-")) >>
(Node::Include(WS(pws.is_some(), nws.is_some()), match name {
- Expr::StrLit(s) => path::get_template_source(s),
+ Expr::StrLit(s) => path::get_template_source(Path::new(s)),
_ => panic!("include path must be a string literal"),
}))
));
diff --git a/askama_derive/src/path.rs b/askama_derive/src/path.rs
index 28b1b17..b51f5f3 100644
--- a/askama_derive/src/path.rs
+++ b/askama_derive/src/path.rs
@@ -33,9 +33,9 @@ pub fn find_template_from_path<'a>(path: &str, start_at: Option<&str>) -> PathBu
}
}
-pub fn get_template_source(tpl_file: &str) -> String {
+pub fn get_template_source(tpl_path: &Path) -> String {
let mut path = template_dir();
- path.push(Path::new(tpl_file));
+ path.push(tpl_path);
let mut f = match File::open(&path) {
Err(_) => {
let msg = format!("unable to open template file '{}'",
@@ -59,7 +59,7 @@ mod tests {
#[test]
fn get_source() {
- assert_eq!(get_template_source("sub/b.html"), "bar");
+ assert_eq!(get_template_source(Path::new("sub/b.html")), "bar");
}
#[test]