mirror of
https://github.com/robertwayne/axum-htmx
synced 2024-12-25 01:49:31 +01:00
Formatting
This commit is contained in:
parent
9d559d0041
commit
29dbadc8bc
3 changed files with 23 additions and 18 deletions
|
@ -42,8 +42,8 @@ where
|
|||
/// This is set on every request made by htmx itself. As its name implies, it
|
||||
/// just contains the current url.
|
||||
///
|
||||
/// This extractor will always return a value. If the header is not present, or extractor fails to parse the url
|
||||
/// it will return `None`.
|
||||
/// This extractor will always return a value. If the header is not present, or
|
||||
/// extractor fails to parse the url it will return `None`.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct HxCurrentUrl(pub Option<http::Uri>);
|
||||
|
||||
|
@ -60,7 +60,7 @@ where
|
|||
.to_str()
|
||||
.ok()
|
||||
.and_then(|url| url.parse::<http::Uri>().ok());
|
||||
|
||||
|
||||
return Ok(HxCurrentUrl(url));
|
||||
}
|
||||
|
||||
|
@ -70,8 +70,8 @@ where
|
|||
|
||||
/// The `HX-History-Restore-Request` header.
|
||||
///
|
||||
/// This extractor will always return a value. If the header is not present,
|
||||
/// it will return `false`.
|
||||
/// This extractor will always return a value. If the header is not present, it
|
||||
/// will return `false`.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct HxHistoryRestoreRequest(pub bool);
|
||||
|
||||
|
@ -148,8 +148,8 @@ where
|
|||
/// The `HX-Target` header.
|
||||
///
|
||||
/// This is set when a request is made from an element that has the `hx-target`
|
||||
/// attribute set. The value will contain the target element's id. If the
|
||||
/// id does not exist on the page, the value will be None.
|
||||
/// attribute set. The value will contain the target element's id. If the id
|
||||
/// does not exist on the page, the value will be None.
|
||||
///
|
||||
/// This extractor will always return a value. If the header is not present, it
|
||||
/// will return `None`.
|
||||
|
@ -206,8 +206,8 @@ where
|
|||
/// The `HX-Trigger` header.
|
||||
///
|
||||
/// This is set when a request is made from an element that has the `hx-trigger`
|
||||
/// attribute set. The value will contain the trigger element's id. If the
|
||||
/// id does not exist on the page, the value will be None.
|
||||
/// attribute set. The value will contain the trigger element's id. If the id
|
||||
/// does not exist on the page, the value will be None.
|
||||
///
|
||||
/// This extractor will always return a value. If the header is not present, it
|
||||
/// will return `None`.
|
||||
|
|
|
@ -83,7 +83,7 @@ impl HxLocation {
|
|||
path: self.uri.to_string(),
|
||||
opts: self.options,
|
||||
};
|
||||
|
||||
|
||||
Ok(serde_json::to_string(&loc_with_opts)?)
|
||||
}
|
||||
}
|
||||
|
@ -147,7 +147,8 @@ impl IntoResponseParts for HxLocation {
|
|||
/// - `swap` - how the response will be swapped in relative to the target
|
||||
/// - `values` - values to submit with the request
|
||||
/// - `headers` - headers to submit with the request
|
||||
/// - `select` - allows you to select the content you want swapped from a response
|
||||
/// - `select` - allows you to select the content you want swapped from a
|
||||
/// response
|
||||
#[cfg(feature = "serde")]
|
||||
#[cfg_attr(feature = "unstable", doc(cfg(feature = "serde")))]
|
||||
#[derive(Debug, Clone, serde::Serialize, Default)]
|
||||
|
|
|
@ -103,9 +103,9 @@ pub enum TriggerMode {
|
|||
|
||||
/// The `HX-Trigger*` header.
|
||||
///
|
||||
/// Allows you to trigger client-side events.
|
||||
/// Corresponds to `HX-Trigger`, `HX-Trigger-After-Settle` and `HX-Trigger-After-Swap` headers.
|
||||
/// To change when events trigger use appropriate `mode`.
|
||||
/// Allows you to trigger client-side events. Corresponds to `HX-Trigger`,
|
||||
/// `HX-Trigger-After-Settle` and `HX-Trigger-After-Swap` headers. To change
|
||||
/// when events trigger use appropriate `mode`.
|
||||
///
|
||||
/// Will fail if the supplied events contain or produce characters that are not
|
||||
/// visible ASCII (32-127) when serializing to JSON.
|
||||
|
@ -118,7 +118,8 @@ pub struct HxResponseTrigger {
|
|||
}
|
||||
|
||||
impl HxResponseTrigger {
|
||||
/// Creates new [trigger](https://htmx.org/headers/hx-trigger/) with specified mode and events.
|
||||
/// Creates new [trigger](https://htmx.org/headers/hx-trigger/) with
|
||||
/// specified mode and events.
|
||||
pub fn new<T: Into<HxEvent>>(mode: TriggerMode, events: impl IntoIterator<Item = T>) -> Self {
|
||||
Self {
|
||||
mode,
|
||||
|
@ -126,17 +127,20 @@ impl HxResponseTrigger {
|
|||
}
|
||||
}
|
||||
|
||||
/// Creates new [normal](https://htmx.org/headers/hx-trigger/) trigger from events.
|
||||
/// Creates new [normal](https://htmx.org/headers/hx-trigger/) trigger from
|
||||
/// events.
|
||||
pub fn normal<T: Into<HxEvent>>(events: impl IntoIterator<Item = T>) -> Self {
|
||||
Self::new(TriggerMode::Normal, events)
|
||||
}
|
||||
|
||||
/// Creates new [after settle](https://htmx.org/headers/hx-trigger/) trigger from events.
|
||||
/// Creates new [after settle](https://htmx.org/headers/hx-trigger/) trigger
|
||||
/// from events.
|
||||
pub fn after_settle<T: Into<HxEvent>>(events: impl IntoIterator<Item = T>) -> Self {
|
||||
Self::new(TriggerMode::AfterSettle, events)
|
||||
}
|
||||
|
||||
/// Creates new [after swap](https://htmx.org/headers/hx-trigger/) trigger from events.
|
||||
/// Creates new [after swap](https://htmx.org/headers/hx-trigger/) trigger
|
||||
/// from events.
|
||||
pub fn after_swap<T: Into<HxEvent>>(events: impl IntoIterator<Item = T>) -> Self {
|
||||
Self::new(TriggerMode::AfterSwap, events)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue