diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index a263ea89..ff7bf6e0 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -35,9 +35,8 @@ jobs: strategy: matrix: package: [ - rinja, rinja_actix, rinja_axum, rinja_derive, rinja_derive_standalone, - rinja_parser, rinja_rocket, rinja_warp, testing, examples/actix-web-app, - fuzzing + examples/actix-web-app, fuzzing, rinja, rinja_derive, rinja_derive_standalone, + rinja_parser, testing, ] runs-on: ubuntu-latest steps: @@ -55,10 +54,7 @@ jobs: Docs: strategy: matrix: - package: [ - rinja, rinja_actix, rinja_axum, rinja_derive, - rinja_parser, rinja_rocket, rinja_warp, - ] + package: [rinja, rinja_derive, rinja_parser] runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -81,13 +77,11 @@ jobs: - run: | set -eu for PKG in \ - rinja rinja_actix rinja_axum rinja_derive rinja_derive_standalone \ - rinja_parser rinja_rocket rinja_warp testing examples/actix-web-app \ - fuzzing + examples/actix-web-app fuzzing rinja rinja_derive rinja_derive_standalone rinja_parser testing do cd "$PKG" echo "Testing: $PKG" - cargo fmt -- --check + cargo +nightly fmt -- --check cd - > /dev/null done @@ -150,8 +144,7 @@ jobs: - run: | set -eu for PKG in \ - rinja rinja_actix rinja_axum rinja_derive rinja_derive_standalone \ - rinja_parser rinja_rocket rinja_warp testing + examples/actix-web-app fuzzing rinja rinja_derive rinja_derive_standalone rinja_parser testing do cd "$PKG" cargo sort --check --check-format --grouped diff --git a/README.md b/README.md index 84d6dee1..c4d3e392 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,6 @@ if you want to try out rinja's code generation online. * Construct templates using a familiar, easy-to-use syntax * Benefit from the safety provided by Rust's type system * Template code is compiled into your crate for optimal performance -* Optional built-in support for Actix, Axum, Rocket, and warp web frameworks * Debugging features to assist you in template development * Templates must be valid UTF-8 and produce UTF-8 when rendered * Works on stable Rust diff --git a/book/src/SUMMARY.md b/book/src/SUMMARY.md index 284c6e62..dea508d1 100644 --- a/book/src/SUMMARY.md +++ b/book/src/SUMMARY.md @@ -7,5 +7,4 @@ - [Configuration](./configuration.md) - [Template syntax](./template_syntax.md) - [Filters](./filters.md) -- [Integrations](./integrations.md) - [Performance](./performance.md) diff --git a/book/src/integrations.md b/book/src/integrations.md deleted file mode 100644 index 591009a6..00000000 --- a/book/src/integrations.md +++ /dev/null @@ -1,54 +0,0 @@ -# Integrations - -## Rocket integration - -You can use the `rocket` integration with the [rinja_rocket] crate. - -In your template definitions, replace `rinja::Template` with -[`rinja_rocket::Template`][rinja_rocket]. - -See [the example](https://github.com/rinja-rs/rinja/blob/master/rinja_rocket/tests/basic.rs) -from the Rinja test suite for more on how to integrate. - -In case a run-time error occurs during templating, a `500 Internal Server -Error` `Status` value will be returned, so that this can be further -handled by your error catcher. - -## Actix-web integration - -You can use the `actix` integration with the [rinja_actix] crate. - -In your template definitions, replace `rinja::Template` with -[`rinja_actix::Template`][rinja_actix]. - -See [the example](https://github.com/rinja-rs/rinja/blob/master/rinja_actix/tests/basic.rs) -from the Rinja test suite for more on how to integrate. - -## Axum integration - -You can use the `axum` integration with the [rinja_axum] crate. - -In your template definitions, replace `rinja::Template` with -[`rinja_axum::Template`][rinja_axum]. - -See [the example](https://github.com/rinja-rs/rinja/blob/master/rinja_axum/tests/basic.rs) -from the Rinja test suite for more on how to integrate. - -In case of a run-time error occurring during templating, the response will be of the same -signature, with a status code of `500 Internal Server Error`, mime `*/*`, and an empty `Body`. -This preserves the response chain if any custom error handling needs to occur. - -## Warp integration - -You can use the `warp` integration with the [rinja_warp] crate. - -In your template definitions, replace `rinja::Template` with -[`rinja_warp::Template`][rinja_warp]. - -See [the example](https://github.com/rinja-rs/rinja/blob/master/rinja_warp/tests/warp.rs) -from the Rinja test suite for more on how to integrate. - -[rinja_rocket]: https://docs.rs/rinja_rocket -[rinja_actix]: https://docs.rs/rinja_actix -[rinja_axum]: https://docs.rs/rinja_axum -[rinja_warp]: https://docs.rs/rinja_warp diff --git a/book/src/introduction.md b/book/src/introduction.md index 73f848be..bfafb366 100644 --- a/book/src/introduction.md +++ b/book/src/introduction.md @@ -16,7 +16,6 @@ if you want to try out rinja's code generation online. * Construct templates using a familiar, easy-to-use syntax * Benefit from the safety provided by Rust's type system * Template code is compiled into your crate for optimal performance -* Optional built-in support for Actix, Axum, Rocket, and warp web frameworks * Debugging features to assist you in template development * Templates must be valid UTF-8 and produce UTF-8 when rendered * Works on stable Rust diff --git a/examples/actix-web-app/Cargo.toml b/examples/actix-web-app/Cargo.toml index 9bc93ae5..bac4b9df 100644 --- a/examples/actix-web-app/Cargo.toml +++ b/examples/actix-web-app/Cargo.toml @@ -10,18 +10,16 @@ edition = "2021" license = "MIT OR Apache-2.0" publish = false -[dependencies] -actix-web = { version = "4.8.0", default-features = false, features = ["macros"] } # This is an example application that uses both rinja as template engine, # and actix-web as your web-framework. -# rinja_actix makes it easy to use rinja templates as `Responder` of an actix-web request. -# The rendered template is simply the response of your handler! -rinja_actix = { version = "0.3.5", path = "../../rinja_actix" } -tokio = { version = "1.38.0", features = ["sync", "rt-multi-thread"] } +[dependencies] +actix-web = { version = "4.9.0", default-features = false, features = ["macros"] } +rinja = { version = "0.3.5", path = "../../rinja" } +tokio = { version = "1.41.1", features = ["sync", "rt-multi-thread"] } # serde and strum are used to parse (deserialize) and generate (serialize) information # between web requests, e.g. to share the selected display language. -serde = { version = "1.0.203", features = ["derive"] } +serde = { version = "1.0.215", features = ["derive"] } strum = { version = "0.26.3", features = ["derive"] } # These depenendies are simply used for a better user experience, having access logs in the @@ -29,4 +27,4 @@ strum = { version = "0.26.3", features = ["derive"] } env_logger = "0.11.3" log = "0.4.22" pretty-error-debug = "0.3.0" -thiserror = "1.0.61" +thiserror = "2.0.3" diff --git a/examples/actix-web-app/src/main.rs b/examples/actix-web-app/src/main.rs index b4a23248..9a2218e2 100644 --- a/examples/actix-web-app/src/main.rs +++ b/examples/actix-web-app/src/main.rs @@ -1,8 +1,10 @@ +use actix_web::http::header::ContentType; use actix_web::http::{Method, header}; +use actix_web::web::Html; use actix_web::{ App, HttpRequest, HttpResponse, HttpServer, Responder, Result, get, middleware, web, }; -use rinja_actix::Template; +use rinja::Template; use serde::Deserialize; use tokio::runtime; @@ -88,18 +90,13 @@ async fn not_found_handler(req: HttpRequest) -> Result { } if req.method() == Method::GET { - // In here we have to render the result to a string manually, because we don't want to - // generate a "status 200" result, but "status 404". In other cases you can simply return - // the template, wrapped in `Ok()`, and the request gets generated with "status 200", - // and the right MIME type. let tmpl = Tmpl { req, lang: Lang::default(), }; - // The MIME type was derived by rinja by the extension of the template file. Ok(HttpResponse::NotFound() - .append_header((header::CONTENT_TYPE, Tmpl::MIME_TYPE)) - .body(tmpl.to_string())) + .insert_header(ContentType::html()) + .body(tmpl.render().map_err(>::from)?)) } else { Ok(HttpResponse::MethodNotAllowed().finish()) } @@ -152,11 +149,16 @@ async fn index_handler( } let (lang,) = path.into_inner(); - Ok(Tmpl { + let template = Tmpl { req, lang, name: query.name, - }) + }; + Ok(Html::new( + template + .render() + .map_err(>::from)?, + )) } #[derive(Debug, Deserialize)] @@ -184,9 +186,14 @@ async fn greeting_handler( } let (lang,) = path.into_inner(); - Ok(Tmpl { + let template = Tmpl { req, lang, name: query.name, - }) + }; + Ok(Html::new( + template + .render() + .map_err(>::from)?, + )) } diff --git a/fuzzing/Cargo.toml b/fuzzing/Cargo.toml index d9731dd9..a7f14881 100644 --- a/fuzzing/Cargo.toml +++ b/fuzzing/Cargo.toml @@ -1,3 +1,6 @@ + +[workspace] +members = [".", "fuzz"] [package] name = "rinja_fuzzing" version = "0.1.0" @@ -8,12 +11,9 @@ publish = false [dependencies] fuzz = { path = "fuzz" } -arbitrary = "1.3.2" +arbitrary = "1.4.1" pretty-error-debug = "0.3.0" -thiserror = "1.0.63" - -[workspace] -members = [".", "fuzz"] +thiserror = "2.0.3" [profile.release] debug = 1 diff --git a/fuzzing/fuzz/Cargo.toml b/fuzzing/fuzz/Cargo.toml index 5e1cb308..be4796c2 100644 --- a/fuzzing/fuzz/Cargo.toml +++ b/fuzzing/fuzz/Cargo.toml @@ -19,7 +19,7 @@ rinja_parser = { path = "../../rinja_parser" } arbitrary = { version = "1.3.2", features = ["derive"] } html-escape = "0.2.13" libfuzzer-sys = "0.4.7" -thiserror = "1.0.63" +thiserror = "2.0.3" [[bin]] name = "all" diff --git a/rinja/Cargo.toml b/rinja/Cargo.toml index 90629a4b..b6a10ed2 100644 --- a/rinja/Cargo.toml +++ b/rinja/Cargo.toml @@ -28,13 +28,6 @@ config = ["rinja_derive/config"] serde_json = ["rinja_derive/serde_json", "dep:serde", "dep:serde_json"] urlencode = ["rinja_derive/urlencode", "dep:percent-encoding"] -# Please do not depend on the following features manually. -# Depend on the relevant integration crate instead! -with-actix-web = ["rinja_derive/with-actix-web"] -with-axum = ["rinja_derive/with-axum"] -with-rocket = ["rinja_derive/with-rocket"] -with-warp = ["rinja_derive/with-warp"] - [dependencies] rinja_derive = { version = "=0.3.5", path = "../rinja_derive" } diff --git a/rinja/src/lib.rs b/rinja/src/lib.rs index afe80f78..d750b79a 100644 --- a/rinja/src/lib.rs +++ b/rinja/src/lib.rs @@ -144,9 +144,6 @@ pub trait Template: fmt::Display + filters::FastWritable { /// [`render_into`]: Template::render_into /// [`write_into`]: Template::write_into const SIZE_HINT: usize; - - /// The MIME type (Content-Type) of the data that gets rendered by this Template - const MIME_TYPE: &'static str; } impl Template for &T { @@ -166,8 +163,6 @@ impl Template for &T { } const SIZE_HINT: usize = T::SIZE_HINT; - - const MIME_TYPE: &'static str = T::MIME_TYPE; } /// Object-safe wrapper trait around [`Template`] implementers @@ -185,9 +180,6 @@ pub trait DynTemplate { /// Provides a conservative estimate of the expanded length of the rendered template fn size_hint(&self) -> usize; - - /// The MIME type (Content-Type) of the data that gets rendered by this Template - fn mime_type(&self) -> &'static str; } impl DynTemplate for T { @@ -207,10 +199,6 @@ impl DynTemplate for T { fn size_hint(&self) -> usize { Self::SIZE_HINT } - - fn mime_type(&self) -> &'static str { - Self::MIME_TYPE - } } impl fmt::Display for dyn DynTemplate { @@ -261,8 +249,6 @@ mod tests { } const SIZE_HINT: usize = 4; - - const MIME_TYPE: &'static str = "text/plain; charset=utf-8"; } impl fmt::Display for Test { diff --git a/rinja_actix/.rustfmt.toml b/rinja_actix/.rustfmt.toml deleted file mode 120000 index a7ef950c..00000000 --- a/rinja_actix/.rustfmt.toml +++ /dev/null @@ -1 +0,0 @@ -../.rustfmt.toml \ No newline at end of file diff --git a/rinja_actix/Cargo.toml b/rinja_actix/Cargo.toml deleted file mode 100644 index 1908b832..00000000 --- a/rinja_actix/Cargo.toml +++ /dev/null @@ -1,38 +0,0 @@ -[workspace] -members = ["."] - -[package] -name = "rinja_actix" -version = "0.3.5" -description = "Actix-Web integration for Rinja templates" -documentation = "https://docs.rs/rinja" -keywords = ["markup", "template", "jinja2", "html"] -categories = ["template-engine"] -homepage = "https://github.com/rinja-rs/rinja" -repository = "https://github.com/rinja-rs/rinja" -license = "MIT OR Apache-2.0" -readme = "README.md" -edition = "2021" -rust-version = "1.80" - -[package.metadata.docs.rs] -all-features = true -rustdoc-args = ["--generate-link-to-definition", "--cfg=docsrs"] - -[features] -default = ["rinja/default"] -full = ["rinja/full"] -code-in-doc = ["rinja/code-in-doc"] -config = ["rinja/config"] -serde_json = ["rinja/serde_json"] -urlencode = ["rinja/urlencode"] - -[dependencies] -rinja = { version = "0.3.5", path = "../rinja", default-features = false, features = ["with-actix-web"] } - -actix-web = { version = "4", default-features = false } - -[dev-dependencies] -actix-rt = { version = "2", default-features = false } -actix-test = "0.1" -bytes = { version = "1" } diff --git a/rinja_actix/LICENSE-APACHE b/rinja_actix/LICENSE-APACHE deleted file mode 120000 index 965b606f..00000000 --- a/rinja_actix/LICENSE-APACHE +++ /dev/null @@ -1 +0,0 @@ -../LICENSE-APACHE \ No newline at end of file diff --git a/rinja_actix/LICENSE-MIT b/rinja_actix/LICENSE-MIT deleted file mode 120000 index 76219eb7..00000000 --- a/rinja_actix/LICENSE-MIT +++ /dev/null @@ -1 +0,0 @@ -../LICENSE-MIT \ No newline at end of file diff --git a/rinja_actix/README.md b/rinja_actix/README.md deleted file mode 100644 index 4cff059f..00000000 --- a/rinja_actix/README.md +++ /dev/null @@ -1,9 +0,0 @@ -# rinja_actix: Rinja integration with Actix-web - -[![Crates.io](https://img.shields.io/crates/v/rinja_actix?logo=rust&style=flat-square&logoColor=white "Crates.io")](https://crates.io/crates/rinja_actix) -[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/rinja-rs/rinja/rust.yml?branch=master&logo=github&style=flat-square&logoColor=white "GitHub Workflow Status")](https://github.com/rinja-rs/rinja/actions/workflows/rust.yml) -[![Book](https://img.shields.io/readthedocs/rinja?label=book&logo=readthedocs&style=flat-square&logoColor=white "Book")](https://rinja.readthedocs.io/) -[![docs.rs](https://img.shields.io/docsrs/rinja_actix?logo=docsdotrs&style=flat-square&logoColor=white "docs.rs")](https://docs.rs/rinja_actix/) - -Integration of the [Rinja](https://github.com/rinja-rs/rinja) templating engine in -code building on the Actix-web framework. diff --git a/rinja_actix/_typos.toml b/rinja_actix/_typos.toml deleted file mode 120000 index 2264b5db..00000000 --- a/rinja_actix/_typos.toml +++ /dev/null @@ -1 +0,0 @@ -../_typos.toml \ No newline at end of file diff --git a/rinja_actix/deny.toml b/rinja_actix/deny.toml deleted file mode 120000 index a65e17bb..00000000 --- a/rinja_actix/deny.toml +++ /dev/null @@ -1 +0,0 @@ -../deny.toml \ No newline at end of file diff --git a/rinja_actix/src/lib.rs b/rinja_actix/src/lib.rs deleted file mode 100644 index 29269c9f..00000000 --- a/rinja_actix/src/lib.rs +++ /dev/null @@ -1,49 +0,0 @@ -#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] -#![deny(elided_lifetimes_in_paths)] -#![deny(unreachable_pub)] - -use std::fmt; - -#[doc(no_inline)] -pub use actix_web; -use actix_web::body::BoxBody; -use actix_web::http::StatusCode; -use actix_web::http::header::HeaderValue; -use actix_web::{HttpResponse, HttpResponseBuilder, ResponseError}; -#[doc(no_inline)] -pub use rinja::*; - -/// Render a [`Template`] into a [`HttpResponse`], or render an error page. -#[must_use] -pub fn into_response(tmpl: &T) -> HttpResponse { - try_into_response(tmpl).unwrap_or_else(|err| HttpResponse::from_error(ActixError(err))) -} - -/// Try to render a [`Template`] into a [`HttpResponse`]. -pub fn try_into_response( - tmpl: &T, -) -> Result, Error> { - let value = tmpl.render()?; - Ok(HttpResponseBuilder::new(StatusCode::OK) - .content_type(HeaderValue::from_static(T::MIME_TYPE)) - .body(value)) -} - -/// Newtype to let `rinja::Error` implement `actix_web::ResponseError`. -struct ActixError(Error); - -impl fmt::Debug for ActixError { - #[inline] - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - ::fmt(&self.0, f) - } -} - -impl fmt::Display for ActixError { - #[inline] - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - ::fmt(&self.0, f) - } -} - -impl ResponseError for ActixError {} diff --git a/rinja_actix/templates/hello.html b/rinja_actix/templates/hello.html deleted file mode 100644 index 8149be7a..00000000 --- a/rinja_actix/templates/hello.html +++ /dev/null @@ -1 +0,0 @@ -Hello, {{ name }}! diff --git a/rinja_actix/tests/basic.rs b/rinja_actix/tests/basic.rs deleted file mode 100644 index 4cc6c453..00000000 --- a/rinja_actix/tests/basic.rs +++ /dev/null @@ -1,29 +0,0 @@ -use actix_web::http::header::CONTENT_TYPE; -use actix_web::web; -use bytes::Bytes; -use rinja_actix::Template; - -#[derive(Template)] -#[template(path = "hello.html")] -struct HelloTemplate<'a> { - name: &'a str, -} - -#[actix_rt::test] -async fn test_actix_web() { - let srv = actix_test::start(|| { - actix_web::App::new() - .service(web::resource("/").to(|| async { HelloTemplate { name: "world" } })) - }); - - let request = srv.get("/"); - let mut response = request.send().await.unwrap(); - assert!(response.status().is_success()); - assert_eq!( - response.headers().get(CONTENT_TYPE).unwrap(), - "text/html; charset=utf-8" - ); - - let bytes = response.body().await.unwrap(); - assert_eq!(bytes, Bytes::from_static("Hello, world!".as_ref())); -} diff --git a/rinja_actix/tomlfmt.toml b/rinja_actix/tomlfmt.toml deleted file mode 120000 index 053191cc..00000000 --- a/rinja_actix/tomlfmt.toml +++ /dev/null @@ -1 +0,0 @@ -../tomlfmt.toml \ No newline at end of file diff --git a/rinja_axum/.rustfmt.toml b/rinja_axum/.rustfmt.toml deleted file mode 120000 index a7ef950c..00000000 --- a/rinja_axum/.rustfmt.toml +++ /dev/null @@ -1 +0,0 @@ -../.rustfmt.toml \ No newline at end of file diff --git a/rinja_axum/Cargo.toml b/rinja_axum/Cargo.toml deleted file mode 100644 index 619837ba..00000000 --- a/rinja_axum/Cargo.toml +++ /dev/null @@ -1,40 +0,0 @@ -[workspace] -members = ["."] - -[package] -name = "rinja_axum" -version = "0.3.5" -edition = "2021" -rust-version = "1.80" -description = "Axum integration for Rinja templates" -keywords = ["markup", "template", "jinja2", "html", "axum"] -categories = ["template-engine"] -homepage = "https://github.com/rinja-rs/rinja" -repository = "https://github.com/rinja-rs/rinja" -documentation = "https://docs.rs/rinja" -license = "MIT OR Apache-2.0" -readme = "README.md" - -[package.metadata.docs.rs] -all-features = true -rustdoc-args = ["--generate-link-to-definition", "--cfg=docsrs"] - -[features] -default = ["rinja/default"] -full = ["rinja/full"] -code-in-doc = ["rinja/code-in-doc"] -config = ["rinja/config"] -serde_json = ["rinja/serde_json"] -urlencode = ["rinja/urlencode"] - -[dependencies] -rinja = { version = "0.3.5", path = "../rinja", default-features = false, features = ["with-axum"] } - -axum-core = "0.4" -http = "1.0" - -[dev-dependencies] -axum = { version = "0.7", default-features = false } -http-body-util = "0.1" -tokio = { version = "1.0", features = ["macros", "rt"] } -tower = { version = "0.5", features = ["util"] } diff --git a/rinja_axum/LICENSE-APACHE b/rinja_axum/LICENSE-APACHE deleted file mode 120000 index 965b606f..00000000 --- a/rinja_axum/LICENSE-APACHE +++ /dev/null @@ -1 +0,0 @@ -../LICENSE-APACHE \ No newline at end of file diff --git a/rinja_axum/LICENSE-MIT b/rinja_axum/LICENSE-MIT deleted file mode 120000 index 76219eb7..00000000 --- a/rinja_axum/LICENSE-MIT +++ /dev/null @@ -1 +0,0 @@ -../LICENSE-MIT \ No newline at end of file diff --git a/rinja_axum/README.md b/rinja_axum/README.md deleted file mode 100644 index f560c25a..00000000 --- a/rinja_axum/README.md +++ /dev/null @@ -1,9 +0,0 @@ -# rinja_axum: Rinja integration with Axum - -[![Crates.io](https://img.shields.io/crates/v/rinja_axum?logo=rust&style=flat-square&logoColor=white "Crates.io")](https://crates.io/crates/rinja_axum) -[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/rinja-rs/rinja/rust.yml?branch=master&logo=github&style=flat-square&logoColor=white "GitHub Workflow Status")](https://github.com/rinja-rs/rinja/actions/workflows/rust.yml) -[![Book](https://img.shields.io/readthedocs/rinja?label=book&logo=readthedocs&style=flat-square&logoColor=white "Book")](https://rinja.readthedocs.io/) -[![docs.rs](https://img.shields.io/docsrs/rinja_axum?logo=docsdotrs&style=flat-square&logoColor=white "docs.rs")](https://docs.rs/rinja_axum/) - -Integration of the [Rinja](https://github.com/rinja-rs/rinja) templating engine in -code building on the Axum web framework. diff --git a/rinja_axum/_typos.toml b/rinja_axum/_typos.toml deleted file mode 120000 index 2264b5db..00000000 --- a/rinja_axum/_typos.toml +++ /dev/null @@ -1 +0,0 @@ -../_typos.toml \ No newline at end of file diff --git a/rinja_axum/deny.toml b/rinja_axum/deny.toml deleted file mode 120000 index a65e17bb..00000000 --- a/rinja_axum/deny.toml +++ /dev/null @@ -1 +0,0 @@ -../deny.toml \ No newline at end of file diff --git a/rinja_axum/src/lib.rs b/rinja_axum/src/lib.rs deleted file mode 100644 index 897e3b7f..00000000 --- a/rinja_axum/src/lib.rs +++ /dev/null @@ -1,29 +0,0 @@ -#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] -#![deny(elided_lifetimes_in_paths)] -#![deny(unreachable_pub)] - -#[doc(no_inline)] -pub use axum_core; -use axum_core::response::{IntoResponse, Response}; -#[doc(no_inline)] -pub use rinja::*; - -/// Render a [`Template`] into a [`Response`], or render an error page. -#[must_use] -pub fn into_response(tmpl: &T) -> Response { - try_into_response(tmpl) - .map_err(|err| axum_core::response::ErrorResponse::from(err.to_string())) - .into_response() -} - -/// Try to render a [`Template`] into a [`Response`]. -pub fn try_into_response(tmpl: &T) -> Result { - let value = tmpl.render()?.into(); - Response::builder() - .header( - http::header::CONTENT_TYPE, - http::header::HeaderValue::from_static(T::MIME_TYPE), - ) - .body(value) - .map_err(|err| Error::Custom(err.into())) -} diff --git a/rinja_axum/templates/hello.html b/rinja_axum/templates/hello.html deleted file mode 100644 index 8149be7a..00000000 --- a/rinja_axum/templates/hello.html +++ /dev/null @@ -1 +0,0 @@ -Hello, {{ name }}! diff --git a/rinja_axum/tests/basic.rs b/rinja_axum/tests/basic.rs deleted file mode 100644 index b5510975..00000000 --- a/rinja_axum/tests/basic.rs +++ /dev/null @@ -1,34 +0,0 @@ -use axum::Router; -use axum::body::Body; -use axum::http::{Request, StatusCode}; -use axum::routing::get; -use http_body_util::BodyExt; -use rinja_axum::Template; -use tower::util::ServiceExt; - -#[derive(Template)] -#[template(path = "hello.html")] -struct HelloTemplate<'a> { - name: &'a str, -} - -async fn hello() -> HelloTemplate<'static> { - HelloTemplate { name: "world" } -} - -#[tokio::test] -async fn template_to_response() { - let app = Router::new().route("/", get(hello)); - - let res = app - .oneshot(Request::builder().uri("/").body(Body::empty()).unwrap()) - .await - .unwrap(); - assert_eq!(res.status(), StatusCode::OK); - - let headers = res.headers(); - assert_eq!(headers["Content-Type"], "text/html; charset=utf-8"); - - let body = res.into_body().collect().await.unwrap().to_bytes(); - assert_eq!(&body[..], b"Hello, world!"); -} diff --git a/rinja_axum/tomlfmt.toml b/rinja_axum/tomlfmt.toml deleted file mode 120000 index 053191cc..00000000 --- a/rinja_axum/tomlfmt.toml +++ /dev/null @@ -1 +0,0 @@ -../tomlfmt.toml \ No newline at end of file diff --git a/rinja_derive/Cargo.toml b/rinja_derive/Cargo.toml index e6d2b676..d724c3f9 100644 --- a/rinja_derive/Cargo.toml +++ b/rinja_derive/Cargo.toml @@ -22,10 +22,6 @@ code-in-doc = ["dep:pulldown-cmark"] config = ["dep:serde", "dep:basic-toml", "parser/config"] urlencode = [] serde_json = [] -with-actix-web = [] -with-axum = [] -with-rocket = [] -with-warp = [] [dependencies] parser = { package = "rinja_parser", version = "=0.3.5", path = "../rinja_parser" } @@ -35,8 +31,6 @@ pulldown-cmark = { version = "0.12.0", optional = true, default-features = false serde = { version = "1.0", optional = true, features = ["derive"] } memchr = "2" -mime = "0.3" -mime_guess = "2" quote = { version = "1", default-features = false } rustc-hash = "2.0.0" syn = { version = "2.0.3", default-features = false, features = ["clone-impls", "derive", "parsing", "printing"] } diff --git a/rinja_derive/src/generator.rs b/rinja_derive/src/generator.rs index cafc009a..caf1cdec 100644 --- a/rinja_derive/src/generator.rs +++ b/rinja_derive/src/generator.rs @@ -19,7 +19,7 @@ use crate::heritage::{Context, Heritage}; use crate::html::write_escaped_str; use crate::input::{Source, TemplateInput}; use crate::integration::{Buffer, impl_everything, write_header}; -use crate::{BUILT_IN_FILTERS, CRATE, CompileError, FileInfo, MsgValidEscapers}; +use crate::{BUILT_IN_FILTERS, CompileError, FileInfo, MsgValidEscapers}; pub(crate) fn template_to_string( buf: &mut Buffer, @@ -103,9 +103,7 @@ impl<'a, 'h> Generator<'a, 'h> { target: Option<&str>, ) -> Result { if target.is_none() { - buf.write(format_args!( - "const _: () = {{ extern crate {CRATE} as rinja;" - )); + buf.write("const _: () = { extern crate rinja as rinja;"); } let size_hint = self.impl_template(ctx, buf, target.unwrap_or("rinja::Template"))?; if target.is_none() { @@ -203,9 +201,7 @@ impl<'a, 'h> Generator<'a, 'h> { "\ rinja::Result::Ok(())\ }}\ - const SIZE_HINT: rinja::helpers::core::primitive::usize = {size_hint}usize;\ - const MIME_TYPE: &'static rinja::helpers::core::primitive::str = {:?};", - self.input.mime_type, + const SIZE_HINT: rinja::helpers::core::primitive::usize = {size_hint}usize;", )); buf.write('}'); diff --git a/rinja_derive/src/input.rs b/rinja_derive/src/input.rs index b9f343ea..eb743dca 100644 --- a/rinja_derive/src/input.rs +++ b/rinja_derive/src/input.rs @@ -6,7 +6,6 @@ use std::path::{Path, PathBuf}; use std::str::FromStr; use std::sync::{Arc, OnceLock}; -use mime::Mime; use parser::node::Whitespace; use parser::{Node, Parsed}; use proc_macro2::Span; @@ -27,7 +26,6 @@ pub(crate) struct TemplateInput<'a> { pub(crate) block: Option<&'a str>, pub(crate) print: Print, pub(crate) escaper: &'a str, - pub(crate) mime_type: String, pub(crate) path: Arc, pub(crate) fields: Vec, } @@ -107,10 +105,6 @@ impl TemplateInput<'_> { ) })?; - let mime_type = - extension_to_mime_type(ext.as_deref().or_else(|| extension(&path)).unwrap_or("txt")) - .to_string(); - let empty_punctuated = Punctuated::new(); let fields = match ast.data { syn::Data::Struct(ref struct_) => { @@ -139,7 +133,6 @@ impl TemplateInput<'_> { block: block.as_deref(), print: *print, escaper, - mime_type, path, fields, }) @@ -491,7 +484,9 @@ fn collect_rinja_code_blocks( for e in Parser::new(&source) { match (in_rinja_code, e) { (false, Event::Start(Tag::CodeBlock(CodeBlockKind::Fenced(s)))) => { - if s.split(",").any(|s| JINJA_EXTENSIONS.contains(&s)) { + if s.split(",") + .any(|s| JINJA_EXTENSIONS.contains(&s.trim_ascii())) + { in_rinja_code = true; had_rinja_code = true; } @@ -535,19 +530,6 @@ impl Iterator for ResultIter { impl FusedIterator for ResultIter {} -fn extension(path: &Path) -> Option<&str> { - let ext = path.extension()?.to_str()?; - if JINJA_EXTENSIONS.contains(&ext) { - // an extension was found: file stem cannot be absent - Path::new(path.file_stem().unwrap()) - .extension() - .and_then(|s| s.to_str()) - .or(Some(ext)) - } else { - Some(ext) - } -} - #[derive(Debug, Clone, Hash, PartialEq)] pub(crate) enum Source { Path(Arc), @@ -582,32 +564,6 @@ impl FromStr for Print { } } -pub(crate) fn extension_to_mime_type(ext: &str) -> Mime { - let basic_type = mime_guess::from_ext(ext).first_or_octet_stream(); - for (simple, utf_8) in &TEXT_TYPES { - if &basic_type == simple { - return utf_8.clone(); - } - } - basic_type -} - -const TEXT_TYPES: [(Mime, Mime); 7] = [ - (mime::TEXT_PLAIN, mime::TEXT_PLAIN_UTF_8), - (mime::TEXT_HTML, mime::TEXT_HTML_UTF_8), - (mime::TEXT_CSS, mime::TEXT_CSS_UTF_8), - (mime::TEXT_CSV, mime::TEXT_CSV_UTF_8), - ( - mime::TEXT_TAB_SEPARATED_VALUES, - mime::TEXT_TAB_SEPARATED_VALUES_UTF_8, - ), - ( - mime::APPLICATION_JAVASCRIPT, - mime::APPLICATION_JAVASCRIPT_UTF_8, - ), - (mime::IMAGE_SVG, mime::IMAGE_SVG), -]; - fn cyclic_graph_error(dependency_graph: &[(Arc, Arc)]) -> Result<(), CompileError> { Err(CompileError::no_file_info( format!( @@ -908,62 +864,13 @@ const _: () = { } }; +#[cfg(feature = "code-in-doc")] const JINJA_EXTENSIONS: &[&str] = &["j2", "jinja", "jinja2", "rinja"]; -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_ext() { - assert_eq!(extension(Path::new("foo-bar.txt")), Some("txt")); - assert_eq!(extension(Path::new("foo-bar.html")), Some("html")); - assert_eq!(extension(Path::new("foo-bar.unknown")), Some("unknown")); - assert_eq!(extension(Path::new("foo-bar.svg")), Some("svg")); - - assert_eq!(extension(Path::new("foo/bar/baz.txt")), Some("txt")); - assert_eq!(extension(Path::new("foo/bar/baz.html")), Some("html")); - assert_eq!(extension(Path::new("foo/bar/baz.unknown")), Some("unknown")); - assert_eq!(extension(Path::new("foo/bar/baz.svg")), Some("svg")); - } - - #[test] - fn test_double_ext() { - assert_eq!(extension(Path::new("foo-bar.html.txt")), Some("txt")); - assert_eq!(extension(Path::new("foo-bar.txt.html")), Some("html")); - assert_eq!(extension(Path::new("foo-bar.txt.unknown")), Some("unknown")); - - assert_eq!(extension(Path::new("foo/bar/baz.html.txt")), Some("txt")); - assert_eq!(extension(Path::new("foo/bar/baz.txt.html")), Some("html")); - assert_eq!( - extension(Path::new("foo/bar/baz.txt.unknown")), - Some("unknown") - ); - } - - #[test] - fn test_skip_jinja_ext() { - assert_eq!(extension(Path::new("foo-bar.html.j2")), Some("html")); - assert_eq!(extension(Path::new("foo-bar.html.jinja")), Some("html")); - assert_eq!(extension(Path::new("foo-bar.html.jinja2")), Some("html")); - - assert_eq!(extension(Path::new("foo/bar/baz.txt.j2")), Some("txt")); - assert_eq!(extension(Path::new("foo/bar/baz.txt.jinja")), Some("txt")); - assert_eq!(extension(Path::new("foo/bar/baz.txt.jinja2")), Some("txt")); - } - - #[test] - fn test_only_jinja_ext() { - assert_eq!(extension(Path::new("foo-bar.j2")), Some("j2")); - assert_eq!(extension(Path::new("foo-bar.jinja")), Some("jinja")); - assert_eq!(extension(Path::new("foo-bar.jinja2")), Some("jinja2")); - } - - #[test] - fn get_source() { - let path = Config::new("", None, None, None) - .and_then(|config| config.find_template("b.html", None, None)) - .unwrap(); - assert_eq!(get_template_source(&path, None).unwrap(), "bar".into()); - } +#[test] +fn get_source() { + let path = Config::new("", None, None, None) + .and_then(|config| config.find_template("b.html", None, None)) + .unwrap(); + assert_eq!(get_template_source(&path, None).unwrap(), "bar".into()); } diff --git a/rinja_derive/src/integration.rs b/rinja_derive/src/integration.rs index 8c933427..31d3b452 100644 --- a/rinja_derive/src/integration.rs +++ b/rinja_derive/src/integration.rs @@ -7,15 +7,6 @@ use syn::DeriveInput; pub(crate) fn impl_everything(ast: &DeriveInput, buf: &mut Buffer) { impl_display(ast, buf); impl_fast_writable(ast, buf); - - #[cfg(feature = "with-actix-web")] - impl_actix_web_responder(ast, buf); - #[cfg(feature = "with-axum")] - impl_axum_into_response(ast, buf); - #[cfg(feature = "with-rocket")] - impl_rocket_responder(ast, buf); - #[cfg(feature = "with-warp")] - impl_warp_reply(ast, buf); } /// Writes header for the `impl` for `TraitFromPathName` or `Template` for the given item @@ -91,79 +82,6 @@ fn impl_fast_writable(ast: &DeriveInput, buf: &mut Buffer) { ); } -/// Implement Actix-web's `Responder`. -#[cfg(feature = "with-actix-web")] -fn impl_actix_web_responder(ast: &DeriveInput, buf: &mut Buffer) { - write_header(ast, buf, "::rinja_actix::actix_web::Responder", None); - buf.write( - "\ - type Body = ::rinja_actix::actix_web::body::BoxBody;\ - #[inline]\ - fn respond_to(self, _req: &::rinja_actix::actix_web::HttpRequest)\ - -> ::rinja_actix::actix_web::HttpResponse {\ - ::rinja_actix::into_response(&self)\ - }\ - }", - ); -} - -/// Implement Axum's `IntoResponse`. -#[cfg(feature = "with-axum")] -fn impl_axum_into_response(ast: &DeriveInput, buf: &mut Buffer) { - write_header( - ast, - buf, - "::rinja_axum::axum_core::response::IntoResponse", - None, - ); - buf.write( - "\ - #[inline]\ - fn into_response(self) -> ::rinja_axum::axum_core::response::Response {\ - ::rinja_axum::into_response(&self)\ - }\ - }", - ); -} - -/// Implement Rocket's `Responder`. -#[cfg(feature = "with-rocket")] -fn impl_rocket_responder(ast: &DeriveInput, buf: &mut Buffer) { - let lifetime1 = syn::Lifetime::new("'rinja1", proc_macro2::Span::call_site()); - let param1 = syn::GenericParam::Lifetime(syn::LifetimeParam::new(lifetime1)); - - write_header( - ast, - buf, - "::rinja_rocket::rocket::response::Responder<'rinja1, 'static>", - Some(vec![param1]), - ); - buf.write( - "\ - #[inline]\ - fn respond_to(self, _: &'rinja1 ::rinja_rocket::rocket::request::Request<'_>)\ - -> ::rinja_rocket::rocket::response::Result<'static>\ - {\ - ::rinja_rocket::respond(&self)\ - }\ - }", - ); -} - -/// Implement Warp's `Reply`. -#[cfg(feature = "with-warp")] -fn impl_warp_reply(ast: &DeriveInput, buf: &mut Buffer) { - write_header(ast, buf, "::rinja_warp::warp::reply::Reply", None); - buf.write( - "\ - #[inline]\ - fn into_response(self) -> ::rinja_warp::warp::reply::Response {\ - ::rinja_warp::into_response(&self)\ - }\ - }", - ); -} - #[derive(Debug)] pub(crate) struct Buffer { // The buffer to generate the code into diff --git a/rinja_derive/src/lib.rs b/rinja_derive/src/lib.rs index 78f376ac..13762c4c 100644 --- a/rinja_derive/src/lib.rs +++ b/rinja_derive/src/lib.rs @@ -143,11 +143,10 @@ pub fn derive_template(input: TokenStream12) -> TokenStream12 { } fn compile_error(msgs: impl Iterator, span: Span) -> TokenStream { - let crate_ = syn::Ident::new(CRATE, Span::call_site()); quote_spanned! { span => const _: () = { - extern crate #crate_ as rinja; + extern crate rinja as rinja; #(rinja::helpers::core::compile_error!(#msgs);)* }; } @@ -425,15 +424,3 @@ const BUILT_IN_FILTERS: &[&str] = &[ "urlencode", "wordcount", ]; - -const CRATE: &str = if cfg!(feature = "with-actix-web") { - "rinja_actix" -} else if cfg!(feature = "with-axum") { - "rinja_axum" -} else if cfg!(feature = "with-rocket") { - "rinja_rocket" -} else if cfg!(feature = "with-warp") { - "rinja_warp" -} else { - "rinja" -}; diff --git a/rinja_derive/src/tests.rs b/rinja_derive/src/tests.rs index 7dd60e1c..804dfd96 100644 --- a/rinja_derive/src/tests.rs +++ b/rinja_derive/src/tests.rs @@ -37,7 +37,6 @@ fn compare(jinja: &str, expected: &str, fields: &[(&str, &str)], size_hint: usiz rinja::Result::Ok(()) } const SIZE_HINT: rinja::helpers::core::primitive::usize = #size_hint; - const MIME_TYPE: &'static rinja::helpers::core::primitive::str = "text/plain; charset=utf-8"; } /// Implement the [`format!()`][rinja::helpers::std::format] trait for [`Foo`] diff --git a/rinja_derive_standalone/Cargo.toml b/rinja_derive_standalone/Cargo.toml index 0be4c951..c2102e0e 100644 --- a/rinja_derive_standalone/Cargo.toml +++ b/rinja_derive_standalone/Cargo.toml @@ -25,10 +25,6 @@ code-in-doc = ["dep:pulldown-cmark"] config = ["dep:serde", "dep:basic-toml", "parser/config"] urlencode = [] serde_json = [] -with-actix-web = [] -with-axum = [] -with-rocket = [] -with-warp = [] [dependencies] parser = { package = "rinja_parser", version = "=0.3.5", path = "../rinja_parser" } @@ -38,8 +34,6 @@ pulldown-cmark = { version = "0.12.0", optional = true, default-features = false serde = { version = "1.0", optional = true, features = ["derive"] } memchr = "2" -mime = "0.3" -mime_guess = "2" quote = { version = "1", default-features = false } rustc-hash = "2.0.0" syn = { version = "2.0.3", default-features = false, features = ["clone-impls", "derive", "parsing", "printing"] } diff --git a/rinja_rocket/.rustfmt.toml b/rinja_rocket/.rustfmt.toml deleted file mode 120000 index a7ef950c..00000000 --- a/rinja_rocket/.rustfmt.toml +++ /dev/null @@ -1 +0,0 @@ -../.rustfmt.toml \ No newline at end of file diff --git a/rinja_rocket/Cargo.toml b/rinja_rocket/Cargo.toml deleted file mode 100644 index 3ea5b54a..00000000 --- a/rinja_rocket/Cargo.toml +++ /dev/null @@ -1,36 +0,0 @@ -[workspace] -members = ["."] - -[package] -name = "rinja_rocket" -version = "0.3.5" -description = "Rocket integration for Rinja templates" -documentation = "https://docs.rs/rinja" -keywords = ["markup", "template", "jinja2", "html"] -categories = ["template-engine"] -homepage = "https://github.com/rinja-rs/rinja" -repository = "https://github.com/rinja-rs/rinja" -license = "MIT OR Apache-2.0" -readme = "README.md" -edition = "2021" -rust-version = "1.80" - -[package.metadata.docs.rs] -all-features = true -rustdoc-args = ["--generate-link-to-definition", "--cfg=docsrs"] - -[features] -default = ["rinja/default"] -full = ["rinja/full"] -code-in-doc = ["rinja/code-in-doc"] -config = ["rinja/config"] -serde_json = ["rinja/serde_json"] -urlencode = ["rinja/urlencode"] - -[dependencies] -rinja = { version = "0.3.5", path = "../rinja", default-features = false, features = ["with-rocket"] } - -rocket = { version = "0.5", default-features = false } - -[dev-dependencies] -tokio = { version = "1.0", features = ["macros", "rt"] } diff --git a/rinja_rocket/LICENSE-APACHE b/rinja_rocket/LICENSE-APACHE deleted file mode 120000 index 965b606f..00000000 --- a/rinja_rocket/LICENSE-APACHE +++ /dev/null @@ -1 +0,0 @@ -../LICENSE-APACHE \ No newline at end of file diff --git a/rinja_rocket/LICENSE-MIT b/rinja_rocket/LICENSE-MIT deleted file mode 120000 index 76219eb7..00000000 --- a/rinja_rocket/LICENSE-MIT +++ /dev/null @@ -1 +0,0 @@ -../LICENSE-MIT \ No newline at end of file diff --git a/rinja_rocket/README.md b/rinja_rocket/README.md deleted file mode 100644 index 5a39ab8c..00000000 --- a/rinja_rocket/README.md +++ /dev/null @@ -1,9 +0,0 @@ -# rinja_rocket: Rinja integration with Rocket - -[![Crates.io](https://img.shields.io/crates/v/rinja_rocket?logo=rust&style=flat-square&logoColor=white "Crates.io")](https://crates.io/crates/rinja_rocket) -[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/rinja-rs/rinja/rust.yml?branch=master&logo=github&style=flat-square&logoColor=white "GitHub Workflow Status")](https://github.com/rinja-rs/rinja/actions/workflows/rust.yml) -[![Book](https://img.shields.io/readthedocs/rinja?label=book&logo=readthedocs&style=flat-square&logoColor=white "Book")](https://rinja.readthedocs.io/) -[![docs.rs](https://img.shields.io/docsrs/rinja_rocket?logo=docsdotrs&style=flat-square&logoColor=white "docs.rs")](https://docs.rs/rinja_rocket/) - -Integration of the [Rinja](https://github.com/rinja-rs/rinja) templating engine in -code building on the Rocket web framework. diff --git a/rinja_rocket/_typos.toml b/rinja_rocket/_typos.toml deleted file mode 120000 index 2264b5db..00000000 --- a/rinja_rocket/_typos.toml +++ /dev/null @@ -1 +0,0 @@ -../_typos.toml \ No newline at end of file diff --git a/rinja_rocket/deny.toml b/rinja_rocket/deny.toml deleted file mode 120000 index a65e17bb..00000000 --- a/rinja_rocket/deny.toml +++ /dev/null @@ -1 +0,0 @@ -../deny.toml \ No newline at end of file diff --git a/rinja_rocket/src/lib.rs b/rinja_rocket/src/lib.rs deleted file mode 100644 index 28c9b4ae..00000000 --- a/rinja_rocket/src/lib.rs +++ /dev/null @@ -1,46 +0,0 @@ -#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] -#![deny(elided_lifetimes_in_paths)] -#![deny(unreachable_pub)] - -use std::io::Cursor; - -#[doc(no_inline)] -pub use rinja::*; -#[doc(no_inline)] -pub use rocket; -use rocket::Response; - -#[inline] -pub fn respond(tmpl: &T) -> rocket::response::Result<'static> { - try_into_response(tmpl).map_err(|_| rocket::http::Status::InternalServerError) -} - -/// Render a [`Template`] into a [`Response`], or render an error page. -#[must_use] -pub fn into_response(tmpl: &T) -> Response<'static> { - match try_into_response(tmpl) { - Ok(response) => response, - Err(err) => { - let value = err.to_string(); - Response::build() - .status(rocket::http::Status::InternalServerError) - .header(rocket::http::Header::new( - "content-type", - "text/plain; charset=utf-8", - )) - .sized_body(value.len(), Cursor::new(value)) - .finalize() - } - } -} - -/// Try to render a [`Template`] into a [`Response`]. -pub fn try_into_response( - tmpl: &T, -) -> Result, Error> { - let value = tmpl.render()?; - Ok(Response::build() - .header(rocket::http::Header::new("content-type", T::MIME_TYPE)) - .sized_body(value.len(), Cursor::new(value)) - .finalize()) -} diff --git a/rinja_rocket/templates/hello.html b/rinja_rocket/templates/hello.html deleted file mode 100644 index 8149be7a..00000000 --- a/rinja_rocket/templates/hello.html +++ /dev/null @@ -1 +0,0 @@ -Hello, {{ name }}! diff --git a/rinja_rocket/tests/basic.rs b/rinja_rocket/tests/basic.rs deleted file mode 100644 index f39f3f2f..00000000 --- a/rinja_rocket/tests/basic.rs +++ /dev/null @@ -1,28 +0,0 @@ -use rinja_rocket::Template; -use rocket::http::{ContentType, Status}; -use rocket::local::asynchronous::Client; - -#[derive(Template)] -#[template(path = "hello.html")] -struct HelloTemplate<'a> { - name: &'a str, -} - -#[rocket::get("/")] -fn hello() -> HelloTemplate<'static> { - HelloTemplate { name: "world" } -} - -#[tokio::test] -async fn test_rocket() { - let rocket = rocket::build() - .mount("/", rocket::routes![hello]) - .ignite() - .await - .unwrap(); - let client = Client::untracked(rocket).await.unwrap(); - let rsp = client.get("/").dispatch().await; - assert_eq!(rsp.status(), Status::Ok); - assert_eq!(rsp.content_type(), Some(ContentType::HTML)); - assert_eq!(rsp.into_string().await.as_deref(), Some("Hello, world!")); -} diff --git a/rinja_rocket/tomlfmt.toml b/rinja_rocket/tomlfmt.toml deleted file mode 120000 index 053191cc..00000000 --- a/rinja_rocket/tomlfmt.toml +++ /dev/null @@ -1 +0,0 @@ -../tomlfmt.toml \ No newline at end of file diff --git a/rinja_warp/.rustfmt.toml b/rinja_warp/.rustfmt.toml deleted file mode 120000 index a7ef950c..00000000 --- a/rinja_warp/.rustfmt.toml +++ /dev/null @@ -1 +0,0 @@ -../.rustfmt.toml \ No newline at end of file diff --git a/rinja_warp/Cargo.toml b/rinja_warp/Cargo.toml deleted file mode 100644 index f4a63363..00000000 --- a/rinja_warp/Cargo.toml +++ /dev/null @@ -1,36 +0,0 @@ -[workspace] -members = ["."] - -[package] -name = "rinja_warp" -version = "0.3.5" -description = "Warp integration for Rinja templates" -documentation = "https://docs.rs/rinja" -keywords = ["markup", "template", "jinja2", "html"] -categories = ["template-engine"] -homepage = "https://github.com/rinja-rs/rinja" -repository = "https://github.com/rinja-rs/rinja" -license = "MIT OR Apache-2.0" -readme = "README.md" -edition = "2021" -rust-version = "1.80" - -[package.metadata.docs.rs] -all-features = true -rustdoc-args = ["--generate-link-to-definition", "--cfg=docsrs"] - -[features] -default = ["rinja/default"] -full = ["rinja/full"] -code-in-doc = ["rinja/code-in-doc"] -config = ["rinja/config"] -serde_json = ["rinja/serde_json"] -urlencode = ["rinja/urlencode"] - -[dependencies] -rinja = { version = "0.3.5", path = "../rinja", default-features = false, features = ["with-warp"] } - -warp = { version = "0.3", default-features = false } - -[dev-dependencies] -tokio = { version = "1.0", features = ["macros", "rt"] } diff --git a/rinja_warp/LICENSE-APACHE b/rinja_warp/LICENSE-APACHE deleted file mode 120000 index 965b606f..00000000 --- a/rinja_warp/LICENSE-APACHE +++ /dev/null @@ -1 +0,0 @@ -../LICENSE-APACHE \ No newline at end of file diff --git a/rinja_warp/LICENSE-MIT b/rinja_warp/LICENSE-MIT deleted file mode 120000 index 76219eb7..00000000 --- a/rinja_warp/LICENSE-MIT +++ /dev/null @@ -1 +0,0 @@ -../LICENSE-MIT \ No newline at end of file diff --git a/rinja_warp/README.md b/rinja_warp/README.md deleted file mode 100644 index ed4fefbf..00000000 --- a/rinja_warp/README.md +++ /dev/null @@ -1,9 +0,0 @@ -# rinja_warp: Rinja integration with warp - -[![Crates.io](https://img.shields.io/crates/v/rinja_warp?logo=rust&style=flat-square&logoColor=white "Crates.io")](https://crates.io/crates/rinja_warp) -[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/rinja-rs/rinja/rust.yml?branch=master&logo=github&style=flat-square&logoColor=white "GitHub Workflow Status")](https://github.com/rinja-rs/rinja/actions/workflows/rust.yml) -[![Book](https://img.shields.io/readthedocs/rinja?label=book&logo=readthedocs&style=flat-square&logoColor=white "Book")](https://rinja.readthedocs.io/) -[![docs.rs](https://img.shields.io/docsrs/rinja_warp?logo=docsdotrs&style=flat-square&logoColor=white "docs.rs")](https://docs.rs/rinja_warp/) - -Integration of the [Rinja](https://github.com/rinja-rs/rinja) templating engine in -code building on the warp web framework. diff --git a/rinja_warp/_typos.toml b/rinja_warp/_typos.toml deleted file mode 120000 index 2264b5db..00000000 --- a/rinja_warp/_typos.toml +++ /dev/null @@ -1 +0,0 @@ -../_typos.toml \ No newline at end of file diff --git a/rinja_warp/deny.toml b/rinja_warp/deny.toml deleted file mode 120000 index a65e17bb..00000000 --- a/rinja_warp/deny.toml +++ /dev/null @@ -1 +0,0 @@ -../deny.toml \ No newline at end of file diff --git a/rinja_warp/src/lib.rs b/rinja_warp/src/lib.rs deleted file mode 100644 index f83538e9..00000000 --- a/rinja_warp/src/lib.rs +++ /dev/null @@ -1,35 +0,0 @@ -#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] -#![deny(elided_lifetimes_in_paths)] -#![deny(unreachable_pub)] - -#[doc(no_inline)] -pub use rinja::*; -#[doc(no_inline)] -pub use warp; -use warp::reply::Response; - -/// Render a [`Template`] into a [`Response`], or render an error page. -#[must_use] -pub fn into_response(tmpl: &T) -> Response { - match try_into_response(tmpl) { - Ok(response) => response, - Err(err) => warp::http::Response::builder() - .status(warp::http::StatusCode::INTERNAL_SERVER_ERROR) - .header( - warp::http::header::CONTENT_TYPE, - warp::http::HeaderValue::from_static("text/plain; charset=utf-8"), - ) - .body(err.to_string().into()) - .unwrap(), - } -} - -/// Try to render a [`Template`] into a [`Response`]. -pub fn try_into_response(tmpl: &T) -> Result { - let value = tmpl.render()?.into(); - warp::http::Response::builder() - .status(warp::http::StatusCode::OK) - .header(warp::http::header::CONTENT_TYPE, T::MIME_TYPE) - .body(value) - .map_err(|err| Error::Custom(err.into())) -} diff --git a/rinja_warp/templates/hello.html b/rinja_warp/templates/hello.html deleted file mode 100644 index 8149be7a..00000000 --- a/rinja_warp/templates/hello.html +++ /dev/null @@ -1 +0,0 @@ -Hello, {{ name }}! diff --git a/rinja_warp/tests/warp.rs b/rinja_warp/tests/warp.rs deleted file mode 100644 index 0b66ddfa..00000000 --- a/rinja_warp/tests/warp.rs +++ /dev/null @@ -1,18 +0,0 @@ -use rinja_warp::Template; -use warp::Filter; - -#[derive(Template)] -#[template(path = "hello.html")] -struct HelloTemplate<'a> { - name: &'a str, -} - -#[tokio::test] -async fn test_warp() { - let filter = warp::get().map(|| HelloTemplate { name: "world" }); - - let res = warp::test::request().reply(&filter).await; - - assert_eq!(res.status(), 200); - assert_eq!(res.body(), "Hello, world!"); -} diff --git a/rinja_warp/tomlfmt.toml b/rinja_warp/tomlfmt.toml deleted file mode 120000 index 053191cc..00000000 --- a/rinja_warp/tomlfmt.toml +++ /dev/null @@ -1 +0,0 @@ -../tomlfmt.toml \ No newline at end of file