Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
robertwayne committed Dec 3, 2023
1 parent 9d559d0 commit 29dbadc
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
18 changes: 9 additions & 9 deletions src/extractors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>);

Expand All @@ -60,7 +60,7 @@ where
.to_str()
.ok()
.and_then(|url| url.parse::<http::Uri>().ok());

return Ok(HxCurrentUrl(url));
}

Expand All @@ -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);

Expand Down Expand Up @@ -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`.
Expand Down Expand Up @@ -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`.
Expand Down
5 changes: 3 additions & 2 deletions src/responders/location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl HxLocation {
path: self.uri.to_string(),
opts: self.options,
};

Ok(serde_json::to_string(&loc_with_opts)?)
}
}
Expand Down Expand Up @@ -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)]
Expand Down
18 changes: 11 additions & 7 deletions src/responders/trigger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -118,25 +118,29 @@ 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,
events: events.into_iter().map(Into::into).collect(),
}
}

/// 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)
}
Expand Down

0 comments on commit 29dbadc

Please sign in to comment.