h

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2025 License: MIT Imports: 23 Imported by: 14

Documentation

Index

Constants

View Source
const RequestContextKey = "htmgo.request.context"

Variables

View Source
var Version = uuid.NewString()

Functions

func BaseExtensions

func BaseExtensions() string

func Cached

func Cached(duration time.Duration, cb GetElementFunc) func() *Element

Cached caches the given element for the given duration. The element is only rendered once, and then cached for the given duration. Please note this element is globally cached, and not per unique identifier / user. Use CachedPerKey to cache elements per unqiue identifier.

func CachedPerKey

func CachedPerKey[K comparable](duration time.Duration, cb GetElementFuncWithKey[K]) func() *Element

CachedPerKey caches the given element for the given duration. The element is only rendered once per key, and then cached for the given duration. The element is cached by the unique identifier that is returned by the callback function.

func CachedPerKeyT

func CachedPerKeyT[K comparable, T any](duration time.Duration, cb GetElementFuncTWithKey[K, T]) func(T) *Element

CachedPerKeyT caches the given element for the given duration. The element is only rendered once per key, and then cached for the given duration. The element is cached by the unique identifier that is returned by the callback function.

func CachedPerKeyT2

func CachedPerKeyT2[K comparable, T any, T2 any](duration time.Duration, cb GetElementFuncT2WithKey[K, T, T2]) func(T, T2) *Element

CachedPerKeyT2 caches the given element for the given duration. The element is only rendered once per key, and then cached for the given duration. The element is cached by the unique identifier that is returned by the callback function.

func CachedPerKeyT3

func CachedPerKeyT3[K comparable, T any, T2 any, T3 any](duration time.Duration, cb GetElementFuncT3WithKey[K, T, T2, T3]) func(T, T2, T3) *Element

CachedPerKeyT3 caches the given element for the given duration. The element is only rendered once per key, and then cached for the given duration. The element is cached by the unique identifier that is returned by the callback function.

func CachedPerKeyT4

func CachedPerKeyT4[K comparable, T any, T2 any, T3 any, T4 any](duration time.Duration, cb GetElementFuncT4WithKey[K, T, T2, T3, T4]) func(T, T2, T3, T4) *Element

CachedPerKeyT4 caches the given element for the given duration. The element is only rendered once per key, and then cached for the given duration. The element is cached by the unique identifier that is returned by the callback function.

func CachedT

func CachedT[T any](duration time.Duration, cb GetElementFuncT[T]) func(T) *Element

CachedT caches the given element for the given duration. The element is only rendered once, and then cached for the given duration. Please note this element is globally cached, and not per unique identifier / user. Use CachedPerKey to cache elements per unqiue identifier.

func CachedT2

func CachedT2[T any, T2 any](duration time.Duration, cb GetElementFuncT2[T, T2]) func(T, T2) *Element

CachedT2 caches the given element for the given duration. The element is only rendered once, and then cached for the given duration. Please note this element is globally cached, and not per unique identifier / user. Use CachedPerKey to cache elements per unqiue identifier.

func CachedT3

func CachedT3[T any, T2 any, T3 any](duration time.Duration, cb GetElementFuncT3[T, T2, T3]) func(T, T2, T3) *Element

CachedT3 caches the given element for the given duration. The element is only rendered once, and then cached for the given duration. Please note this element is globally cached, and not per unique identifier / user. Use CachedPerKey to cache elements per unqiue identifier.

func CachedT4

func CachedT4[T any, T2 any, T3 any, T4 any](duration time.Duration, cb GetElementFuncT4[T, T2, T3, T4]) func(T, T2, T3, T4) *Element

CachedT4 caches the given element for the given duration. The element is only rendered once, and then cached for the given duration. Please note this element is globally cached, and not per unique identifier / user. Use CachedPerKey to cache elements per unqiue identifier.

func CombineCommands added in v1.0.5

func CombineCommands(cmds ...Command) string

func CurrentPath

func CurrentPath(ctx *RequestContext) string

func Filter

func Filter[T any](slice []T, predicate func(item T) bool) []T

Filter returns a new slice with only items that match the predicate.

func Find added in v1.0.5

func Find[T any](slice []T, predicate func(item *T) bool) *T

Find returns the first item in the slice that matches the predicate.

func GenId added in v1.0.5

func GenId(len int) string

func GetLogLevel

func GetLogLevel() slog.Level

func GetPartialPath

func GetPartialPath(partial PartialFunc) string

func GetPartialPathWithQs

func GetPartialPathWithQs(partial func(ctx *RequestContext) *Partial, qs *Qs) string

func GetQueryParam

func GetQueryParam(ctx *RequestContext, key string) string

GetQueryParam returns the value of the given query parameter from the request URL. There are two layers of priority: 1. The query parameter in the URL 2. The current browser URL If the query parameter is not found in the URL from the *RequestContext, it will fall back to the current browser URL if set. The URL from the *RequestContext would normally be the url from an XHR request through htmx, which is not the current browser url a visitor may be on.

func GroupBy added in v1.0.5

func GroupBy[T any, K comparable](slice []T, key func(item T) K) map[K][]T

GroupBy groups the items in the slice by the key returned by the key function.

func GroupByOrdered added in v1.0.5

func GroupByOrdered[T any, K comparable](slice []T, key func(item T) K) *orderedmap.Map[K, []T]

GroupByOrdered groups the items in the slice by the key returned by the key function, and returns an Map.

func HtmlView

func HtmlView(w http.ResponseWriter, page *Page) error

func IfElse

func IfElse[T any](condition bool, node T, node2 T) T

IfElse returns node if condition is true, otherwise returns node2

func IfElseLazy

func IfElseLazy[T any](condition bool, cb1 func() T, cb2 func() T) T

IfElseLazy returns node if condition is true, otherwise returns the result of cb2 This is useful if you want to lazily evaluate a node based on a condition For example, If you are rendering a component that requires specific data, you can use this to only load the component if the data is available

func IsDevelopment

func IsDevelopment() bool

func IsEmptyPartial added in v1.0.5

func IsEmptyPartial(partial *Partial) bool

func IsProduction

func IsProduction() bool

func IsWatchMode

func IsWatchMode() bool

func JsonSerializeOrEmpty

func JsonSerializeOrEmpty(data any) string

JsonSerializeOrEmpty serializes the given data as JSON, or returns an empty string if the serialization fails.

func Map

func Map[T, U any](slice []T, mapper func(item T) U) []U

Map returns a new slice with the results of the mapper function.

func MergeClasses

func MergeClasses(classes ...string) string

MergeClasses merges multiple classes into a single class string

func MultiLineQuotes

func MultiLineQuotes(text string) string

func PartialView

func PartialView(w http.ResponseWriter, partial *Partial) error

func PartialViewWithHeaders

func PartialViewWithHeaders(w http.ResponseWriter, headers *Headers, partial *Partial) error

func Render

func Render(node Ren, opts ...RenderOpt) string

Render renders the given node recursively, and returns the resulting string.

func SetQueryParams

func SetQueryParams(href string, qs *Qs) string

SetQueryParams sets the query parameters of the given URL. Given the *Qs passed in, it will set the query parameters of the URL to the given values. If the value does not exist in *QS, it will remain untouched. If the value is an empty string, it will be removed from the query parameters. If the value is not an empty string, it will be set to the given value.

func Start

func Start(opts AppOpts)

Start starts the htmgo server

func Ternary

func Ternary[T any](value bool, a T, b T) T

Ternary returns the first argument if the second argument is true, otherwise returns the third argument

func Unique

func Unique[T any](slice []T, key func(item T) string) []T

Unique returns a new slice with only unique items.

Types

type App

type App struct {
	Opts   AppOpts
	Router *chi.Mux
}

func (*App) AddLiveReloadHandler

func (app *App) AddLiveReloadHandler(path string)

func (*App) Use added in v1.0.5

func (app *App) Use(h func(ctx *RequestContext))

func (*App) UseWithContext

func (app *App) UseWithContext(h func(w http.ResponseWriter, r *http.Request, context map[string]any))

type AppOpts

type AppOpts struct {
	LiveReload     bool
	ServiceLocator *service.Locator
	Register       func(app *App)
	Port           int
}

type AttributeMap

type AttributeMap = map[string]any

type AttributeMapOrdered

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

func AttributeList

func AttributeList(children ...*AttributeR) *AttributeMapOrdered

func AttributePairs

func AttributePairs(pairs ...string) *AttributeMapOrdered

func Attributes

func Attributes(attributes *AttributeMap) *AttributeMapOrdered

func Get

func Get(path string, trigger ...string) *AttributeMapOrdered

Get adds two attributes to the element: hx-get and hx-trigger.

func GetPartial

func GetPartial(partial PartialFunc, trigger ...string) *AttributeMapOrdered

GetPartial adds two attributes to the element: hx-get and hx-trigger, and uses the partial path for the hx-get attribute.

func GetPartialWithQs

func GetPartialWithQs(partial PartialFunc, qs *Qs, trigger string) *AttributeMapOrdered

GetPartialWithQs adds two attributes to the element: hx-get and hx-trigger, and uses the partial path for the hx-get attribute. It also sets the query string parameters.

func GetWithQs

func GetWithQs(path string, qs *Qs, trigger string) *AttributeMapOrdered

GetWithQs adds two attributes to the element: hx-get and hx-trigger, and uses the path for the hx-get attribute. It also sets the query string parameters.

func NewAttributeMap

func NewAttributeMap(pairs ...string) *AttributeMapOrdered

func Post

func Post(url string, trigger ...string) *AttributeMapOrdered

func PostOnClick

func PostOnClick(url string) *AttributeMapOrdered

PostOnClick adds two attributes to the element: hx-post and hx-trigger, and uses the path for the hx-post attribute. It also sets the hx-trigger to hx-click.

func PostPartial

func PostPartial(partial PartialFunc, triggers ...string) *AttributeMapOrdered

PostPartial adds two attributes to the element: hx-post and hx-trigger, and uses the partial path for the hx-post attribute.

func PostPartialOnClick

func PostPartialOnClick(partial PartialFunc) *AttributeMapOrdered

PostPartialOnClick adds two attributes to the element: hx-post and hx-trigger, and uses the partial path for the hx-post attribute. It also sets the hx-trigger to hx-click.

func PostPartialOnClickQs

func PostPartialOnClickQs(partial PartialFunc, qs *Qs) *AttributeMapOrdered

PostPartialOnClickQs adds two attributes to the element: hx-post and hx-trigger, and uses the partial path for the hx-post attribute. It also sets the hx-trigger to hx-click. It also sets the query string parameters.

func PostPartialWithQs

func PostPartialWithQs(partial PartialFunc, qs *Qs, trigger ...string) *AttributeMapOrdered

PostPartialWithQs adds two attributes to the element: hx-post and hx-trigger, and uses the partial path for the hx-post attribute. It also sets the query string parameters.

func PostWithQs

func PostWithQs(url string, qs *Qs, trigger string) *AttributeMapOrdered

PostWithQs adds two attributes to the element: hx-post and hx-trigger, and uses the path for the hx-post attribute. It also sets the query string parameters.

func (*AttributeMapOrdered) Each

func (m *AttributeMapOrdered) Each(cb func(key string, value string))

func (*AttributeMapOrdered) Entries

func (*AttributeMapOrdered) Render

func (m *AttributeMapOrdered) Render(context *RenderContext)

func (*AttributeMapOrdered) Set

func (m *AttributeMapOrdered) Set(key string, value any)

type AttributeR

type AttributeR struct {
	Name  string
	Value string
}

func Action

func Action(value string) *AttributeR

func AriaHidden

func AriaHidden(value bool) *AttributeR

func AriaLabel

func AriaLabel(value string) *AttributeR

func Attribute

func Attribute(key string, value string) *AttributeR

func AutoComplete

func AutoComplete(value string) *AttributeR

func AutoFocus

func AutoFocus() *AttributeR

func Class

func Class(value ...string) *AttributeR

func ClassF added in v1.0.1

func ClassF(format string, args ...interface{}) *AttributeR

ClassF is a helper function to create a class attribute with the given format string and arguments

func Cols

func Cols(value int) *AttributeR

func Disabled

func Disabled() *AttributeR

func Download

func Download(value bool) *AttributeR

func Enctype

func Enctype(value string) *AttributeR

func Height

func Height(value int) *AttributeR

func HxExtension

func HxExtension(value string) *AttributeR

HxExtension Adds a hx-ext to an element

func HxIndicator

func HxIndicator(tag string) *AttributeR

func HxTrigger

func HxTrigger(opts ...hx.TriggerEvent) *AttributeR

HxTrigger Adds a hx-trigger to an element

func HxTriggerClick

func HxTriggerClick(opts ...hx.Modifier) *AttributeR

HxTriggerClick Adds a hx-trigger="click" to an element

func HxTriggerString

func HxTriggerString(triggers ...string) *AttributeR

HxTriggerString Adds a hx-trigger to an element based on a string of triggers

func JoinAttributes

func JoinAttributes(sep string, attrs ...*AttributeR) *AttributeR

JoinAttributes joins multiple attributes into a single attribute string based on a separator Example: JoinAttributes(", ", Attribute("hx-extension", "one"), Attribute("hx-extension", "two")) = hx-extension="one,two"

func Max

func Max(value string) *AttributeR

func MaxLength

func MaxLength(value int) *AttributeR

func Method

func Method(value string) *AttributeR

func Min

func Min(value string) *AttributeR

func MinLength

func MinLength(value int) *AttributeR

func Multiple

func Multiple() *AttributeR

func NewAttribute

func NewAttribute(name string, value string) *AttributeR

func NoSwap

func NoSwap() *AttributeR

func NoValidate

func NoValidate() *AttributeR

func Pattern

func Pattern(value string) *AttributeR

func ReadOnly

func ReadOnly() *AttributeR

func Rel

func Rel(value string) *AttributeR

func Required

func Required() *AttributeR

func Role

func Role(value string) *AttributeR

func Rows

func Rows(value int) *AttributeR

func Selected

func Selected() *AttributeR

func Size

func Size(value int) *AttributeR

func Src

func Src(src string) *AttributeR

func Step

func Step(value string) *AttributeR

func TabIndex

func TabIndex(value int) *AttributeR

func TriggerChildren

func TriggerChildren() *AttributeR

TriggerChildren Adds the hx-extension="trigger-children" to an element See https://htmgo.dev/docs#htmx-extensions-trigger-children

func Value

func Value(value any) *AttributeR

func Width

func Width(value int) *AttributeR

func Wrap

func Wrap(value string) *AttributeR

func (*AttributeR) Render

func (a *AttributeR) Render(context *RenderContext)

type ByKeyEntry

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

func (*ByKeyEntry) Render

func (c *ByKeyEntry) Render(ctx *RenderContext)

type CachedNode

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

func (*CachedNode) ClearCache

func (c *CachedNode) ClearCache()

ClearCache clears the cached HTML of the element. This is called automatically by the framework.

func (*CachedNode) ClearExpired

func (c *CachedNode) ClearExpired()

ClearExpired clears all expired cached HTML of the element. This is called automatically by the framework.

func (*CachedNode) Render

func (c *CachedNode) Render(ctx *RenderContext)

type ChildList

type ChildList struct {
	Children []Ren
}

func Children

func Children(children ...Ren) *ChildList

func NewChildList

func NewChildList(children ...Ren) *ChildList

func (*ChildList) Render

func (c *ChildList) Render(context *RenderContext)

type ClassMap

type ClassMap map[string]bool

type Command

type Command = Ren

func ToggleText added in v1.0.5

func ToggleText(text string, textTwo string) Command

ToggleText toggles the given text on the element.

func ToggleTextOnChildren added in v1.0.5

func ToggleTextOnChildren(selector, text string, textTwo string) Command

ToggleTextOnChildren toggles the given text on the children of the element.

func ToggleTextOnParent added in v1.0.5

func ToggleTextOnParent(text string, textTwo string) Command

ToggleTextOnParent toggles the given text on the parent of the element.

func ToggleTextOnSibling added in v1.0.5

func ToggleTextOnSibling(selector, text string, textTwo string) Command

ToggleTextOnSibling toggles the given text on the siblings of the element.

type ComplexJsCommand

type ComplexJsCommand struct {
	Command      string
	TempFuncName string
}

func EvalCommands added in v1.0.5

func EvalCommands(element *Element, cmds ...Command) ComplexJsCommand

func EvalCommandsOnSelector added in v1.0.5

func EvalCommandsOnSelector(selector string, cmds ...Command) ComplexJsCommand

func EvalJs

func EvalJs(js string) ComplexJsCommand

EvalJs evaluates the given JavaScript code.

func EvalJsOnChildren

func EvalJsOnChildren(selector, js string) ComplexJsCommand

EvalJsOnChildren evaluates the given JavaScript code on the children of the element. Reference the element using 'element'.

func EvalJsOnParent

func EvalJsOnParent(js string) ComplexJsCommand

EvalJsOnParent evaluates the given JavaScript code on the parent of the element. Reference the element using 'element'.

func EvalJsOnSibling

func EvalJsOnSibling(selector, js string) ComplexJsCommand

EvalJsOnSibling evaluates the given JavaScript code on the siblings of the element. Reference the element using 'element'.

func InjectScript

func InjectScript(src string) ComplexJsCommand

InjectScript injects a script tag into the document.

func InjectScriptIfNotExist

func InjectScriptIfNotExist(src string) ComplexJsCommand

InjectScriptIfNotExist injects a script tag into the document if it does not already exist.

func NewComplexJsCommand

func NewComplexJsCommand(command string) ComplexJsCommand

NewComplexJsCommand creates a new complex JavaScript command.

func RemoveClassOnChildren

func RemoveClassOnChildren(selector, class string) ComplexJsCommand

RemoveClassOnChildren removes the given class from the children of the element. Reference the element using 'element'.

func RemoveClassOnParent

func RemoveClassOnParent(class string) ComplexJsCommand

RemoveClassOnParent removes the given class from the parent of the element.

func RemoveClassOnSibling

func RemoveClassOnSibling(selector, class string) ComplexJsCommand

RemoveClassOnSibling removes the given class from the siblings of the element. Reference the element using 'element'.

func RunAfterTimeout added in v1.0.5

func RunAfterTimeout(time time.Duration, cmds ...Command) ComplexJsCommand

func RunOnInterval added in v1.0.5

func RunOnInterval(time time.Duration, cmds ...Command) ComplexJsCommand

func SetClassOnChildren

func SetClassOnChildren(selector, class string) ComplexJsCommand

SetClassOnChildren sets the given class on the children of the element.

func SetClassOnParent

func SetClassOnParent(class string) ComplexJsCommand

SetClassOnParent sets the given class on the parent of the element.

func SetClassOnSibling

func SetClassOnSibling(selector, class string) ComplexJsCommand

SetClassOnSibling sets the given class on the siblings of the element. Reference the element using 'element'.

func SetTextOnChildren

func SetTextOnChildren(selector, text string) ComplexJsCommand

SetTextOnChildren sets the inner text of all the children of the element that match the selector.

func SubmitFormOnEnter

func SubmitFormOnEnter() ComplexJsCommand

SubmitFormOnEnter submits the form when the user presses the enter key.

func ToggleClassOnChildren added in v1.0.5

func ToggleClassOnChildren(selector, class string) ComplexJsCommand

ToggleClassOnChildren toggles the given class on the children of the element.

func ToggleClassOnElement

func ToggleClassOnElement(selector, class string) ComplexJsCommand

ToggleClassOnElement toggles the given class on the elements returned by the selector.

func ToggleClassOnParent added in v1.0.5

func ToggleClassOnParent(class string) ComplexJsCommand

ToggleClassOnParent toggles the given class on the parent of the element.

func ToggleClassOnSibling added in v1.0.5

func ToggleClassOnSibling(selector, class string) ComplexJsCommand

ToggleClassOnSibling toggles the given class on the siblings of the element.

func (ComplexJsCommand) Render

func (j ComplexJsCommand) Render(context *RenderContext)

type CustomElement

type CustomElement = string
var (
	CachedNodeTag        CustomElement = "htmgo_cache_node"
	CachedNodeByKeyEntry CustomElement = "htmgo_cached_node_by_key_entry"
)

type Element

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

func A

func A(children ...Ren) *Element

func Abbr

func Abbr(children ...Ren) *Element

func Address

func Address(children ...Ren) *Element

func AppendChildren

func AppendChildren(node *Element, children ...Ren) *Element

func Article

func Article(children ...Ren) *Element

func Aside

func Aside(children ...Ren) *Element

func Body

func Body(children ...Ren) *Element

func Br

func Br() *Element

func Button

func Button(children ...Ren) *Element

func Checkbox

func Checkbox(children ...Ren) *Element

func Code

func Code(children ...Ren) *Element

func Dd added in v1.0.5

func Dd(children ...Ren) *Element

func Details added in v1.0.1

func Details(children ...Ren) *Element

func Dialog

func Dialog(children ...Ren) *Element

func Div

func Div(children ...Ren) *Element

func Dl added in v1.0.5

func Dl(children ...Ren) *Element

func Dt added in v1.0.5

func Dt(children ...Ren) *Element

func ElementIf

func ElementIf(condition bool, element *Element) *Element

ElementIf returns the element if the condition is true, otherwise returns an empty element

func Empty

func Empty() *Element

func FieldSet

func FieldSet(children ...Ren) *Element

func FileInput

func FileInput(children ...Ren) *Element
func Footer(children ...Ren) *Element

func Form

func Form(children ...Ren) *Element

func Fragment

func Fragment(children ...Ren) *Element

func H1

func H1(children ...Ren) *Element

func H1F

func H1F(format string, args ...interface{}) *Element

func H2

func H2(children ...Ren) *Element

func H2F

func H2F(format string, args ...interface{}) *Element

func H3

func H3(children ...Ren) *Element

func H3F

func H3F(format string, args ...interface{}) *Element

func H4

func H4(children ...Ren) *Element

func H4F

func H4F(format string, args ...interface{}) *Element

func H5

func H5(children ...Ren) *Element

func H5F

func H5F(format string, args ...interface{}) *Element

func H6

func H6(children ...Ren) *Element

func H6F

func H6F(format string, args ...interface{}) *Element
func Head(children ...Ren) *Element
func Header(children ...Ren) *Element

func Hr

func Hr(children ...Ren) *Element

func Html

func Html(children ...Ren) *Element

func I

func I(children ...Ren) *Element

func IFrame

func IFrame(src string, children ...Ren) *Element

func IfElseE

func IfElseE(condition bool, element *Element, element2 *Element) *Element

IfElseE returns element if condition is true, otherwise returns element2

func Img

func Img(children ...Ren) *Element

func Input

func Input(inputType string, children ...Ren) *Element

func IterMap

func IterMap[T any](m map[string]T, mapper func(key string, value T) *Element) *Element

func Label

func Label(children ...Ren) *Element

func LabelFor

func LabelFor(id string, text string) *Element

func Li

func Li(children ...Ren) *Element
func Link(href string, rel string) *Element

func LinkWithVersion

func LinkWithVersion(href string, rel string, version string) *Element

func List

func List[T any](items []T, mapper func(item T, index int) *Element) *Element

func Main

func Main(children ...Ren) *Element

func Meta

func Meta(name string, content string) *Element
func Nav(children ...Ren) *Element

func NumberInput

func NumberInput(children ...Ren) *Element

func Ol

func Ol(children ...Ren) *Element

func OobSwap

func OobSwap(ctx *RequestContext, content *Element, option ...SwapOption) *Element

func OobSwapWithSelector

func OobSwapWithSelector(ctx *RequestContext, selector string, content *Element, option ...SwapOption) *Element

func Option

func Option(children ...Ren) *Element

func P

func P(children ...Ren) *Element

func Path

func Path(children ...Ren) *Element

func Pf

func Pf(format string, args ...interface{}) *Element

func Pre

func Pre(children ...Ren) *Element

func Radio

func Radio(children ...Ren) *Element

func Script

func Script(url string) *Element

func ScriptWithVersion

func ScriptWithVersion(url string, version string) *Element

func Section

func Section(children ...Ren) *Element

func Select

func Select(children ...Ren) *Element

func Span

func Span(children ...Ren) *Element

func Strong

func Strong(children ...Ren) *Element

func Style

func Style(text string) *Element

func Summary added in v1.0.1

func Summary(children ...Ren) *Element

func Svg

func Svg(children ...Ren) *Element

func SwapMany

func SwapMany(ctx *RequestContext, elements ...*Element) *Element

func SwapManyX

func SwapManyX(ctx *RequestContext, args ...SwapArg) *Element

func TBody

func TBody(children ...Ren) *Element

func TFoot

func TFoot(children ...Ren) *Element

func THead

func THead(children ...Ren) *Element

func Table

func Table(children ...Ren) *Element

func Tag

func Tag(tag string, children ...Ren) *Element

func TagF

func TagF(tag string, format string, args ...interface{}) *Element

func Td

func Td(children ...Ren) *Element

func Template

func Template(children ...Ren) *Element

func TextArea

func TextArea(children ...Ren) *Element

func TextInput

func TextInput(children ...Ren) *Element

func Th

func Th(children ...Ren) *Element

func Title

func Title(children ...Ren) *Element

func Tr

func Tr(children ...Ren) *Element

func Ul

func Ul(children ...Ren) *Element

func Video added in v1.0.5

func Video(children ...Ren) *Element

func (*Element) AppendChild

func (node *Element) AppendChild(child Ren) *Element

func (*Element) AppendChildren

func (node *Element) AppendChildren(children ...Ren) *Element

func (*Element) Render

func (node *Element) Render(context *RenderContext)

type Entry

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

type GetElementFunc

type GetElementFunc func() *Element

type GetElementFuncT

type GetElementFuncT[T any] func(T) *Element

type GetElementFuncT2

type GetElementFuncT2[T any, T2 any] func(T, T2) *Element

type GetElementFuncT2WithKey

type GetElementFuncT2WithKey[K comparable, T any, T2 any] func(T, T2) (K, GetElementFunc)

type GetElementFuncT3

type GetElementFuncT3[T any, T2 any, T3 any] func(T, T2, T3) *Element

type GetElementFuncT3WithKey

type GetElementFuncT3WithKey[K comparable, T any, T2 any, T3 any] func(T, T2, T3) (K, GetElementFunc)

type GetElementFuncT4

type GetElementFuncT4[T any, T2 any, T3 any, T4 any] func(T, T2, T3, T4) *Element

type GetElementFuncT4WithKey

type GetElementFuncT4WithKey[K comparable, T any, T2 any, T3 any, T4 any] func(T, T2, T3, T4) (K, GetElementFunc)

type GetElementFuncTWithKey

type GetElementFuncTWithKey[K comparable, T any] func(T) (K, GetElementFunc)

type GetElementFuncWithKey

type GetElementFuncWithKey[K comparable] func() (K, GetElementFunc)

type Headers

type Headers = map[string]string

func CombineHeaders

func CombineHeaders(headers ...*Headers) *Headers

func NewHeaders

func NewHeaders(headers ...string) *Headers

func PushQsHeader

func PushQsHeader(ctx *RequestContext, qs *Qs) *Headers

func PushUrlHeader

func PushUrlHeader(url string) *Headers

func ReplaceUrlHeader

func ReplaceUrlHeader(url string) *Headers

type KeyValue

type KeyValue[T any] struct {
	Key   string
	Value T
}

type LifeCycle

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

func HxAfterRequest

func HxAfterRequest(cmd ...Command) *LifeCycle

HxAfterRequest executes the given commands after the request is sent.

func HxAfterSseMessage

func HxAfterSseMessage(cmd ...Command) *LifeCycle

HxAfterSseMessage executes the given commands when a message is received from the server via SSE, and after it is processed.

func HxBeforeRequest

func HxBeforeRequest(cmd ...Command) *LifeCycle

HxBeforeRequest executes the given commands before the request is sent.

func HxBeforeSseMessage

func HxBeforeSseMessage(cmd ...Command) *LifeCycle

HxBeforeSseMessage executes the given commands when a message is received from the server via SSE, but before it is processed.

func HxOnAfterSwap

func HxOnAfterSwap(cmd ...Command) *LifeCycle

HxOnAfterSwap executes the given commands when the element is swapped in.

func HxOnLoad

func HxOnLoad(cmd ...Command) *LifeCycle

HxOnLoad executes the given commands when the element is loaded into the DOM. Deprecated: Use OnLoad instead.

func HxOnMutationError

func HxOnMutationError(cmd ...Command) *LifeCycle

HxOnMutationError executes the given commands when a mutation error of a request occurs.

func HxOnSseClose

func HxOnSseClose(cmd ...Command) *LifeCycle

HxOnSseClose executes the given commands when the connection to the server via SSE is closed.

func HxOnSseConnecting

func HxOnSseConnecting(cmd ...Command) *LifeCycle

HxOnSseConnecting executes the given commands when the connection to the server via SSE is being established.

func HxOnSseError

func HxOnSseError(cmd ...Command) *LifeCycle

HxOnSseError executes the given commands when an error occurs while connecting to the server via SSE.

func HxOnSseOpen

func HxOnSseOpen(cmd ...Command) *LifeCycle

HxOnSseOpen executes the given commands when the connection to the server via SSE is established.

func NewLifeCycle

func NewLifeCycle() *LifeCycle

func OnClick

func OnClick(cmd ...Command) *LifeCycle

OnClick executes the given commands when the element is clicked.

func OnEvent

func OnEvent(event hx.Event, cmd ...Command) *LifeCycle

OnEvent executes the given commands when the given event is triggered.

func OnLoad

func OnLoad(cmd ...Command) *LifeCycle

OnLoad executes the given commands when the element is loaded into the DOM, it also executes when the element is replaced / swapped in. This will work on any element because of the htmgo htmx extension to trigger it, instead of the browser.

func OnSubmit

func OnSubmit(cmd ...Command) *LifeCycle

OnSubmit executes the given commands when the form is submitted.

func (*LifeCycle) HxAfterRequest

func (l *LifeCycle) HxAfterRequest(cmd ...Command) *LifeCycle

func (*LifeCycle) HxBeforeRequest

func (l *LifeCycle) HxBeforeRequest(cmd ...Command) *LifeCycle

func (*LifeCycle) HxOnMutationError

func (l *LifeCycle) HxOnMutationError(cmd ...Command) *LifeCycle

func (*LifeCycle) OnEvent

func (l *LifeCycle) OnEvent(event hx.Event, cmd ...Command) *LifeCycle

func (*LifeCycle) Render

func (l *LifeCycle) Render(context *RenderContext)

type Page

type Page struct {
	Root       Ren
	HttpMethod string
}

func EmptyPage

func EmptyPage() *Page

func NewPage

func NewPage(root Ren) *Page

func NewPageWithHttpMethod

func NewPageWithHttpMethod(httpMethod string, root *Element) *Page

type Partial

type Partial struct {
	Headers *Headers
	Root    *Element
}

func EmptyPartial

func EmptyPartial() *Partial

func NewPartial

func NewPartial(root *Element) *Partial

func NewPartialWithHeaders

func NewPartialWithHeaders(headers *Headers, root *Element) *Partial

func RedirectPartial

func RedirectPartial(path string) *Partial

func RedirectPartialWithHeaders

func RedirectPartialWithHeaders(path string, headers *Headers) *Partial

func SwapManyPartial

func SwapManyPartial(ctx *RequestContext, swaps ...*Element) *Partial

func SwapManyPartialWithHeaders

func SwapManyPartialWithHeaders(ctx *RequestContext, headers *Headers, swaps ...*Element) *Partial

func SwapManyXPartial

func SwapManyXPartial(ctx *RequestContext, swaps ...SwapArg) *Partial

func SwapPartial

func SwapPartial(ctx *RequestContext, swap *Element) *Partial

func (*Partial) Render

func (p *Partial) Render(context *RenderContext)

type PartialFunc

type PartialFunc = func(ctx *RequestContext) *Partial

type Qs

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

func NewQs

func NewQs(pairs ...string) *Qs

func (*Qs) Add

func (q *Qs) Add(key string, value string) *Qs

func (*Qs) Remove

func (q *Qs) Remove(key string) *Qs

func (*Qs) ToString

func (q *Qs) ToString() string

type RawContent

type RawContent struct {
	Content string
}

func NewRawContent

func NewRawContent(content string) *RawContent

func UnsafeRaw

func UnsafeRaw(text string) *RawContent

UnsafeRaw is a helper function to create a raw content with the given text The text is not escaped, do not use this function with user input

func UnsafeRawF

func UnsafeRawF(text string, args any) *RawContent

UnsafeRawF is a helper function to create a raw content with the given text The text is not escaped, do not use this function with user input

func UnsafeRawScript

func UnsafeRawScript(text string) *RawContent

UnsafeRawScript is a helper function to create a script tag with the given text The text is not escaped, do not use this function with user input

func (*RawContent) Render

func (r *RawContent) Render(context *RenderContext)

type Ren

type Ren interface {
	Render(context *RenderContext)
}

func Alt

func Alt(value string) Ren

func AttributeIf

func AttributeIf(condition bool, name string, value string) Ren

AttributeIf returns the attribute if the condition is true, otherwise returns an empty element

func Boost

func Boost() Ren

func Checked

func Checked() Ren

func ClassIf

func ClassIf(condition bool, value string) Ren

ClassIf returns the class attribute if the condition is true, otherwise returns an empty element

func ClassX

func ClassX(value string, m ClassMap) Ren

ClassX conditionally renders a class based on a map of class names and boolean values value is any non-conditional class name you'd like to add m is a map of class names and boolean values

func Controls added in v1.0.5

func Controls() Ren

func D

func D(value string) Ren

func For

func For(value string) Ren

func Hidden

func Hidden() Ren

func Href

func Href(path string) Ren

func HxConfirm

func HxConfirm(message string) Ren

func HxExtensions

func HxExtensions(value ...string) Ren

HxExtensions Adds multiple hx-ext to an element, separated by commas

func HxInclude

func HxInclude(selector string) Ren

HxInclude https://htmx.org/attributes/hx-include/

func HxTarget

func HxTarget(target string) Ren

func Id

func Id(value string) Ren

func If

func If(condition bool, node Ren) Ren

If returns the node if the condition is true, otherwise returns an empty element

func IfHtmxRequest

func IfHtmxRequest(ctx *RequestContext, node Ren) Ren

IfHtmxRequest returns the node if the request is an htmx request, otherwise returns an empty element

func IfQueryParam

func IfQueryParam(key string, node *Element) Ren

func JoinExtensions

func JoinExtensions(attrs ...*AttributeR) Ren

func Name

func Name(name string) Ren

func Placeholder

func Placeholder(placeholder string) Ren

func Target

func Target(target string) Ren

func Type

func Type(name string) Ren

type RenderContext

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

func (*RenderContext) AddScript

func (ctx *RenderContext) AddScript(funcName string, body string)

type RenderOpt added in v1.0.1

type RenderOpt func(context *RenderContext, opt *RenderOptions)

func WithDocType added in v1.0.1

func WithDocType() RenderOpt

type RenderOptions added in v1.0.1

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

type RequestContext

type RequestContext struct {
	Request  *http.Request
	Response http.ResponseWriter
	// contains filtered or unexported fields
}

func GetRequestContext

func GetRequestContext(r *http.Request) *RequestContext

func (*RequestContext) FormValue

func (c *RequestContext) FormValue(key string) string

func (*RequestContext) Get

func (c *RequestContext) Get(key string) interface{}

func (*RequestContext) Header

func (c *RequestContext) Header(key string) string

func (*RequestContext) HxCurrentBrowserUrl

func (c *RequestContext) HxCurrentBrowserUrl() string

func (*RequestContext) HxPromptResponse

func (c *RequestContext) HxPromptResponse() string

func (*RequestContext) HxTargetId

func (c *RequestContext) HxTargetId() string

func (*RequestContext) HxTriggerId

func (c *RequestContext) HxTriggerId() string

func (*RequestContext) HxTriggerName

func (c *RequestContext) HxTriggerName() string

func (*RequestContext) IsBoosted

func (c *RequestContext) IsBoosted() bool

func (*RequestContext) IsHttpDelete

func (c *RequestContext) IsHttpDelete() bool

func (*RequestContext) IsHttpGet

func (c *RequestContext) IsHttpGet() bool

func (*RequestContext) IsHttpPost

func (c *RequestContext) IsHttpPost() bool

func (*RequestContext) IsHttpPut

func (c *RequestContext) IsHttpPut() bool

func (*RequestContext) IsHxRequest

func (c *RequestContext) IsHxRequest() bool

func (*RequestContext) QueryParam

func (c *RequestContext) QueryParam(key string) string

func (*RequestContext) Redirect

func (c *RequestContext) Redirect(path string, code int)

func (*RequestContext) ServiceLocator

func (c *RequestContext) ServiceLocator() *service.Locator

ServiceLocator returns the service locator to register and retrieve services Usage: service.Set[db.Queries](locator, service.Singleton, db.Provide) service.Get[db.Queries](locator)

func (*RequestContext) Set

func (c *RequestContext) Set(key string, value interface{})

func (*RequestContext) SetCookie

func (c *RequestContext) SetCookie(cookie *http.Cookie)

func (*RequestContext) UrlParam

func (c *RequestContext) UrlParam(key string) string

type ScriptEntry added in v1.0.5

type ScriptEntry struct {
	Body    string
	ChildOf *Element
}

type SimpleJsCommand

type SimpleJsCommand struct {
	Command string
}

func AddAttribute

func AddAttribute(name, value string) SimpleJsCommand

AddAttribute adds the given attribute to the element.

func AddClass

func AddClass(class string) SimpleJsCommand

AddClass adds the given class to the element.

func Alert

func Alert(text string) SimpleJsCommand

Alert displays an alert dialog with the given text.

func ConsoleLog

func ConsoleLog(text string) SimpleJsCommand

ConsoleLog logs a message to the console.

func Increment

func Increment(amount int) SimpleJsCommand

Increment increments the inner text of the element by the given amount.

func PreventDefault

func PreventDefault() SimpleJsCommand

PreventDefault prevents the default action of the event.

func Remove

func Remove() SimpleJsCommand

Remove removes the element from the DOM.

func RemoveAttribute

func RemoveAttribute(name string) SimpleJsCommand

RemoveAttribute removes the given attribute from the element.

func RemoveClass

func RemoveClass(class string) SimpleJsCommand

RemoveClass removes the given class from the element.

func SetDisabled

func SetDisabled(disabled bool) SimpleJsCommand

SetDisabled sets the disabled attribute on the element.

func SetInnerHtml

func SetInnerHtml(r Ren) SimpleJsCommand

SetInnerHtml sets the inner HTML of the element.

func SetOuterHtml

func SetOuterHtml(r Ren) SimpleJsCommand

SetOuterHtml sets the outer HTML of the element.

func SetText

func SetText(text string) SimpleJsCommand

SetText sets the inner text of the element.

func SetValue

func SetValue(value string) SimpleJsCommand

SetValue sets the value of the element.

func ToggleClass

func ToggleClass(class string) SimpleJsCommand

ToggleClass toggles the given class on the element.

func (SimpleJsCommand) Render

func (j SimpleJsCommand) Render(context *RenderContext)

type SwapArg

type SwapArg struct {
	Content *Element
	Option  SwapOption
}

func NewSwap

func NewSwap(content *Element, opts ...SwapOption) SwapArg

type SwapOption

type SwapOption struct {
	Selector string
	SwapType hx.SwapType
	Modifier string
}

type TextContent

type TextContent struct {
	Content string
}

func NewTextContent

func NewTextContent(content string) *TextContent

func Text

func Text(text string) *TextContent

func TextF

func TextF(format string, args ...interface{}) *TextContent

func (*TextContent) Render

func (t *TextContent) Render(context *RenderContext)

Jump to

Keyboard shortcuts

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