-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
335 additions
and
153 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use std::mem; | ||
use std::task::Poll; | ||
|
||
use actix_web::body::{BoxBody, MessageBody}; | ||
use actix_web::http::header::ContentType; | ||
use actix_web::web::Bytes; | ||
use actix_web::{HttpResponse, Responder}; | ||
|
||
use crate::{Html, HtmxSrc}; | ||
|
||
impl Responder for Html { | ||
type Body = BoxBody; | ||
|
||
fn respond_to(self, _req: &actix_web::HttpRequest) -> HttpResponse<Self::Body> { | ||
HttpResponse::Ok() | ||
.content_type(ContentType::html()) | ||
.body(self) | ||
} | ||
} | ||
|
||
impl MessageBody for Html { | ||
type Error = <String as MessageBody>::Error; | ||
|
||
fn size(&self) -> actix_web::body::BodySize { | ||
self.0.size() | ||
} | ||
|
||
fn poll_next( | ||
mut self: std::pin::Pin<&mut Self>, | ||
_cx: &mut std::task::Context<'_>, | ||
) -> std::task::Poll<Option<Result<actix_web::web::Bytes, Self::Error>>> { | ||
if self.0.is_empty() { | ||
Poll::Ready(None) | ||
} else { | ||
let string = mem::take(&mut self.0); | ||
Poll::Ready(Some(Ok(Bytes::from(string)))) | ||
} | ||
} | ||
|
||
fn try_into_bytes(self) -> Result<Bytes, Self> | ||
where | ||
Self: Sized, | ||
{ | ||
Ok(Bytes::from(self.0)) | ||
} | ||
} | ||
|
||
impl Responder for HtmxSrc { | ||
type Body = BoxBody; | ||
|
||
fn respond_to(self, _req: &actix_web::HttpRequest) -> HttpResponse<Self::Body> { | ||
HttpResponse::Ok() | ||
.content_type("text/javascript; charset=utf-8") | ||
.body(Self::HTMX_SRC) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use axum_core::response::IntoResponse; | ||
|
||
use crate::{Html, HtmxSrc}; | ||
|
||
impl IntoResponse for Html { | ||
fn into_response(self) -> axum_core::response::Response { | ||
( | ||
[("Content-Type", "text/html; charset=utf-8")], | ||
self.to_string(), | ||
) | ||
.into_response() | ||
} | ||
} | ||
|
||
impl IntoResponse for HtmxSrc { | ||
fn into_response(self) -> axum_core::response::Response { | ||
( | ||
[("Content-Type", "text/javascript; charset=utf-8")], | ||
Self::HTMX_SRC, | ||
) | ||
.into_response() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.