diff options
author | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2017-08-27 22:10:42 +0200 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2017-08-27 22:10:42 +0200 |
commit | 9f3b590206e3dfe33b7129b1c8ff010f60318cf2 (patch) | |
tree | 5411864d92ec220d9d4db8d9e40cda6df9b2b16f /askama_derive/src | |
parent | aeac47cee0e14b9fa38c01082876667f0ec8d874 (diff) | |
download | askama-9f3b590206e3dfe33b7129b1c8ff010f60318cf2.tar.gz askama-9f3b590206e3dfe33b7129b1c8ff010f60318cf2.tar.bz2 askama-9f3b590206e3dfe33b7129b1c8ff010f60318cf2.zip |
Move most of the code into new askama_shared crate
This makes it possible to share code between askama and askama_derive.
Diffstat (limited to '')
-rw-r--r-- | askama_derive/src/lib.rs | 16 | ||||
-rw-r--r-- | askama_shared/src/generator.rs (renamed from askama_derive/src/generator.rs) | 0 | ||||
-rw-r--r-- | askama_shared/src/parser.rs (renamed from askama_derive/src/parser.rs) | 0 | ||||
-rw-r--r-- | askama_shared/src/path.rs (renamed from askama_derive/src/path.rs) | 3 |
4 files changed, 6 insertions, 13 deletions
diff --git a/askama_derive/src/lib.rs b/askama_derive/src/lib.rs index 0564ccc..0333c06 100644 --- a/askama_derive/src/lib.rs +++ b/askama_derive/src/lib.rs @@ -1,7 +1,5 @@ -#[macro_use] -extern crate nom; +extern crate askama_shared as shared; extern crate proc_macro; -extern crate quote; extern crate syn; use proc_macro::TokenStream; @@ -9,10 +7,6 @@ use proc_macro::TokenStream; use std::borrow::Cow; use std::path::PathBuf; -mod generator; -mod parser; -mod path; - #[proc_macro_derive(Template, attributes(template))] pub fn derive_template(input: TokenStream) -> TokenStream { let ast = syn::parse_derive_input(&input.to_string()).unwrap(); @@ -35,16 +29,16 @@ fn build_template(ast: &syn::DeriveInput) -> String { let (path, src) = match meta.source { Source::Source(s) => (PathBuf::new(), Cow::Borrowed(s)), Source::Path(s) => { - let path = path::find_template_from_path(&s, None); - let src = path::get_template_source(&path); + let path = shared::path::find_template_from_path(&s, None); + let src = shared::path::get_template_source(&path); (path, Cow::Owned(src)) }, }; - let nodes = parser::parse(src.as_ref()); + let nodes = shared::parse(src.as_ref()); if meta.print == Print::Ast || meta.print == Print::All { println!("{:?}", nodes); } - let code = generator::generate(ast, &path, nodes); + let code = shared::generate(ast, &path, nodes); if meta.print == Print::Code || meta.print == Print::All { println!("{}", code); } diff --git a/askama_derive/src/generator.rs b/askama_shared/src/generator.rs index 82f3994..82f3994 100644 --- a/askama_derive/src/generator.rs +++ b/askama_shared/src/generator.rs diff --git a/askama_derive/src/parser.rs b/askama_shared/src/parser.rs index 8732f0e..8732f0e 100644 --- a/askama_derive/src/parser.rs +++ b/askama_shared/src/parser.rs diff --git a/askama_derive/src/path.rs b/askama_shared/src/path.rs index 3c04965..86bf6d7 100644 --- a/askama_derive/src/path.rs +++ b/askama_shared/src/path.rs @@ -43,8 +43,7 @@ pub fn find_template_from_path<'a>(path: &str, start_at: Option<&Path>) -> PathB } } -// Duplicated in askama -fn template_dir() -> PathBuf { +pub fn template_dir() -> PathBuf { let mut path = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()); path.push("templates"); path |