Skip to content

Commit

Permalink
Move Iron integration into a separate askama_iron crate
Browse files Browse the repository at this point in the history
  • Loading branch information
djc committed Jan 29, 2020
1 parent 75f32d3 commit ff24eef
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 28 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/rust.yml
Expand Up @@ -34,7 +34,7 @@ jobs:
with:
command: test

stable-integrations:
Actix-Web:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
Expand All @@ -44,10 +44,10 @@ jobs:
toolchain: stable
override: true
- run: |
cd testing
cargo test --features full
cargo test --package askama_actix --all-targets
cargo clippy --package askama_actix --all-targets -- -D warnings
Actix-Web:
Gotham:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
Expand All @@ -58,10 +58,10 @@ jobs:
override: true
components: clippy
- run: |
cargo test --package askama_actix --all-targets
cargo clippy --package askama_actix --all-targets -- -D warnings
cargo test --package askama_gotham --all-targets
cargo clippy --package askama_gotham --all-targets -- -D warnings
Gotham:
Iron:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
Expand All @@ -72,8 +72,8 @@ jobs:
override: true
components: clippy
- run: |
cargo test --package askama_gotham --all-targets
cargo clippy --package askama_gotham --all-targets -- -D warnings
cargo test --package askama_iron --all-targets
cargo clippy --package askama_iron --all-targets -- -D warnings
Rocket:
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Expand Up @@ -5,6 +5,7 @@ members = [
"askama_gotham",
"askama_derive",
"askama_escape",
"askama_iron",
"askama_rocket",
"askama_shared",
"testing",
Expand Down
3 changes: 1 addition & 2 deletions askama/Cargo.toml
Expand Up @@ -24,7 +24,7 @@ humansize = ["askama_shared/humansize"]
serde-json = ["askama_shared/json"]
serde-yaml = ["askama_shared/yaml"]
num-traits = ["askama_shared/num-traits"]
with-iron = ["iron", "askama_derive/iron"]
with-iron = ["askama_derive/iron"]
with-rocket = ["askama_derive/rocket"]
with-actix-web = ["askama_derive/actix-web"]
with-gotham = ["askama_derive/gotham"]
Expand All @@ -33,7 +33,6 @@ with-gotham = ["askama_derive/gotham"]
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 }
mime = { version = "0.3", optional = true }
mime_guess = { version = "2.0.0-alpha", optional = true }

Expand Down
7 changes: 0 additions & 7 deletions askama/src/lib.rs
Expand Up @@ -516,13 +516,6 @@ pub use crate::shared::helpers;
pub use crate::shared::{read_config_file, Error, MarkupDisplay, Result};
pub use askama_derive::*;

#[cfg(feature = "with-iron")]
pub mod iron {
pub use iron::headers::ContentType;
pub use iron::modifier::Modifier;
pub use iron::response::Response;
}

pub mod mime {
#[cfg(all(feature = "mime_guess", feature = "mime"))]
pub fn extension_to_mime_type(ext: &str) -> mime_guess::Mime {
Expand Down
8 changes: 4 additions & 4 deletions askama_derive/src/generator.rs
Expand Up @@ -191,12 +191,12 @@ impl<'a> Generator<'a> {
fn impl_modifier_response(&mut self, buf: &mut Buffer) {
self.write_header(
buf,
"::askama::iron::Modifier<::askama::iron::Response>",
"::askama_iron::Modifier<::askama_iron::Response>",
None,
);
buf.writeln("fn modify(self, res: &mut ::askama::iron::Response) {");
buf.writeln("fn modify(self, res: &mut ::askama_iron::Response) {");
buf.writeln(
"res.body = Some(Box::new(::askama::Template::render(&self).unwrap().into_bytes()));",
"res.body = Some(Box::new(::askama_iron::Template::render(&self).unwrap().into_bytes()));",
);

let ext = self
Expand All @@ -206,7 +206,7 @@ impl<'a> Generator<'a> {
.map_or("", |s| s.to_str().unwrap_or(""));
match ext {
"html" | "htm" => {
buf.writeln("::askama::iron::ContentType::html().0.modify(res);");
buf.writeln("::askama_iron::ContentType::html().0.modify(res);");
}
_ => (),
};
Expand Down
17 changes: 17 additions & 0 deletions askama_iron/Cargo.toml
@@ -0,0 +1,17 @@
[package]
name = "askama_iron"
version = "0.9.0"
authors = ["Dirkjan Ochtman <dirkjan@ochtman.nl>"]
description = "Iron 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-iron"] }
iron = { version = ">= 0.5, < 0.7" }
3 changes: 3 additions & 0 deletions askama_iron/src/lib.rs
@@ -0,0 +1,3 @@
pub use askama::*;

pub use iron::{headers::ContentType, modifier::Modifier, Response};
File renamed without changes.
1 change: 1 addition & 0 deletions askama_iron/templates/hello.txt
@@ -0,0 +1 @@
Hello, {{ name }}!
1 change: 0 additions & 1 deletion testing/tests/iron.rs → askama_iron/tests/basic.rs
@@ -1,4 +1,3 @@
#![cfg(feature = "iron")]
use askama::Template;
use iron::{status, Response};

Expand Down
6 changes: 1 addition & 5 deletions testing/Cargo.toml
Expand Up @@ -6,14 +6,10 @@ workspace = ".."
edition = "2018"

[features]
default = []
full = ["with-iron", "serde-json"]
serde-json = ["serde_json", "askama/serde-json"]
with-iron = ["iron", "askama/with-iron"]
default = ["serde_json", "askama/serde-json"]

[dependencies]
askama = { path = "../askama", version = "*" }
iron = { version = "0.6", optional = true }
serde_json = { version = "1.0", optional = true }

[dev-dependencies]
Expand Down

0 comments on commit ff24eef

Please sign in to comment.