aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2016-12-23 09:53:46 +0100
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2016-12-23 09:53:46 +0100
commitdf8b05d0a4243b0d0021871e5cab4269d89b1e0c (patch)
tree99c9ee8d869a8be4f5e396db8b7dbfbcf5a788e4
parent062500ef0c4b586dfe0a7e9508f0b11d4fd55703 (diff)
downloadaskama-df8b05d0a4243b0d0021871e5cab4269d89b1e0c.tar.gz
askama-df8b05d0a4243b0d0021871e5cab4269d89b1e0c.tar.bz2
askama-df8b05d0a4243b0d0021871e5cab4269d89b1e0c.zip
Get template from Cargo manifest-relative source
Diffstat (limited to '')
-rw-r--r--askama_codegen/src/lib.rs9
-rw-r--r--askama_test/templates/simple.html (renamed from askama_test/tests/simple.html)0
2 files changed, 7 insertions, 2 deletions
diff --git a/askama_codegen/src/lib.rs b/askama_codegen/src/lib.rs
index 4a17b18..b325bae 100644
--- a/askama_codegen/src/lib.rs
+++ b/askama_codegen/src/lib.rs
@@ -10,6 +10,7 @@ extern crate syn;
use proc_macro::TokenStream;
use std::fs::File;
use std::io::Read;
+use std::path::{Path, PathBuf};
fn get_path_from_attrs(attrs: &Vec<syn::Attribute>) -> String {
for attr in attrs {
@@ -39,7 +40,11 @@ fn get_path_from_attrs(attrs: &Vec<syn::Attribute>) -> String {
panic!("template annotation not found");
}
-fn get_template_source(path: &str) -> String {
+fn get_template_source(tpl_file: &str) -> String {
+ let root = ::std::env::var("CARGO_MANIFEST_DIR").unwrap();
+ let mut path = PathBuf::from(root);
+ path.push("templates");
+ path.push(Path::new(tpl_file));
let mut f = File::open(path).unwrap();
let mut s = String::new();
f.read_to_string(&mut s).unwrap();
@@ -64,7 +69,7 @@ pub fn derive_template(input: TokenStream) -> TokenStream {
let expanded = quote! {
impl #impl_generics askama::Template for #name #ty_generics #where_clause {
fn render(&self) -> String {
- src
+ #src.into()
}
}
};
diff --git a/askama_test/tests/simple.html b/askama_test/templates/simple.html
index e544306..e544306 100644
--- a/askama_test/tests/simple.html
+++ b/askama_test/templates/simple.html