From 435cbf56db2edeabcf0233b44cffedeac83a5235 Mon Sep 17 00:00:00 2001 From: Rob Wagner Date: Mon, 23 Oct 2023 21:37:20 -0400 Subject: [PATCH] Update comments; fix naming on serde::Hx* variants --- src/responders.rs | 23 +++++++++++++---------- src/responders/serde.rs | 27 +++++++++++++++++---------- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/src/responders.rs b/src/responders.rs index e41331b..22709d3 100644 --- a/src/responders.rs +++ b/src/responders.rs @@ -22,7 +22,9 @@ const HX_SWAP_NONE: &str = "none"; /// The `HX-Location` header. /// /// This response header can be used to trigger a client side redirection -/// without reloading the whole page. +/// without reloading the whole page. If you intend to redirect to a specific +/// target on the page, you must enable the `serde` feature flag and use +/// `axum_htmx::responders::serde::HxLocation` instead. /// /// Will fail if the supplied Uri contains characters that are not visible ASCII /// (32-127). @@ -205,9 +207,9 @@ impl IntoResponseParts for HxReselect { /// The `HX-Trigger` header. /// -/// Allows you to trigger client-side events. This only accepts events without -/// data attached. If you intend to add data to the event, you must enable the -/// `serde` feature flag. +/// Allows you to trigger client-side events. If you intend to add data to your +/// events, you must enable the `serde` feature flag and use +/// `axum_htmx::responders::serde::HxResponseTrigger` instead. /// /// Will fail if the supplied events contain or produce characters that are not /// visible ASCII (32-127) when serializing to JSON. @@ -236,9 +238,10 @@ impl IntoResponseParts for HxResponseTrigger { /// The `HX-Trigger-After-Settle` header. /// -/// Allows you to trigger client-side events after the settle step. This only -/// accepts events without data attached. If you intend to add data to the -/// event, you must enable the `serde` feature flag. +/// Allows you to trigger client-side events after the settle step. If you +/// intend to add data to your events, you must enable the `serde` feature flag +/// and use `axum_htmx::responders::serde::HxResponseTriggerAfterSettle` +/// instead. /// /// Will fail if the supplied events contain or produce characters that are not /// visible ASCII (32-127) when serializing to JSON. @@ -267,9 +270,9 @@ impl IntoResponseParts for HxResponseTriggerAfterSettle { /// The `HX-Trigger-After-Swap` header. /// -/// Allows you to trigger client-side events after the swap step. This only -/// accepts events without data attached. If you intend to add data to the -/// event, you must enable the `serde` feature flag. +/// Allows you to trigger client-side events after the swap step. If you intend +/// to add data to your events, you must enable the `serde` feature flag and use +/// `axum_htmx::responders::serde::HxResponseTriggerAfterSwap` instead. /// /// Will fail if the supplied events contain or produce characters that are not /// visible ASCII (32-127) when serializing to JSON. diff --git a/src/responders/serde.rs b/src/responders/serde.rs index 8a3a06e..3bb7219 100644 --- a/src/responders/serde.rs +++ b/src/responders/serde.rs @@ -19,7 +19,9 @@ use crate::{ /// The `HX-Location` header. /// /// This response header can be used to trigger a client side redirection -/// without reloading the whole page. +/// without reloading the whole page. If you only intend to redirect to the +/// `document.body`, as opposed to a specific target, you can use +/// `axum_htmx::responders::HxResponseLocation` instead. /// /// Will fail if the supplied data contains or produces characters that are not /// visible ASCII (32-127) when serializing to JSON. @@ -85,16 +87,17 @@ impl IntoResponseParts for HxLocation { /// The `HX-Trigger` header. /// -/// Allows you to trigger client-side events. +/// Allows you to trigger client-side events. If you only need to send bare +/// events, you can use `axum_htmx::responders::HxResponseTrigger` instead. /// /// Will fail if the supplied events contain or produce characters that are not /// visible ASCII (32-127) when serializing to JSON. /// /// See for more information. #[derive(Debug, Clone)] -pub struct HxTrigger(pub Vec); +pub struct HxResponseTrigger(pub Vec); -impl IntoResponseParts for HxTrigger { +impl IntoResponseParts for HxResponseTrigger { type Error = HxError; fn into_response_parts(self, mut res: ResponseParts) -> Result { @@ -107,16 +110,18 @@ impl IntoResponseParts for HxTrigger { /// The `HX-Trigger-After-Settle` header. /// -/// Allows you to trigger client-side events after the settle step. +/// Allows you to trigger client-side events after the settle step. If you only +/// intend to send bare events, you can use +/// `axum_htmx::responders::HxResponseTriggerAfterSettle` instead. /// /// Will fail if the supplied events contain or produce characters that are not /// visible ASCII (32-127) when serializing to JSON. /// /// See for more information. #[derive(Debug, Clone)] -pub struct HxTriggerAfterSettle(Vec); +pub struct HxResponseTriggerAfterSettle(pub Vec); -impl IntoResponseParts for HxTriggerAfterSettle { +impl IntoResponseParts for HxResponseTriggerAfterSettle { type Error = HxError; fn into_response_parts(self, mut res: ResponseParts) -> Result { @@ -131,16 +136,18 @@ impl IntoResponseParts for HxTriggerAfterSettle { /// The `HX-Trigger-After-Swap` header. /// -/// Allows you to trigger client-side events after the swap step. +/// Allows you to trigger client-side events after the swap step. If you only +/// need to send bare events, you can use +/// `axum_htmx::responders::HxResponseTriggerAfterSwao` instead. /// /// Will fail if the supplied events contain or produce characters that are not /// visible ASCII (32-127) when serializing to JSON. /// /// See for more information. #[derive(Debug, Clone)] -pub struct HxTriggerAfterSwap(Vec); +pub struct HxResponseTriggerAfterSwap(pub Vec); -impl IntoResponseParts for HxTriggerAfterSwap { +impl IntoResponseParts for HxResponseTriggerAfterSwap { type Error = HxError; fn into_response_parts(self, mut res: ResponseParts) -> Result {