mirror of
https://github.com/robertwayne/axum-htmx
synced 2024-12-26 10:19:32 +01:00
Rename header enums with the Htmx prefix
This commit is contained in:
parent
9c66af6c00
commit
f5680852cd
1 changed files with 25 additions and 25 deletions
50
src/lib.rs
50
src/lib.rs
|
@ -6,7 +6,7 @@ use axum::{extract::FromRequestParts, http::request::Parts};
|
||||||
///
|
///
|
||||||
/// See <https://htmx.org/reference/#request_headers> for more information.
|
/// See <https://htmx.org/reference/#request_headers> for more information.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
pub enum HxRequestHeader {
|
pub enum HtmxRequestHeader {
|
||||||
/// Indicates that the request is via an element using `hx-boost` attribute.
|
/// Indicates that the request is via an element using `hx-boost` attribute.
|
||||||
///
|
///
|
||||||
/// See <https://htmx.org/attributes/hx-boost/> for more information.
|
/// See <https://htmx.org/attributes/hx-boost/> for more information.
|
||||||
|
@ -30,17 +30,17 @@ pub enum HxRequestHeader {
|
||||||
Trigger,
|
Trigger,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HxRequestHeader {
|
impl HtmxRequestHeader {
|
||||||
pub fn as_str(&self) -> &'static str {
|
pub fn as_str(&self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
HxRequestHeader::Boosted => "HX-Boosted",
|
HtmxRequestHeader::Boosted => "HX-Boosted",
|
||||||
HxRequestHeader::CurrentUrl => "HX-Current-Url",
|
HtmxRequestHeader::CurrentUrl => "HX-Current-Url",
|
||||||
HxRequestHeader::HistoryRestoreRequest => "HX-History-Restore-Request",
|
HtmxRequestHeader::HistoryRestoreRequest => "HX-History-Restore-Request",
|
||||||
HxRequestHeader::Prompt => "HX-Prompt",
|
HtmxRequestHeader::Prompt => "HX-Prompt",
|
||||||
HxRequestHeader::Request => "HX-Request",
|
HtmxRequestHeader::Request => "HX-Request",
|
||||||
HxRequestHeader::Target => "HX-Target",
|
HtmxRequestHeader::Target => "HX-Target",
|
||||||
HxRequestHeader::TriggerName => "HX-Trigger-Name",
|
HtmxRequestHeader::TriggerName => "HX-Trigger-Name",
|
||||||
HxRequestHeader::Trigger => "HX-Trigger",
|
HtmxRequestHeader::Trigger => "HX-Trigger",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ impl HxRequestHeader {
|
||||||
///
|
///
|
||||||
/// See <https://htmx.org/reference/#response_headers> for more information.
|
/// See <https://htmx.org/reference/#response_headers> for more information.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
pub enum HxResponseHeader {
|
pub enum HtmxResponseHeader {
|
||||||
/// Allows you to do a client-side redirect that does not do a full page
|
/// Allows you to do a client-side redirect that does not do a full page
|
||||||
/// reload.
|
/// reload.
|
||||||
Location,
|
Location,
|
||||||
|
@ -86,20 +86,20 @@ pub enum HxResponseHeader {
|
||||||
TriggerAfterSwap,
|
TriggerAfterSwap,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HxResponseHeader {
|
impl HtmxResponseHeader {
|
||||||
pub fn as_str(&self) -> &'static str {
|
pub fn as_str(&self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
HxResponseHeader::Location => "HX-Location",
|
HtmxResponseHeader::Location => "HX-Location",
|
||||||
HxResponseHeader::PushUrl => "HX-Push-Url",
|
HtmxResponseHeader::PushUrl => "HX-Push-Url",
|
||||||
HxResponseHeader::Redirect => "HX-Redirect",
|
HtmxResponseHeader::Redirect => "HX-Redirect",
|
||||||
HxResponseHeader::Refresh => "HX-Refresh",
|
HtmxResponseHeader::Refresh => "HX-Refresh",
|
||||||
HxResponseHeader::ReplaceUrl => "HX-Replace-Url",
|
HtmxResponseHeader::ReplaceUrl => "HX-Replace-Url",
|
||||||
HxResponseHeader::Reswap => "HX-Reswap",
|
HtmxResponseHeader::Reswap => "HX-Reswap",
|
||||||
HxResponseHeader::Retarget => "HX-Retarget",
|
HtmxResponseHeader::Retarget => "HX-Retarget",
|
||||||
HxResponseHeader::Reselect => "HX-Reselect",
|
HtmxResponseHeader::Reselect => "HX-Reselect",
|
||||||
HxResponseHeader::Trigger => "HX-Trigger",
|
HtmxResponseHeader::Trigger => "HX-Trigger",
|
||||||
HxResponseHeader::TriggerAfterSettle => "HX-Trigger-After-Settle",
|
HtmxResponseHeader::TriggerAfterSettle => "HX-Trigger-After-Settle",
|
||||||
HxResponseHeader::TriggerAfterSwap => "HX-Trigger-After-Swap",
|
HtmxResponseHeader::TriggerAfterSwap => "HX-Trigger-After-Swap",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -124,7 +124,7 @@ where
|
||||||
async fn from_request_parts(parts: &mut Parts, _: &S) -> Result<Self, Self::Rejection> {
|
async fn from_request_parts(parts: &mut Parts, _: &S) -> Result<Self, Self::Rejection> {
|
||||||
if parts
|
if parts
|
||||||
.headers
|
.headers
|
||||||
.contains_key(HxRequestHeader::Boosted.as_str())
|
.contains_key(HtmxRequestHeader::Boosted.as_str())
|
||||||
{
|
{
|
||||||
return Ok(HxBoosted(true));
|
return Ok(HxBoosted(true));
|
||||||
} else {
|
} else {
|
||||||
|
@ -144,7 +144,7 @@ where
|
||||||
type Rejection = std::convert::Infallible;
|
type Rejection = std::convert::Infallible;
|
||||||
|
|
||||||
async fn from_request_parts(parts: &mut Parts, _: &S) -> Result<Self, Self::Rejection> {
|
async fn from_request_parts(parts: &mut Parts, _: &S) -> Result<Self, Self::Rejection> {
|
||||||
if let Some(url) = parts.headers.get(HxRequestHeader::CurrentUrl.as_str()) {
|
if let Some(url) = parts.headers.get(HtmxRequestHeader::CurrentUrl.as_str()) {
|
||||||
if let Ok(url) = url.to_str() {
|
if let Ok(url) = url.to_str() {
|
||||||
return Ok(HxCurrentUrl(url.to_string()));
|
return Ok(HxCurrentUrl(url.to_string()));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue