aboutsummaryrefslogtreecommitdiffstats
path: root/askama_derive/src/lib.rs
diff options
context:
space:
mode:
authorLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2018-06-21 12:13:56 +0200
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2018-06-21 12:13:56 +0200
commite09cdfaf1f9cca45ed320c3ad97f3502c48ff73d (patch)
treef2317f584defb86207ef4e404de1ec3e8a26f80b /askama_derive/src/lib.rs
parent56c050275b0066d0eaa77264b1a3bfcbc370b2bb (diff)
downloadaskama-e09cdfaf1f9cca45ed320c3ad97f3502c48ff73d.tar.gz
askama-e09cdfaf1f9cca45ed320c3ad97f3502c48ff73d.tar.bz2
askama-e09cdfaf1f9cca45ed320c3ad97f3502c48ff73d.zip
Let build_template() own the template source
Diffstat (limited to 'askama_derive/src/lib.rs')
-rw-r--r--askama_derive/src/lib.rs11
1 files changed, 9 insertions, 2 deletions
diff --git a/askama_derive/src/lib.rs b/askama_derive/src/lib.rs
index 0e372ed..a2b4ace 100644
--- a/askama_derive/src/lib.rs
+++ b/askama_derive/src/lib.rs
@@ -11,8 +11,9 @@ mod input;
mod generator;
mod parser;
-use input::Print;
+use input::{Print, Source};
use proc_macro::TokenStream;
+use shared::path;
#[proc_macro_derive(Template, attributes(template))]
pub fn derive_template(input: TokenStream) -> TokenStream {
@@ -33,10 +34,16 @@ pub fn derive_template(input: TokenStream) -> TokenStream {
/// value as passed to the `template()` attribute.
fn build_template(ast: &syn::DeriveInput) -> String {
let input = input::TemplateInput::new(ast);
- let nodes = parser::parse(input.source.as_ref());
+ let source = match input.meta.source {
+ Source::Source(ref s) => s.clone(),
+ Source::Path(_) => path::get_template_source(&input.path)
+ };
+
+ let nodes = parser::parse(&source);
if input.meta.print == Print::Ast || input.meta.print == Print::All {
println!("{:?}", nodes);
}
+
let code = generator::generate(&input, &nodes);
if input.meta.print == Print::Code || input.meta.print == Print::All {
println!("{}", code);