Remove tide integration

This commit is contained in:
Dirkjan Ochtman 2024-03-06 10:03:55 +01:00
parent d62c2fb44d
commit e5e9fc63a3
13 changed files with 1 additions and 120 deletions

View File

@ -33,7 +33,7 @@ jobs:
matrix:
package: [
askama, askama_actix, askama_axum, askama_derive, askama_escape,
askama_parser, askama_rocket, askama_tide, askama_warp, testing,
askama_parser, askama_rocket, askama_warp, testing,
]
runs-on: ubuntu-latest
steps:

View File

@ -7,7 +7,6 @@ members = [
"askama_escape",
"askama_parser",
"askama_rocket",
"askama_tide",
"askama_warp",
"testing",
]

View File

@ -28,7 +28,6 @@ urlencode = ["askama_derive/urlencode", "percent-encoding"]
with-actix-web = ["askama_derive/with-actix-web"]
with-axum = ["askama_derive/with-axum"]
with-rocket = ["askama_derive/with-rocket"]
with-tide = ["askama_derive/with-tide"]
with-warp = ["askama_derive/with-warp"]
# deprecated

View File

@ -24,7 +24,6 @@ num-traits = []
with-actix-web = []
with-axum = []
with-rocket = []
with-tide = []
with-warp = []
[dependencies]

View File

@ -163,8 +163,6 @@ const CRATE: &str = if cfg!(feature = "with-actix-web") {
"::askama_axum"
} else if cfg!(feature = "with-rocket") {
"::askama_rocket"
} else if cfg!(feature = "with-tide") {
"::askama_tide"
} else if cfg!(feature = "with-warp") {
"::askama_warp"
} else {

View File

@ -1,30 +0,0 @@
[package]
name = "askama_tide"
version = "0.16.0"
edition = "2021"
rust-version = "1.65"
description = "Tide integration for Askama templates"
keywords = ["markup", "template", "html", "tide", "http-types"]
homepage = "https://github.com/djc/askama"
repository = "https://github.com/djc/askama"
documentation = "https://docs.rs/askama"
license = "MIT OR Apache-2.0"
workspace = ".."
readme = "README.md"
[dependencies]
askama = { version = "0.13", path = "../askama", default-features = false, features = ["with-tide"] }
tide = { version = "0.16", default-features = false }
[dev-dependencies]
async-std = { version = "1.6.5", features = ["attributes"] }
[features]
default = ["askama/default"]
config = ["askama/config"]
humansize = ["askama/humansize"]
markdown = ["askama/markdown"]
num-traits = ["askama/num-traits"]
serde-json = ["askama/serde-json"]
serde-yaml = ["askama/serde-yaml"]
urlencode = ["askama/urlencode"]

View File

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

View File

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

View File

@ -1,9 +0,0 @@
# askama_tide: Askama integration with tide
[![Documentation](https://docs.rs/askama_tide/badge.svg)](https://docs.rs/askama_tide/)
[![Latest version](https://img.shields.io/crates/v/askama_tide.svg)](https://crates.io/crates/askama_tide)
[![Build Status](https://github.com/djc/askama/workflows/CI/badge.svg)](https://github.com/djc/askama/actions?query=workflow%3ACI)
[![Chat](https://img.shields.io/discord/976380008299917365?logo=discord)](https://discord.gg/ZucwjE6bmT)
Integration of the [Askama](https://github.com/djc/askama) templating engine in
code building on the tide web framework.

View File

@ -1,31 +0,0 @@
#![forbid(unsafe_code)]
#![deny(elided_lifetimes_in_paths)]
#![deny(unreachable_pub)]
pub use tide;
pub use askama::*;
use tide::{Body, Response};
pub fn try_into_body<T: Template>(t: &T) -> Result<Body> {
let string = t.render()?;
let mut body = Body::from_string(string);
body.set_mime(T::MIME_TYPE);
Ok(body)
}
pub fn into_response<T: Template>(t: &T) -> Response {
match try_into_body(t) {
Ok(body) => {
let mut response = Response::new(200);
response.set_body(body);
response
}
Err(error) => {
let mut response = Response::new(500);
response.set_error(error);
response
}
}
}

View File

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

View File

@ -1,28 +0,0 @@
use askama::Template;
use async_std::prelude::*;
use tide::{http::mime::HTML, Body, Response};
#[derive(Template)]
#[template(path = "hello.html")]
struct HelloTemplate<'a> {
name: &'a str,
}
#[async_std::test]
async fn template_to_response() {
let mut res: Response = HelloTemplate { name: "world" }.into();
assert_eq!(res.status(), 200);
assert_eq!(res.content_type(), Some(HTML));
let res: &mut tide::http::Response = res.as_mut();
assert_eq!(res.body_string().await.unwrap(), "Hello, world!");
}
#[async_std::test]
async fn template_to_body() {
let mut body: Body = HelloTemplate { name: "world" }.try_into().unwrap();
assert_eq!(body.mime(), &HTML);
let mut body_string = String::new();
body.read_to_string(&mut body_string).await.unwrap();
assert_eq!(body_string, "Hello, world!");
}

View File

@ -51,20 +51,7 @@ trait for each template type. This makes it simple to return a template from
a Warp filter. See [the example](https://github.com/djc/askama/blob/main/askama_warp/tests/warp.rs)
from the Askama test suite for more on how to integrate.
## Tide integration
In your template definitions, replace `askama::Template` with
[`askama_tide::Template`][askama_tide].
Enabling the `with-tide` feature appends `Into<tide::Response>` and
`TryInto<tide::Body>` implementations for each template type. This
provides the ability for tide apps to build a response directly from
a template, or to append a templated body to an existing
`Response`. See [the example](https://github.com/djc/askama/blob/main/askama_tide/tests/tide.rs)
from the Askama test suite for more on how to integrate.
[askama_rocket]: https://docs.rs/askama_rocket
[askama_actix]: https://docs.rs/askama_actix
[askama_axum]: https://docs.rs/askama_axum
[askama_warp]: https://docs.rs/askama_warp
[askama_tide]: https://docs.rs/askama_tide