Documentation ¶
Overview ¶
Package htmxtools contains helpers and such for working with htmx from go
Index ¶
Constants ¶
const ( // Request headers // HXRequestHeader is the header that signals an htmx request. Always true if called from htmx HXRequestHeader HTMXRequestHeader = hxHeaderPrefix + "Request" // BoostedRequest indicates that the request is via an element using hx-boost BoostedRequest HTMXRequestHeader = hxHeaderPrefix + "Boosted" // CurrentURLRequest the current URL of the browser CurrentURLRequest HTMXRequestHeader = hxHeaderPrefix + "Current-URL" // HistoryRestoreRequest is true if the request is for history restoration after a miss in the local history cache HistoryRestoreRequest HTMXRequestHeader = hxHeaderPrefix + "History-Restore-Request" // PromptRequest is the user response to an hx-prompt // https://htmx.org/attributes/hx-prompt/ PromptRequest HTMXRequestHeader = hxHeaderPrefix + "Prompt" // TriggerRequest is the id of the target element if it exists TriggerRequest HTMXRequestHeader = hxHeaderPrefix + "Trigger" // TriggerNameRequest is the name of the triggered element if it exists TriggerNameRequest HTMXRequestHeader = hxHeaderPrefix + "Trigger-Name" // TargetRequest is the id of the target element if it exists TargetRequest HTMXRequestHeader = hxHeaderPrefix + "Target" // Response headers // LocationResponse Allows you to do a client-side redirect that does not do a full page reload // https://htmx.org/headers/hx-location/ LocationResponse HTMXResponseHeader = hxHeaderPrefix + "Location" // PushURLResponse pushes a new url into the history stack // https://htmx.org/headers/hx-push-url/ PushURLResponse HTMXResponseHeader = hxHeaderPrefix + "Push-Url" // RedirectResponse can be used to do a client-side redirect to a new location RedirectResponse HTMXResponseHeader = hxHeaderPrefix + "Redirect" // RefreshResponse if set to “true” the client side will do a a full refresh of the page RefreshResponse HTMXResponseHeader = hxHeaderPrefix + "Refresh" // ReplaceURLResponse replaces the current URL in the location bar // https://htmx.org/headers/hx-replace-url/ ReplaceURLResponse HTMXResponseHeader = hxHeaderPrefix + "Replace-Url" // ReswapResponse Allows you to specify how the response will be swapped. See hx-swap for possible values ReswapResponse HTMXResponseHeader = hxHeaderPrefix + "Reswap" // RetargetResponse A CSS selector that updates the target of the content update to a different element on the page RetargetResponse HTMXResponseHeader = hxHeaderPrefix + "Retarget" // TriggerResponse allows you to trigger client side events, see the documentation for more info // https://htmx.org/headers/hx-trigger/ TriggerResponse HTMXResponseHeader = hxHeaderPrefix + "Trigger" // TriggerAfterSettleResponse allows you to trigger client side events, see the documentation for more info // https://htmx.org/headers/hx-trigger/ TriggerAfterSettleResponse HTMXResponseHeader = hxHeaderPrefix + "Trigger-After-Settle" // TriggerAfterSwapResponse allows you to trigger client side events, see the documentation for more info // https://htmx.org/headers/hx-trigger/ TriggerAfterSwapResponse HTMXResponseHeader = hxHeaderPrefix + "Trigger-After-Swap" )
https://htmx.org/reference/#headers http headers are supposed to be case sensitive but in case something isn't behaving somewhere, we'll use the case from the project's page
Variables ¶
This section is empty.
Functions ¶
func WrapFunc ¶
func WrapFunc(next http.HandlerFunc) http.HandlerFunc
WrapFunc is middleware for inspecting http requests for htmx metadata
Types ¶
type HTMXRequest ¶
type HTMXRequest struct { // https://htmx.org/attributes/hx-boost/ Boosted bool CurrentURL string HistoryRestore bool // https://htmx.org/attributes/hx-prompt/ Prompt string Target string TriggerName string Trigger string }
HTMXRequest represents the htmx elements of an http.Request fields may be empty strings
func ParseRequest ¶
func ParseRequest(r *http.Request) *HTMXRequest
ParseRequest parses an http.Request for any htmx request headers and returns an HTMXRequest fields will still have to be checked for empty string at call sites
func RequestFromContext ¶
func RequestFromContext(ctx context.Context) *HTMXRequest
RequestFromContext parses the htmx request from the provided context
type HTMXResponse ¶
type HTMXResponse struct { // https://htmx.org/headers/hx-location/ Location string // https://htmx.org/headers/hx-push-url/ PushURL string Redirect string Refresh bool // https://htmx.org/headers/hx-replace-url/ ReplaceURL string // https://htmx.org/attributes/hx-swap/ Reswap HXSwap // https://htmx.org/headers/hx-trigger/ Trigger string // https://htmx.org/headers/hx-trigger/ TriggerAfterSettle string // https://htmx.org/headers/hx-trigger/ TriggerAfterSwap string }
HTMXResponse represents the htmx elements of an http.Response
func (*HTMXResponse) AddToResponse ¶
func (hr *HTMXResponse) AddToResponse(w http.ResponseWriter) error
AddToResponse adds the current state of the HTMXResponse to the http response headers
type HXLocationResponse ¶
type HXLocationResponse struct { Path string `json:"path"` Source string `json:"source,omitempty"` Event string `json:"event,omitempty"` Handler string `json:"handler,omitempty"` Target string `json:"target,omitempty"` Swap HXSwap `json:"swap,omitempty"` Values map[string]interface{} `json:"value,omitempty"` Headers map[string]string `json:"headers,omitempty"` }
HXLocationResponse represents the structured format of an hx-location header described here: https://htmx.org/headers/hx-location/
type HXSwap ¶
type HXSwap int64
HXSwap - https://htmx.org/attributes/hx-swap/
const ( // SwapUnknown is the zero value for the enum SwapUnknown HXSwap = iota // SwapInnerHTML - The default, replace the inner html of the target element - probably no reason to ever set this explicitly SwapInnerHTML // SwapOuterHTML - Replace the entire target element with the response SwapOuterHTML // SwapBeforeBegin - Insert the response before the target element SwapBeforeBegin // SwapAfterBegin - Insert the response before the first child of the target element SwapAfterBegin // SwapBeforeEnd - Insert the response after the last child of the target element SwapBeforeEnd // SwapAfterEnd - Insert the response after the target element SwapAfterEnd // SwapDelete - Deletes the target element regardless of the response SwapDelete // SwapNone - Does not append content from response (out of band items will still be processed). SwapNone )
func HXSwapFromString ¶
HXSwapFromString returns an [HXSWap] from its string representation