hx

package module
v0.0.1-dev.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 9, 2024 License: MIT Imports: 7 Imported by: 0

README

hx

A tiny set of server side HTMX helpers.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CurrentURL

func CurrentURL(req *http.Request) (*url.URL, error)

CurrentURL returns the value of the HX-Current-URL header, if present.

func IsBoosted

func IsBoosted(req *http.Request) bool

func IsHistoryRestoreRequest

func IsHistoryRestoreRequest(req *http.Request) bool

IsHistoryRestoreRequest reports whether the HX-History-Restore-Request request header set to "true".

func IsRequest

func IsRequest(req *http.Request) bool

IsRequest reports whether the HX-Request request header set to "true".

func Prompt

func Prompt(req *http.Request) (string, bool)

Prompt is the value of the HX-Prompt header, if present.

func SetLocation

func SetLocation(res http.ResponseWriter, url string)

SetLocation sets the HX-Location header to the given URL. See https://htmx.org/headers/hx-location/

func SetPreventHistoryUpdate

func SetPreventHistoryUpdate(res http.ResponseWriter)

func SetPushURL

func SetPushURL(res http.ResponseWriter, url string)

SetPushURL sets the HX-Push-Url header to the given URL. See https://htmx.org/headers/hx-push-url/

func SetRedirect

func SetRedirect(res http.ResponseWriter, url string)

SetRedirect sets the HX-Redirect header to the given URL. See https://htmx.org/reference/#response_headers

func SetRefresh

func SetRefresh(res http.ResponseWriter)

SetRefresh sets the HX-Refresh header to "true". It tells the client to refresh the page.

func SetReplaceURL

func SetReplaceURL(res http.ResponseWriter, url string)

SetReplaceURL sets the HX-Replace header to the given URL. See https://htmx.org/headers/hx-replace/

func SetSelect

func SetSelect(res http.ResponseWriter, value string)

SetSelect sets the HX-Reselect header to the given value.

func SetSwap

func SetSwap(res http.ResponseWriter, s Swap)

SetSwap sets the HX-Reswap header to the given value.

func SetTarget

func SetTarget(res http.ResponseWriter, value string)

SetTarget sets the HX-Retarget header to the given value.

func SetTriggerAfterSettleEvents

func SetTriggerAfterSettleEvents(res http.ResponseWriter, events ...string)

func SetTriggerAfterSettleWithData

func SetTriggerAfterSettleWithData(res http.ResponseWriter, data EventsWithData) error

func SetTriggerAfterSwapEvents

func SetTriggerAfterSwapEvents(res http.ResponseWriter, events ...string)

func SetTriggerAfterSwapWithData

func SetTriggerAfterSwapWithData(res http.ResponseWriter, data EventsWithData) error

func SetTriggerEvents

func SetTriggerEvents(res http.ResponseWriter, events ...string)

func SetTriggerWithData

func SetTriggerWithData(res http.ResponseWriter, data EventsWithData) error

func Target

func Target(req *http.Request) (string, bool)

Target is the value of the HX-Target header, if present.

func TriggerID

func TriggerID(req *http.Request) (string, bool)

TriggerID is the value of the HX-Trigger header, if present.

func TriggerName

func TriggerName(req *http.Request) (string, bool)

TriggerName is the value of the HX-Trigger-Name header, if present.

Types

type EventsWithData

type EventsWithData struct {
	// contains filtered or unexported fields
}

func NewEventsWithData

func NewEventsWithData(event string, data any) EventsWithData

func (EventsWithData) MarshalJSON

func (e EventsWithData) MarshalJSON() ([]byte, error)

func (EventsWithData) Set

func (e EventsWithData) Set(event string, data any) EventsWithData

type Swap

type Swap string
const (
	SwapInnerHTML   Swap = "innerHTML"
	SwapOuterHTML   Swap = "outerHTML"
	SwapTextContent Swap = "textContent"
	SwapBeforeBegin Swap = "beforebegin"
	SwapAfterBegin  Swap = "afterbegin"
	SwapBeforeEnd   Swap = "beforeend"
	SwapAfterEnd    Swap = "afterend"
	SwapDelete      Swap = "delete"
	SwapNone        Swap = "none"
)

func (Swap) WithTransition

func (s Swap) WithTransition() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL