diff options
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | askama/Cargo.toml | 6 | ||||
-rw-r--r-- | askama/src/lib.rs | 34 | ||||
-rw-r--r-- | askama_derive/Cargo.toml | 7 | ||||
-rw-r--r-- | askama_derive/src/lib.rs | 16 | ||||
-rw-r--r-- | askama_shared/Cargo.toml | 19 | ||||
-rw-r--r-- | askama_shared/src/filters/json.rs (renamed from askama/src/filters/json.rs) | 0 | ||||
-rw-r--r-- | askama_shared/src/filters/mod.rs (renamed from askama/src/filters/mod.rs) | 0 | ||||
-rw-r--r-- | askama_shared/src/generator.rs (renamed from askama_derive/src/generator.rs) | 0 | ||||
-rw-r--r-- | askama_shared/src/lib.rs | 29 | ||||
-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 | ||||
-rw-r--r-- | askama_shared/templates/a.html (renamed from askama_derive/templates/a.html) | 0 | ||||
-rw-r--r-- | askama_shared/templates/sub/b.html (renamed from askama_derive/templates/sub/b.html) | 0 | ||||
-rw-r--r-- | askama_shared/templates/sub/c.html (renamed from askama_derive/templates/sub/c.html) | 0 | ||||
-rw-r--r-- | askama_shared/templates/sub/sub1/d.html (renamed from askama_derive/templates/sub/sub1/d.html) | 0 |
16 files changed, 66 insertions, 50 deletions
@@ -1,2 +1,2 @@ [workspace] -members = ["askama", "askama_derive", "testing"] +members = ["askama", "askama_derive", "askama_shared", "testing"] diff --git a/askama/Cargo.toml b/askama/Cargo.toml index 7e90e85..cf3a50e 100644 --- a/askama/Cargo.toml +++ b/askama/Cargo.toml @@ -17,17 +17,15 @@ travis-ci = { repository = "djc/askama" } [features] default = [] -serde-json = ["serde", "serde_json"] +serde-json = ["askama_shared/serde-json"] with-iron = ["iron", "askama_derive/iron"] with-rocket = ["rocket", "askama_derive/rocket"] [dependencies] askama_derive = { path = "../askama_derive", version = "0.3.4" } -error-chain = "0.10" +askama_shared = { version = "0.3.4", path = "../askama_shared" } iron = { version = "0.5", optional = true } rocket = { version = "0.3", optional = true } -serde = { version = "1.0", optional = true } -serde_json = { version = "1.0", optional = true } [package.metadata.docs.rs] features = [ "serde-json" ] diff --git a/askama/src/lib.rs b/askama/src/lib.rs index 70202f5..25dff78 100644 --- a/askama/src/lib.rs +++ b/askama/src/lib.rs @@ -213,19 +213,13 @@ #![allow(unused_imports)] #[macro_use] extern crate askama_derive; -#[macro_use] -extern crate error_chain; +extern crate askama_shared as shared; -#[cfg(feature = "serde-json")] -extern crate serde; -#[cfg(feature = "serde-json")] -extern crate serde_json; +use shared::path; -use std::env; -use std::fmt; use std::fs::{self, DirEntry}; use std::io; -use std::path::{Path, PathBuf}; +use std::path::Path; /// Main `Template` trait; implementations are generally derived pub trait Template { @@ -239,9 +233,9 @@ pub trait Template { } } -pub mod filters; +pub use shared::filters; pub use askama_derive::*; -pub use errors::Result; +pub use shared::Result; #[cfg(feature = "with-iron")] pub mod iron { @@ -258,13 +252,6 @@ pub mod rocket { pub use self::rocket::response::{Responder, Response}; } -// Duplicates askama_derive::path::template_dir() -fn template_dir() -> PathBuf { - let mut path = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()); - path.push("templates"); - path -} - fn visit_dirs(dir: &Path, cb: &Fn(&DirEntry)) -> io::Result<()> { if dir.is_dir() { for entry in try!(fs::read_dir(dir)) { @@ -290,16 +277,7 @@ fn visit_dirs(dir: &Path, cb: &Fn(&DirEntry)) -> io::Result<()> { /// that have templates, to make sure the crate gets rebuilt when template /// source code changes. pub fn rerun_if_templates_changed() { - visit_dirs(&template_dir(), &|e: &DirEntry| { + visit_dirs(&path::template_dir(), &|e: &DirEntry| { println!("cargo:rerun-if-changed={}", e.path().to_str().unwrap()); }).unwrap(); } - -mod errors { - error_chain! { - foreign_links { - Fmt(::std::fmt::Error); - Json(::serde_json::Error) #[cfg(feature = "serde-json")]; - } - } -} diff --git a/askama_derive/Cargo.toml b/askama_derive/Cargo.toml index 61263be..66610ea 100644 --- a/askama_derive/Cargo.toml +++ b/askama_derive/Cargo.toml @@ -13,10 +13,9 @@ proc-macro = true [features] default = [] -iron = [] -rocket = [] +iron = ["askama_shared/iron"] +rocket = ["askama_shared/rocket"] [dependencies] -nom = "3" -quote = "0.3" +askama_shared = { version = "0.3.4", path = "../askama_shared" } syn = "0.11" 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_shared/Cargo.toml b/askama_shared/Cargo.toml new file mode 100644 index 0000000..6ad2bff --- /dev/null +++ b/askama_shared/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "askama_shared" +version = "0.3.4" +authors = ["Dirkjan Ochtman <dirkjan@ochtman.nl>"] +workspace = ".." + +[features] +default = [] +serde-json = ["serde", "serde_json"] +iron = [] +rocket = [] + +[dependencies] +error-chain = "0.10" +nom = "3" +quote = "0.3" +serde = { version = "1.0", optional = true } +serde_json = { version = "1.0", optional = true } +syn = "0.11" diff --git a/askama/src/filters/json.rs b/askama_shared/src/filters/json.rs index 4443fb4..4443fb4 100644 --- a/askama/src/filters/json.rs +++ b/askama_shared/src/filters/json.rs diff --git a/askama/src/filters/mod.rs b/askama_shared/src/filters/mod.rs index 73b311d..73b311d 100644 --- a/askama/src/filters/mod.rs +++ b/askama_shared/src/filters/mod.rs 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_shared/src/lib.rs b/askama_shared/src/lib.rs new file mode 100644 index 0000000..1ee19cf --- /dev/null +++ b/askama_shared/src/lib.rs @@ -0,0 +1,29 @@ +#[macro_use] +extern crate error_chain; +#[macro_use] +extern crate nom; +extern crate quote; +extern crate syn; + +#[cfg(feature = "serde-json")] +extern crate serde; +#[cfg(feature = "serde-json")] +extern crate serde_json; + +pub use errors::Result; +pub mod filters; +pub mod path; +pub use parser::parse; +pub use generator::generate; + +mod generator; +mod parser; + +mod errors { + error_chain! { + foreign_links { + Fmt(::std::fmt::Error); + Json(::serde_json::Error) #[cfg(feature = "serde-json")]; + } + } +} 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 diff --git a/askama_derive/templates/a.html b/askama_shared/templates/a.html index 257cc56..257cc56 100644 --- a/askama_derive/templates/a.html +++ b/askama_shared/templates/a.html diff --git a/askama_derive/templates/sub/b.html b/askama_shared/templates/sub/b.html index 5716ca5..5716ca5 100644 --- a/askama_derive/templates/sub/b.html +++ b/askama_shared/templates/sub/b.html diff --git a/askama_derive/templates/sub/c.html b/askama_shared/templates/sub/c.html index 7601807..7601807 100644 --- a/askama_derive/templates/sub/c.html +++ b/askama_shared/templates/sub/c.html diff --git a/askama_derive/templates/sub/sub1/d.html b/askama_shared/templates/sub/sub1/d.html index fa11a6a..fa11a6a 100644 --- a/askama_derive/templates/sub/sub1/d.html +++ b/askama_shared/templates/sub/sub1/d.html |