Remove integration crates

This commit is contained in:
René Kijewski 2024-11-25 02:37:35 +01:00
parent 87f611e871
commit 69ad5ea026
59 changed files with 40 additions and 693 deletions

View File

@ -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

View File

@ -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

View File

@ -7,5 +7,4 @@
- [Configuration](./configuration.md)
- [Template syntax](./template_syntax.md)
- [Filters](./filters.md)
- [Integrations](./integrations.md)
- [Performance](./performance.md)

View File

@ -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

View File

@ -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

View File

@ -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"

View File

@ -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<impl Responder> {
}
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(<Box<dyn std::error::Error>>::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(<Box<dyn std::error::Error>>::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(<Box<dyn std::error::Error>>::from)?,
))
}

View File

@ -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

View File

@ -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"

View File

@ -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" }

View File

@ -1 +0,0 @@
../.rustfmt.toml

View File

@ -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" }

View File

@ -1 +0,0 @@
../LICENSE-APACHE

View File

@ -1 +0,0 @@
../LICENSE-MIT

View File

@ -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.

View File

@ -1 +0,0 @@
../_typos.toml

View File

@ -1 +0,0 @@
../deny.toml

View File

@ -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<T: ?Sized + rinja::Template>(tmpl: &T) -> HttpResponse<BoxBody> {
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<T: ?Sized + rinja::Template>(
tmpl: &T,
) -> Result<HttpResponse<BoxBody>, 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 {
<Error as fmt::Debug>::fmt(&self.0, f)
}
}
impl fmt::Display for ActixError {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
<Error as fmt::Display>::fmt(&self.0, f)
}
}
impl ResponseError for ActixError {}

View File

@ -1 +0,0 @@
Hello, {{ name }}!

View File

@ -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()));
}

View File

@ -1 +0,0 @@
../tomlfmt.toml

View File

@ -1 +0,0 @@
../.rustfmt.toml

View File

@ -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"] }

View File

@ -1 +0,0 @@
../LICENSE-APACHE

View File

@ -1 +0,0 @@
../LICENSE-MIT

View File

@ -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.

View File

@ -1 +0,0 @@
../_typos.toml

View File

@ -1 +0,0 @@
../deny.toml

View File

@ -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<T: ?Sized + rinja::Template>(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<T: ?Sized + rinja::Template>(tmpl: &T) -> Result<Response, Error> {
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()))
}

View File

@ -1 +0,0 @@
Hello, {{ name }}!

View File

@ -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!");
}

View File

@ -1 +0,0 @@
../tomlfmt.toml

View File

@ -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" }

View File

@ -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<usize, CompileError> {
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() {

View File

@ -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<Self::Body> {\
::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

View File

@ -143,11 +143,10 @@ pub fn derive_template(input: TokenStream12) -> TokenStream12 {
}
fn compile_error(msgs: impl Iterator<Item = String>, 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"
};

View File

@ -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" }

View File

@ -1 +0,0 @@
../.rustfmt.toml

View File

@ -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"] }

View File

@ -1 +0,0 @@
../LICENSE-APACHE

View File

@ -1 +0,0 @@
../LICENSE-MIT

View File

@ -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.

View File

@ -1 +0,0 @@
../_typos.toml

View File

@ -1 +0,0 @@
../deny.toml

View File

@ -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<T: ?Sized + rinja::Template>(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<T: ?Sized + rinja::Template>(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<T: ?Sized + rinja::Template>(
tmpl: &T,
) -> Result<Response<'static>, 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())
}

View File

@ -1 +0,0 @@
Hello, {{ name }}!

View File

@ -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!"));
}

View File

@ -1 +0,0 @@
../tomlfmt.toml

View File

@ -1 +0,0 @@
../.rustfmt.toml

View File

@ -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"] }

View File

@ -1 +0,0 @@
../LICENSE-APACHE

View File

@ -1 +0,0 @@
../LICENSE-MIT

View File

@ -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.

View File

@ -1 +0,0 @@
../_typos.toml

View File

@ -1 +0,0 @@
../deny.toml

View File

@ -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<T: ?Sized + rinja::Template>(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<T: ?Sized + rinja::Template>(tmpl: &T) -> Result<Response, Error> {
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()))
}

View File

@ -1 +0,0 @@
Hello, {{ name }}!

View File

@ -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!");
}

View File

@ -1 +0,0 @@
../tomlfmt.toml