diff options
-rw-r--r-- | .github/workflows/rust.yml | 7 | ||||
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | askama/Cargo.toml | 3 | ||||
-rw-r--r-- | askama/src/lib.rs | 19 | ||||
-rw-r--r-- | askama_derive/src/generator.rs | 8 | ||||
-rw-r--r-- | askama_rocket/Cargo.toml | 17 | ||||
-rw-r--r-- | askama_rocket/src/lib.rs | 16 | ||||
-rw-r--r-- | askama_rocket/templates/hello.html | 1 | ||||
-rw-r--r-- | askama_rocket/tests/basic.rs (renamed from testing/tests/rocket.rs) | 1 | ||||
-rw-r--r-- | testing/Cargo.toml | 2 |
10 files changed, 44 insertions, 31 deletions
diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index a6da4c6..fd0c6b4 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -61,7 +61,7 @@ jobs: cargo test --package askama_actix --all-targets cargo clippy --package askama_actix --all-targets -- -D warnings - nightly: + Rocket: runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 @@ -70,9 +70,10 @@ jobs: profile: minimal toolchain: nightly override: true + components: clippy - run: | - cd testing - cargo test --features with-rocket + cargo test --package askama_rocket --all-targets + cargo clippy --package askama_rocket --all-targets -- -D warnings lint: runs-on: ubuntu-latest @@ -4,6 +4,7 @@ members = [ "askama_actix", "askama_derive", "askama_escape", + "askama_rocket", "askama_shared", "testing", ] diff --git a/askama/Cargo.toml b/askama/Cargo.toml index ed729f7..fa0978a 100644 --- a/askama/Cargo.toml +++ b/askama/Cargo.toml @@ -25,7 +25,7 @@ serde-json = ["askama_shared/json"] serde-yaml = ["askama_shared/yaml"] num-traits = ["askama_shared/num-traits"] with-iron = ["iron", "askama_derive/iron"] -with-rocket = ["rocket", "askama_derive/rocket"] +with-rocket = ["askama_derive/rocket"] with-actix-web = ["askama_derive/actix-web"] with-gotham = ["gotham", "askama_derive/gotham", "hyper", "mime", "mime_guess"] @@ -34,7 +34,6 @@ askama_derive = { version = "0.9.0", path = "../askama_derive" } askama_escape = { version = "0.3.0", path = "../askama_escape" } askama_shared = { version = "0.9.0", path = "../askama_shared", default-features = false } iron = { version = ">= 0.5, < 0.7", optional = true } -rocket = { version = "0.4", default-features = false, optional = true } mime = { version = "0.3", optional = true } mime_guess = { version = "2.0.0-alpha", optional = true } gotham = { version = "0.3", default-features = false, optional = true } diff --git a/askama/src/lib.rs b/askama/src/lib.rs index 7991185..8e9eebe 100644 --- a/askama/src/lib.rs +++ b/askama/src/lib.rs @@ -523,25 +523,6 @@ pub mod iron { pub use iron::response::Response; } -#[cfg(feature = "with-rocket")] -pub mod rocket { - use rocket::http::{ContentType, Status}; - pub use rocket::request::Request; - use rocket::response::Response; - use std::io::Cursor; - - pub use rocket::response::{Responder, Result}; - - pub fn respond<T: super::Template>(t: &T, ext: &str) -> Result<'static> { - let rsp = t.render().map_err(|_| Status::InternalServerError)?; - let ctype = ContentType::from_extension(ext).ok_or(Status::InternalServerError)?; - Response::build() - .header(ctype) - .sized_body(Cursor::new(rsp)) - .ok() - } -} - pub mod mime { #[cfg(all(feature = "mime_guess", feature = "mime"))] pub fn extension_to_mime_type(ext: &str) -> mime_guess::Mime { diff --git a/askama_derive/src/generator.rs b/askama_derive/src/generator.rs index 430afb8..0d77c16 100644 --- a/askama_derive/src/generator.rs +++ b/askama_derive/src/generator.rs @@ -221,19 +221,19 @@ impl<'a> Generator<'a> { let param = syn::GenericParam::Lifetime(syn::LifetimeDef::new(lifetime)); self.write_header( buf, - "::askama::rocket::Responder<'askama>", + "::askama_rocket::Responder<'askama>", Some(vec![param]), ); buf.writeln( - "fn respond_to(self, _: &::askama::rocket::Request) \ - -> ::askama::rocket::Result<'askama> {", + "fn respond_to(self, _: &::askama_rocket::Request) \ + -> ::askama_rocket::Result<'askama> {", ); let ext = match self.input.path.extension() { Some(s) => s.to_str().unwrap(), None => "txt", }; - buf.writeln(&format!("::askama::rocket::respond(&self, {:?})", ext)); + buf.writeln(&format!("::askama_rocket::respond(&self, {:?})", ext)); buf.writeln("}"); buf.writeln("}"); diff --git a/askama_rocket/Cargo.toml b/askama_rocket/Cargo.toml new file mode 100644 index 0000000..e557a38 --- /dev/null +++ b/askama_rocket/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "askama_rocket" +version = "0.9.0" +authors = ["Dirkjan Ochtman <dirkjan@ochtman.nl>"] +description = "Rocket integration for Askama templates" +documentation = "https://docs.rs/askama" +keywords = ["markup", "template", "jinja2", "html"] +categories = ["template-engine"] +homepage = "https://github.com/djc/askama" +repository = "https://github.com/djc/askama" +license = "MIT OR Apache-2.0" +workspace = ".." +edition = "2018" + +[dependencies] +askama = { version = "0.9.0", path = "../askama", features = ["with-rocket", "mime", "mime_guess"] } +rocket = { version = "0.4", default-features = false } diff --git a/askama_rocket/src/lib.rs b/askama_rocket/src/lib.rs new file mode 100644 index 0000000..6db3b7b --- /dev/null +++ b/askama_rocket/src/lib.rs @@ -0,0 +1,16 @@ +use std::io::Cursor; + +pub use askama::*; +use rocket::http::{ContentType, Status}; +pub use rocket::request::Request; +use rocket::response::Response; +pub use rocket::response::{Responder, Result}; + +pub fn respond<T: Template>(t: &T, ext: &str) -> Result<'static> { + let rsp = t.render().map_err(|_| Status::InternalServerError)?; + let ctype = ContentType::from_extension(ext).ok_or(Status::InternalServerError)?; + Response::build() + .header(ctype) + .sized_body(Cursor::new(rsp)) + .ok() +} diff --git a/askama_rocket/templates/hello.html b/askama_rocket/templates/hello.html new file mode 100644 index 0000000..8149be7 --- /dev/null +++ b/askama_rocket/templates/hello.html @@ -0,0 +1 @@ +Hello, {{ name }}! diff --git a/testing/tests/rocket.rs b/askama_rocket/tests/basic.rs index 3dbc357..0671c4c 100644 --- a/testing/tests/rocket.rs +++ b/askama_rocket/tests/basic.rs @@ -1,4 +1,3 @@ -#![cfg(feature = "with-rocket")] #![feature(proc_macro_hygiene, decl_macro)] #[macro_use] diff --git a/testing/Cargo.toml b/testing/Cargo.toml index e7b9668..424dd73 100644 --- a/testing/Cargo.toml +++ b/testing/Cargo.toml @@ -9,14 +9,12 @@ edition = "2018" default = [] full = ["with-iron", "serde-json", "with-gotham"] serde-json = ["serde_json", "askama/serde-json"] -with-rocket = ["rocket", "askama/with-rocket"] with-iron = ["iron", "askama/with-iron"] with-gotham = ["gotham", "askama/with-gotham", "mime", "hyper"] [dependencies] askama = { path = "../askama", version = "*" } iron = { version = "0.6", optional = true } -rocket = { version = "0.4", default-features = false, optional = true } serde_json = { version = "1.0", optional = true } gotham = { version = "0.3", default-features = false, optional = true } mime = { version = "0.3", optional = true } |