aboutsummaryrefslogtreecommitdiffstats
path: root/askama_derive/src
diff options
context:
space:
mode:
Diffstat (limited to 'askama_derive/src')
-rw-r--r--askama_derive/src/lib.rs5
-rw-r--r--askama_derive/src/parser.rs14
-rw-r--r--askama_derive/src/path.rs5
3 files changed, 9 insertions, 15 deletions
diff --git a/askama_derive/src/lib.rs b/askama_derive/src/lib.rs
index 370c24d..153e352 100644
--- a/askama_derive/src/lib.rs
+++ b/askama_derive/src/lib.rs
@@ -66,10 +66,7 @@ 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 mut src = path::get_template_source(&meta.path);
- if src.ends_with('\n') {
- let _ = src.pop();
- }
+ let src = path::get_template_source(&meta.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 d466379..ad23cce 100644
--- a/askama_derive/src/parser.rs
+++ b/askama_derive/src/parser.rs
@@ -323,16 +323,10 @@ named!(block_include<Node>, do_parse!(
ws!(tag_s!("include")) >>
name: ws!(expr_str_lit) >>
nws: opt!(tag_s!("-")) >>
- ({
- let mut src = match name {
- Expr::StrLit(s) => path::get_template_source(s),
- _ => panic!("include path must be a string literal"),
- };
- if src.ends_with('\n') {
- let _ = src.pop();
- }
- Node::Include(WS(pws.is_some(), nws.is_some()), src)
- })
+ (Node::Include(WS(pws.is_some(), nws.is_some()), match name {
+ Expr::StrLit(s) => path::get_template_source(s),
+ _ => panic!("include path must be a string literal"),
+ }))
));
named!(block_node<Node>, do_parse!(
diff --git a/askama_derive/src/path.rs b/askama_derive/src/path.rs
index e48f7d7..28b1b17 100644
--- a/askama_derive/src/path.rs
+++ b/askama_derive/src/path.rs
@@ -46,6 +46,9 @@ pub fn get_template_source(tpl_file: &str) -> String {
};
let mut s = String::new();
f.read_to_string(&mut s).unwrap();
+ if s.ends_with('\n') {
+ let _ = s.pop();
+ }
s
}
@@ -56,7 +59,7 @@ mod tests {
#[test]
fn get_source() {
- assert_eq!(get_template_source("sub/b.html"), "bar\n");
+ assert_eq!(get_template_source("sub/b.html"), "bar");
}
#[test]