From d08a2421701949cd26d7796c68f556099a61f2e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Kijewski?= Date: Thu, 6 Jan 2022 14:43:01 +0100 Subject: [PATCH] Remove ext argument in integrations --- askama_axum/src/lib.rs | 2 +- askama_derive/src/generator.rs | 23 +++++++---------------- askama_gotham/src/lib.rs | 2 +- askama_mendes/src/lib.rs | 7 +------ askama_rocket/src/lib.rs | 2 +- askama_tide/src/lib.rs | 6 +++--- askama_warp/src/lib.rs | 2 +- 7 files changed, 15 insertions(+), 29 deletions(-) diff --git a/askama_axum/src/lib.rs b/askama_axum/src/lib.rs index da3d69902..090d1d2a9 100644 --- a/askama_axum/src/lib.rs +++ b/askama_axum/src/lib.rs @@ -6,7 +6,7 @@ pub use askama::*; pub use axum_core::response::{IntoResponse, Response}; use http::StatusCode; -pub fn into_response(t: &T, _ext: &str) -> Response { +pub fn into_response(t: &T) -> Response { match t.render() { Ok(body) => { let headers = [( diff --git a/askama_derive/src/generator.rs b/askama_derive/src/generator.rs index 142ff7fb8..34fe3f954 100644 --- a/askama_derive/src/generator.rs +++ b/askama_derive/src/generator.rs @@ -428,8 +428,7 @@ impl<'a> Generator<'a> { "fn into_response(self)\ -> ::askama_axum::Response {", )?; - let ext = self.input.extension().unwrap_or("txt"); - buf.writeln(&format!("::askama_axum::into_response(&self, {:?})", ext))?; + buf.writeln("::askama_axum::into_response(&self)")?; buf.writeln("}")?; buf.writeln("}") } @@ -443,8 +442,7 @@ impl<'a> Generator<'a> { "fn into_response(self, _state: &::askama_gotham::State)\ -> ::askama_gotham::Response<::askama_gotham::Body> {", )?; - let ext = self.input.extension().unwrap_or("txt"); - buf.writeln(&format!("::askama_gotham::respond(&self, {:?})", ext))?; + buf.writeln("::askama_gotham::respond(&self)")?; buf.writeln("}")?; buf.writeln("}") } @@ -490,10 +488,7 @@ impl<'a> Generator<'a> { -> ::mendes::http::Response {", )?; - buf.writeln(&format!( - "::askama_mendes::into_response(app, req, &self, {:?})", - self.input.extension() - ))?; + buf.writeln("::askama_mendes::into_response(app, req, &self)")?; buf.writeln("}")?; buf.writeln("}")?; Ok(()) @@ -515,8 +510,7 @@ impl<'a> Generator<'a> { "fn respond_to(self, _: &::askama_rocket::Request) \ -> ::askama_rocket::Result<'askama> {", )?; - let ext = self.input.extension().unwrap_or("txt"); - buf.writeln(&format!("::askama_rocket::respond(&self, {:?})", ext))?; + buf.writeln("::askama_rocket::respond(&self)")?; buf.writeln("}")?; buf.writeln("}")?; @@ -525,8 +519,6 @@ impl<'a> Generator<'a> { #[cfg(feature = "with-tide")] fn impl_tide_integrations(&mut self, buf: &mut Buffer) -> Result<(), CompileError> { - let ext = self.input.extension().unwrap_or("txt"); - self.write_header( buf, "::std::convert::TryInto<::askama_tide::tide::Body>", @@ -537,7 +529,7 @@ impl<'a> Generator<'a> { #[inline]\n\ fn try_into(self) -> ::askama_tide::askama::Result<::askama_tide::tide::Body> {", )?; - buf.writeln(&format!("::askama_tide::try_into_body(&self, {:?})", &ext))?; + buf.writeln("::askama_tide::try_into_body(&self)")?; buf.writeln("}")?; buf.writeln("}")?; @@ -545,7 +537,7 @@ impl<'a> Generator<'a> { self.write_header(buf, "Into<::askama_tide::tide::Response>", None)?; buf.writeln("#[inline]")?; buf.writeln("fn into(self) -> ::askama_tide::tide::Response {")?; - buf.writeln(&format!("::askama_tide::into_response(&self, {:?})", ext))?; + buf.writeln("::askama_tide::into_response(&self)")?; buf.writeln("}\n}") } @@ -554,8 +546,7 @@ impl<'a> Generator<'a> { self.write_header(buf, "::askama_warp::warp::reply::Reply", None)?; buf.writeln("#[inline]")?; buf.writeln("fn into_response(self) -> ::askama_warp::warp::reply::Response {")?; - let ext = self.input.extension().unwrap_or("txt"); - buf.writeln(&format!("::askama_warp::reply(&self, {:?})", ext))?; + buf.writeln("::askama_warp::reply(&self)")?; buf.writeln("}")?; buf.writeln("}") } diff --git a/askama_gotham/src/lib.rs b/askama_gotham/src/lib.rs index a32398df8..bc699f6eb 100644 --- a/askama_gotham/src/lib.rs +++ b/askama_gotham/src/lib.rs @@ -9,7 +9,7 @@ use gotham::hyper::header; pub use gotham::hyper::{Body, Response, StatusCode}; pub use gotham::state::State; -pub fn respond(t: &T, _ext: &str) -> Response { +pub fn respond(t: &T) -> Response { match t.render() { Ok(body) => Response::builder() .status(StatusCode::OK) diff --git a/askama_mendes/src/lib.rs b/askama_mendes/src/lib.rs index 3bf364801..5eb3a3cb7 100644 --- a/askama_mendes/src/lib.rs +++ b/askama_mendes/src/lib.rs @@ -9,12 +9,7 @@ use mendes::http::Response; pub use askama::*; -pub fn into_response( - app: &A, - req: &Parts, - t: &T, - _ext: Option<&str>, -) -> Response +pub fn into_response(app: &A, req: &Parts, t: &T) -> Response where A: Application, T: Template, diff --git a/askama_rocket/src/lib.rs b/askama_rocket/src/lib.rs index fb231a420..e2e84be22 100644 --- a/askama_rocket/src/lib.rs +++ b/askama_rocket/src/lib.rs @@ -10,7 +10,7 @@ pub use rocket::request::Request; use rocket::response::Response; pub use rocket::response::{Responder, Result}; -pub fn respond(t: &T, _ext: &str) -> Result<'static> { +pub fn respond(t: &T) -> Result<'static> { let rsp = t.render().map_err(|_| Status::InternalServerError)?; Response::build() .header(Header::new("content-type", T::MIME_TYPE)) diff --git a/askama_tide/src/lib.rs b/askama_tide/src/lib.rs index be597bba1..a7fa6c1e1 100644 --- a/askama_tide/src/lib.rs +++ b/askama_tide/src/lib.rs @@ -8,15 +8,15 @@ pub use tide; use askama::*; use tide::{Body, Response}; -pub fn try_into_body(t: &T, _ext: &str) -> Result { +pub fn try_into_body(t: &T) -> Result { let string = t.render()?; let mut body = Body::from_string(string); body.set_mime(T::MIME_TYPE); Ok(body) } -pub fn into_response(t: &T, ext: &str) -> Response { - match try_into_body(t, ext) { +pub fn into_response(t: &T) -> Response { + match try_into_body(t) { Ok(body) => { let mut response = Response::new(200); response.set_body(body); diff --git a/askama_warp/src/lib.rs b/askama_warp/src/lib.rs index b2f038744..9c4bb9ba8 100644 --- a/askama_warp/src/lib.rs +++ b/askama_warp/src/lib.rs @@ -9,7 +9,7 @@ use warp::http::{self, header, StatusCode}; use warp::hyper::Body; use warp::reply::Response; -pub fn reply(t: &T, _ext: &str) -> Response { +pub fn reply(t: &T) -> Response { match t.render() { Ok(body) => http::Response::builder() .status(StatusCode::OK)