htmx

package module
v1.1.36 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: MIT Imports: 11 Imported by: 0

README

🔨 Htmx

Go Reference Go Report Card Taylor Swift

A Go package to write HTML5 and HTMX components in Go. The package is designed to work with fiber and htmx.

Installation

$ go get github.com/zeiss/fiber-htmx

Components

The package supports to write HTML5 components and HTMX components in Go.

htmx.Button(
    htmx.Attribute("type", "submit")
    htmx.Text("Button"),
    htmx.HxPost("/api/respond")
)

There is also the option to use htmx.Controller to encapsulate the logic of the components.

type HelloWorldController struct {
    htmx.UnimplementedController
}

func (c *HelloWorldController) Get() error {
    return c.Hx.RenderComp(
        htmx.HTML5(
            c.Hx,
            htmx.HTML5Props{
                Title:    "index",
                Language: "en",
                Head: []htmx.Node{},
            },
            htmx.Div(
                htmx.ClassNames{},
                htmx.Text("Hello World"),
            ),
        ),
    )    
}

app := fiber.New()
app.Get("/", htmx.ControllerHandler(&HelloWorldController{}))

app.Listen(":3000")

Examples

See examples to understand the provided interfaces.

Benchmarks

BenchmarkElement-2               7863930               132.8 ns/op
BenchmarkAttribute-2             8052403               157.9 ns/op
Benchmark_HTML5_Render-2             788           1596065 ns/op

Rendering 10.000 nodes took >1.6ms. The package is fast enough to render HTML5 and HTMX components.

License

MIT

Documentation

Index

Examples

Constants

View Source
const (
	ElementType = NodeType(iota)
	AttributeType
)
View Source
const (
	// StatusStopPolling is a helper status code to stop polling.
	StatusStopPolling = 286
)

Variables

View Source
var (
	HxDefaultSwapDuration = 0 * time.Millisecond
	HxDefaultSettleDelay  = 20 * time.Millisecond
)
View Source
var ConfigDefault = Config{
	ErrorHandler: defaultErrorHandler,
	Resolvers:    []ResolveFunc{},
}

ConfigDefault is the default config.

Functions

func AsBool

func AsBool(str string) bool

AsBool is a helper function that returns a boolean value based on the provided string.

func AsStr added in v1.0.1

func AsStr(v bool) string

AsStr is a helper function that returns a string value based on the provided boolean.

func ContextWithHx

func ContextWithHx(c *fiber.Ctx) *fiber.Ctx

ContextWithHx ...

func IntAsString added in v1.0.16

func IntAsString(v int) string

IntAsString is a helper function that returns a string value based on the provided integer.

func New

func New(config ...Config) fiber.Handler

New ...

func NewCompFuncHandler added in v1.0.4

func NewCompFuncHandler(handler CompFunc, config ...Config) fiber.Handler

NewCompFuncHandler returns a new comp handler.

func NewCompHandler added in v1.0.1

func NewCompHandler(n Node, config ...Config) fiber.Handler

NewCompHandler returns a new comp handler.

func NewHtmxHandler

func NewHtmxHandler(handler HtmxHandlerFunc, config ...Config) fiber.Handler

NewHtmxHandler returns a new htmx handler.

func NewHxControllerHandler added in v1.0.42

func NewHxControllerHandler(ctrl Controller, config ...Config) fiber.Handler

NewHxControllerHandler returns a new htmx controller handler. nolint:gocyclo

Types

type ClassNames added in v1.0.1

type ClassNames map[string]bool

ClassNames represents a set of class names.

func Merge added in v1.0.28

func Merge(classNames ...ClassNames) ClassNames

Merge returns a new ClassNames object that is the result of merging the provided ClassNames objects.

func (ClassNames) Merge added in v1.0.4

func (c ClassNames) Merge(classNames ClassNames) ClassNames

Merge merges the provided class names into the class names.

func (ClassNames) Render added in v1.0.1

func (c ClassNames) Render(w io.Writer) error

Render writes the class names to the provided writer.

func (ClassNames) String added in v1.0.1

func (c ClassNames) String() string

String returns the string representation of the ClassNames.

func (ClassNames) Type added in v1.0.1

func (c ClassNames) Type() NodeType

Type returns the node type of the ClassNames.

type CompFunc added in v1.0.4

type CompFunc func(c *fiber.Ctx) (Node, error)

CompFunc is a helper type for component functions.

type Config

type Config struct {
	// Next defines a function to skip this middleware when returned true.
	Next func(c *fiber.Ctx) bool

	// Resolvers is a list of resolvers that resolve locals for the context.
	Resolvers []ResolveFunc

	// ErrorHandler is executed when an error is returned from fiber.Handler.
	//
	// Optional. Default: DefaultErrorHandler
	ErrorHandler fiber.ErrorHandler
}

Config ...

type Controller added in v1.0.42

type Controller interface {
	// Init is called when the controller is initialized.
	Init(hx *Htmx) error
	// Prepare is called before the controller is executed.
	Prepare() error
	// Finalize is called after the controller is executed.
	Finalize() error
	// Get is called when the controller is executed with the GET method.
	Get() error
	// Post is called when the controller is executed with the POST method.
	Post() error
	// Put is called when the controller is executed with the PUT method.
	Put() error
	// Patch is called when the controller is executed with the PATCH method.
	Patch() error
	// Delete is called when the controller is executed with the DELETE method.
	Delete() error
	// Options is called when the controller is executed with the OPTIONS method.
	Options() error
}

Controller is the interface for the htmx controller.

type Ctx added in v1.0.26

type Ctx interface {
	// Values is a helper function to get the values from the context.
	Values(key any, value ...any) (val any)
	// ValuesString is a helper function to get the values as a string from the context.
	ValuesString(key any, value ...any) (val string)
	// ValuesInt is a helper function to get the values as an int from the context.
	ValuesInt(key any, value ...any) (val int)
	// ValuesBool is a helper function to get the values as a bool from the context.
	ValuesBool(key any, value ...any) (val bool)
	// Path is a helper function to get the path from the context.
	Path() string
}

Ctx is the component context.

type HTML5Props added in v1.0.1

type HTML5Props struct {
	Title       string // The title of the HTML document.
	Description string // The description of the HTML document.
	Language    string // The language of the HTML document.
	Head        []Node // The nodes to be included in the head section of the HTML document.
	Attributes  []Node // The attributes to be included in the HTML document.
}

HTML5Props represents the properties for an HTML5 document.

type HXSwapStyle added in v1.0.2

type HXSwapStyle string

HxSwapStyle ...

const (
	HxSwapInnerHTML   HXSwapStyle = "innerHTML"
	HxSwapOuterHTML   HXSwapStyle = "outerHTML"
	HxSwapBeforeBegin HXSwapStyle = "beforebegin"
	HxSwapAfterBegin  HXSwapStyle = "afterbegin"
	HxSwapBeforeEnd   HXSwapStyle = "beforeend"
	HxSwapAfterEnd    HXSwapStyle = "afterend"
	HxSwapDelete      HXSwapStyle = "delete"
	HxSwapNone        HXSwapStyle = "none"
)

func (HXSwapStyle) String added in v1.0.2

func (s HXSwapStyle) String() string

String ...

type Htmx

type Htmx struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Htmx is a helper struct for htmx requests.

func HtmxFromContext added in v1.0.42

func HtmxFromContext(c *fiber.Ctx) *Htmx

HtmxFromContext is a helper function to get the htmx from the context.

func (*Htmx) Context added in v1.0.42

func (h *Htmx) Context() *fiber.Ctx

Context is a method that returns the fiber context.

func (*Htmx) Ctx

func (h *Htmx) Ctx() *fiber.Ctx

Ctx returns the fiber context.

func (*Htmx) IsHxBoosted

func (h *Htmx) IsHxBoosted() bool

IsHxBoosted returns true if the request is an htmx request.

func (*Htmx) IsHxHistoryRestoreRequest

func (h *Htmx) IsHxHistoryRestoreRequest() bool

IsHxHistoryRestoreRequest returns true if the request is an htmx request.

func (*Htmx) IsHxRequest

func (h *Htmx) IsHxRequest() bool

IsHxRequest returns true if the request is an htmx request.

func (*Htmx) Locals added in v1.0.42

func (h *Htmx) Locals(key any, value ...any) (val any)

Locals is a method that returns the local values.

func (*Htmx) Path added in v1.0.43

func (h *Htmx) Path() string

Path is a method that returns the path.

func (*Htmx) ReSelect

func (h *Htmx) ReSelect(target string)

ReSelect ...

func (*Htmx) ReSwap

func (h *Htmx) ReSwap(target string)

ReSwap ...

func (*Htmx) ReTarget

func (h *Htmx) ReTarget(target string)

ReTarget ...

func (*Htmx) Redirect

func (h *Htmx) Redirect(url string)

Redirect is a helper function to redirect the client.

func (*Htmx) RenderComp added in v1.0.1

func (h *Htmx) RenderComp(n Node) error

RenderComp is a helper function to render a component.

func (*Htmx) RenderPartial

func (h *Htmx) RenderPartial() bool

RenderPartial returns true if the request is an htmx request.

func (*Htmx) ReplaceURL

func (h *Htmx) ReplaceURL(url string)

ReplaceURL is a helper function to replace the current URL.

func (*Htmx) Reset added in v1.0.42

func (h *Htmx) Reset()

Reset is a method that resets the local values.

func (*Htmx) Resolve added in v1.0.42

func (h *Htmx) Resolve(ctx *fiber.Ctx, funcs ...ResolveFunc) error

Resolve is a method that resolves locals for the context.

func (*Htmx) StopPolling

func (h *Htmx) StopPolling() error

StopPolling ...

func (*Htmx) Trigger

func (h *Htmx) Trigger(target string)

Trigger ...

func (*Htmx) Values added in v1.0.42

func (h *Htmx) Values(key any, value ...any) (val any)

Values is a method that returns the local values.

func (*Htmx) ValuesBool added in v1.0.42

func (h *Htmx) ValuesBool(key any, value ...any) (val bool)

ValuesBool is a method that returns the local values.

func (*Htmx) ValuesInt added in v1.0.42

func (h *Htmx) ValuesInt(key any, value ...any) (val int)

ValuesInt is a method that returns the local values.

func (*Htmx) ValuesString added in v1.0.42

func (h *Htmx) ValuesString(key any, value ...any) (val string)

ValuesString is a method that returns the local values.

func (*Htmx) Write

func (h *Htmx) Write(data []byte) (n int, err error)

Write writes a response.

func (*Htmx) WriteHTML

func (h *Htmx) WriteHTML(html template.HTML) (n int, err error)

WriteHTML writes an HTML response.

func (*Htmx) WriteJSON

func (h *Htmx) WriteJSON(data any) (n int, err error)

WriteJSON writes a JSON response.

func (*Htmx) WriteString

func (h *Htmx) WriteString(s string) (n int, err error)

WriteString is a helper function to write a string.

type HtmxHandlerFunc

type HtmxHandlerFunc = func(hx *Htmx) error

HtmxHandler ...

type Hx

type Hx struct {
	HxBoosted               bool
	HxCurrentURL            string
	HxHistoryRestoreRequest bool
	HxPrompt                string
	HxRequest               bool
	HxTarget                string
	HxTriggerName           string
	HxTrigger               string
}

Hx ...

func HxFromContext

func HxFromContext(c *fiber.Ctx) *Hx

HxFromContext ...

type HxClassName added in v1.0.1

type HxClassName string

HxClassName represents a class name for htmx elements.

const (
	HxClassNameAdded     HxClassName = "htmx-added"
	HxClassNameIndicator HxClassName = "htmx-indicator"
	HxClassNameRequest   HxClassName = "htmx-request"
	HxClassNameSettling  HxClassName = "htmx-settling"
	HxClassNameSwapping  HxClassName = "htmx-swapping"
)

func (HxClassName) String added in v1.0.1

func (c HxClassName) String() string

String returns the string representation of the HxClassName.

type HxEventType added in v1.0.1

type HxEventType string

HxEventType represents the type of htmx event.

const (
	HxEventTypeAbort            HxEventType = "htmx:abort"
	HxEventTypeAfterLoad        HxEventType = "htmx:afterLoad"
	HxEventTypeAfterProcessNode HxEventType = "htmx:afterProcessNode"
	HxEventTypeAfterRequest     HxEventType = "htmx:afterRequest"
)

List of predefined htmx event types.

func (HxEventType) String added in v1.0.1

func (e HxEventType) String() string

String returns the string representation of the HxEventType.

type HxExtType added in v1.0.33

type HxExtType string

HxExtType is a type for htmx extension types.

const (
	HxExtAlpineMorph         HxExtType = "alpine-morph"
	HxExtClassTools          HxExtType = "class-tools"
	HxExtClientSideTemplates HxExtType = "client-side-templates"
	HxExtIgnoreDebug         HxExtType = "ignore:debug"
	HxExtJSON                HxExtType = "json-enc"
	HxExtMultiSwap           HxExtType = "multi-swap"
	HxExtPathDeps            HxExtType = "path-deps"
)

func (HxExtType) String added in v1.0.33

func (v HxExtType) String() string

String returns the string representation of the htmx extension type.

type HxRequestHeader

type HxRequestHeader string

HxRequestHeader is a helper type for htmx request headers.

const (
	HxRequestHeaderBoosted               HxRequestHeader = "HX-Boosted"
	HxRequestHeaderCurrentURL            HxRequestHeader = "HX-Current-URL"
	HxRequestHeaderHistoryRestoreRequest HxRequestHeader = "HX-History-Restore-Request"
	HxRequestHeaderPrompt                HxRequestHeader = "HX-Prompt"
	HxRequestHeaderRequest               HxRequestHeader = "HX-Request"
	HxRequestHeaderTarget                HxRequestHeader = "HX-Target"
	HxRequestHeaderTrigger               HxRequestHeader = "HX-Trigger"
	HxRequestHeaderTriggerName           HxRequestHeader = "HX-Trigger-Name"
)

func (HxRequestHeader) String

func (h HxRequestHeader) String() string

String returns the header as a string.

type HxResponseHeader

type HxResponseHeader string

HxResponseHeader ...

const (
	HXLocation           HxResponseHeader = "HX-Location"             // Allows you to do a client-side redirect that does not do a full page reload
	HXPushUrl            HxResponseHeader = "HX-Push-Url"             // pushes a new url into the history stack
	HXRedirect           HxResponseHeader = "HX-Redirect"             // can be used to do a client-side redirect to a new location
	HXRefresh            HxResponseHeader = "HX-Refresh"              // if set to "true" the client side will do a full refresh of the page
	HXReplaceUrl         HxResponseHeader = "HX-Replace-Url"          // replaces the current URL in the location bar
	HXReswap             HxResponseHeader = "HX-Reswap"               // Allows you to specify how the response will be swapped. See hx-swap for possible values
	HXRetarget           HxResponseHeader = "HX-Retarget"             // A CSS selector that updates the target of the content update to a different element on the page
	HXReselect           HxResponseHeader = "HX-Reselect"             // A CSS selector that allows you to choose which part of the response is used to be swapped in. Overrides an existing hx-select on the triggering element
	HXTrigger            HxResponseHeader = "HX-Trigger"              // allows you to trigger client side events, see the documentation for more info
	HXTriggerAfterSettle HxResponseHeader = "HX-Trigger-After-Settle" // allows you to trigger client side events, see the documentation for more info
	HXTriggerAfterSwap   HxResponseHeader = "HX-Trigger-After-Swap"   // allows you to trigger client side events, see the documentation for more info
)

func (HxResponseHeader) String

func (h HxResponseHeader) String() string

String returns the header as a string.

type HxResponseHeaders

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

HxResponseHeaders ...

func (*HxResponseHeaders) Get

Get is a helper function to get a header.

func (*HxResponseHeaders) Set

func (h *HxResponseHeaders) Set(k HxResponseHeader, val string)

Set is a helper function to set a header.

type HxSwapDirection added in v1.0.2

type HxSwapDirection string

HxSwapDirection ...

const (
	HxSwapDirectionTop    HxSwapDirection = "top"
	HxSwapDirectionBottom HxSwapDirection = "bottom"
)

func (HxSwapDirection) String added in v1.0.2

func (s HxSwapDirection) String() string

String ...

type HxSwapScrolling added in v1.0.2

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

HxSwapScrolling ...

func (*HxSwapScrolling) String added in v1.0.2

func (s *HxSwapScrolling) String() string

String ...

type HxSwapScrollingMode added in v1.0.2

type HxSwapScrollingMode string

HxSwapScrollingMode ...

const (
	HxSwapScrollingScroll HxSwapScrollingMode = "scroll"
	HxSwapScrollingShow   HxSwapScrollingMode = "show"
)

func (HxSwapScrollingMode) String added in v1.0.2

func (s HxSwapScrollingMode) String() string

String ...

type HxSwapTiming added in v1.0.2

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

HxSwapTiming ...

func (*HxSwapTiming) String added in v1.0.2

func (s *HxSwapTiming) String() string

String ...

type HxSwapTimingMode added in v1.0.2

type HxSwapTimingMode string

HxSwapTimingMode ...

const (
	HxTimingSwap   HxSwapTimingMode = "swap"
	HxTimingSettle HxSwapTimingMode = "settle"
)

func (HxSwapTimingMode) String added in v1.0.2

func (s HxSwapTimingMode) String() string

String ...

type Node added in v1.0.1

type Node interface {
	Render(w io.Writer) error
}

Node is a node in the HTML tree.

func A added in v1.0.1

func A(children ...Node) Node

A represents an HTML anchor element.

func Abbr added in v1.0.1

func Abbr(children ...Node) Node

Abbr represents an HTML abbr element.

func Accept added in v1.0.1

func Accept(v string) Node

Accept sets the accept attribute for file input elements.

func Action added in v1.0.1

func Action(v string) Node

Action sets the action attribute for form elements.

func Address added in v1.0.1

func Address(children ...Node) Node

Address represents an HTML address element.

func Alt added in v1.0.1

func Alt(v string) Node

Alt sets the alt attribute for image elements.

func Area added in v1.0.1

func Area(children ...Node) Node

Area represents an HTML area element.

func Aria added in v1.0.1

func Aria(name, v string) Node

Aria sets the aria-{name} attribute for elements.

func Article added in v1.0.1

func Article(children ...Node) Node

Article represents an HTML article element.

func As added in v1.0.1

func As(v string) Node

As sets the as attribute for link elements.

func Aside added in v1.0.1

func Aside(children ...Node) Node

Aside represents an HTML aside element.

func Async added in v1.0.1

func Async() Node

Async sets the async attribute for script elements.

func Attribute added in v1.0.1

func Attribute(name string, value ...string) Node

Attribute is a node that renders an HTML attribute.

Example (Bool)
package main

import (
	"os"

	htmx "github.com/zeiss/fiber-htmx"
)

func main() {
	_ = htmx.Attribute("disabled", htmx.AsStr(true)).Render(os.Stdout)
}
Output:

disabled="true"
Example (Name_value)
package main

import (
	"os"

	htmx "github.com/zeiss/fiber-htmx"
)

func main() {
	_ = htmx.Attribute("href", "/").Render(os.Stdout)
}
Output:

href="/"

func Audio added in v1.0.1

func Audio(children ...Node) Node

Audio represents an HTML audio element.

func AutoComplete added in v1.0.1

func AutoComplete(v string) Node

AutoComplete sets the autocomplete attribute for form elements.

func AutoFocus added in v1.0.1

func AutoFocus() Node

AutoFocus sets the autofocus attribute for form elements.

func AutoPlay added in v1.0.1

func AutoPlay() Node

AutoPlay sets the autoplay attribute for media elements.

func B added in v1.0.1

func B(children ...Node) Node

B represents an HTML b element.

func Base added in v1.0.1

func Base(children ...Node) Node

Base represents an HTML base element.

func BlockQuote added in v1.0.1

func BlockQuote(children ...Node) Node

BlockQuote represents an HTML blockquote element.

func Body added in v1.0.1

func Body(children ...Node) Node

Body represents an HTML body element.

func Br added in v1.0.1

func Br(children ...Node) Node

Br represents an HTML line break element.

func Button added in v1.0.1

func Button(children ...Node) Node

Button represents an HTML button element.

func Canvas added in v1.0.1

func Canvas(children ...Node) Node

Canvas represents an HTML canvas element.

func Caption added in v1.0.1

func Caption(children ...Node) Node

Caption represents an HTML caption element.

func Charset added in v1.0.1

func Charset(v string) Node

Charset sets the charset attribute for meta elements.

func Checked added in v1.0.1

func Checked() Node

Checked sets the checked attribute for input elements.

func Cite added in v1.0.1

func Cite(children ...Node) Node

Cite represents an HTML cite element.

func Class added in v1.0.1

func Class(v string) Node

Class sets the class attribute for elements.

func ClipRule added in v1.0.2

func ClipRule(v string) Node

ClipRule returns an SVG attribute node for specifying the clip rule. The clip rule determines how the clipping path is applied to the SVG element. The value of the clip rule is specified as a string. Example usage: ClipRule("evenodd")

func Code added in v1.0.1

func Code(children ...Node) Node

Code represents an HTML code element.

func Col added in v1.0.1

func Col(children ...Node) Node

Col represents an HTML col element.

func ColGroup added in v1.0.1

func ColGroup(children ...Node) Node

ColGroup represents an HTML colgroup element.

func ColSpan added in v1.0.1

func ColSpan(v string) Node

ColSpan sets the colspan attribute for table cells.

func Cols added in v1.0.1

func Cols(v string) Node

Cols sets the cols attribute for textarea elements.

func Content added in v1.0.1

func Content(v string) Node

Content sets the content attribute for meta elements.

func Controls added in v1.0.1

func Controls() Node

Controls sets the controls attribute for media elements.

func D added in v1.0.2

func D(v string) Node

D returns an SVG attribute node for specifying the path data. The path data defines the shape of the SVG path element. The value of the path data is specified as a string. Example usage: D("M10 10 L20 20")

func DElement added in v1.0.1

func DElement(children ...Node) Node

DElement represents an HTML del element.

func DataAttribute added in v1.0.1

func DataAttribute(name, v string) Node

DataAttribute sets the data-{name} attribute for elements.

func DataElement added in v1.0.1

func DataElement(children ...Node) Node

DataElement represents an HTML data element.

func DataList added in v1.0.1

func DataList(children ...Node) Node

DataList represents an HTML datalist element.

func Dd added in v1.0.1

func Dd(children ...Node) Node

Dd represents an HTML dd element.

func Defer added in v1.0.1

func Defer() Node

Defer sets the defer attribute for script elements.

func Details added in v1.0.1

func Details(children ...Node) Node

Details represents an HTML details element.

func Dfn added in v1.0.1

func Dfn(children ...Node) Node

Dfn represents an HTML dfn element.

func Dialog added in v1.0.1

func Dialog(children ...Node) Node

Dialog represents an HTML dialog element.

func Disabled added in v1.0.1

func Disabled() Node

Disabled sets the disabled attribute for form elements.

func Div added in v1.0.1

func Div(children ...Node) Node

Div represents an HTML div element.

func Dl added in v1.0.1

func Dl(children ...Node) Node

Dl represents an HTML dl element.

func Doctype added in v1.0.1

func Doctype(sibling Node) Node

Doctype represents the HTML doctype declaration.

func Dt added in v1.0.1

func Dt(children ...Node) Node

Dt represents an HTML dt element.

func Em added in v1.0.1

func Em(children ...Node) Node

Em represents an HTML em element.

func Embed added in v1.0.1

func Embed(children ...Node) Node

Embed represents an HTML embed element.

func EncType added in v1.0.1

func EncType(v string) Node

EncType sets the enctype attribute for form elements.

func FieldSet added in v1.0.1

func FieldSet(children ...Node) Node

FieldSet represents an HTML fieldset element.

func FigCaption added in v1.0.1

func FigCaption(children ...Node) Node

FigCaption represents an HTML figcaption element.

func Figure added in v1.0.1

func Figure(children ...Node) Node

Figure represents an HTML figure element.

func Fill added in v1.0.2

func Fill(v string) Node

Fill returns an SVG attribute node for specifying the fill color. The fill color determines the color used to fill the SVG element. The value of the fill color is specified as a string. Example usage: Fill("red")

func FillRule added in v1.0.2

func FillRule(v string) Node

FillRule returns an SVG attribute node for specifying the fill rule. The fill rule determines how the interior of the SVG element is filled. The value of the fill rule is specified as a string. Example usage: FillRule("evenodd")

func Filter added in v1.0.38

func Filter(f func(i int) bool, children ...Node) []Node

Filter loops and filters the content.

func Footer(children ...Node) Node

Footer represents an HTML footer element.

func For added in v1.0.1

func For(v string) Node

For sets the for attribute for label elements.

func Form added in v1.0.32

func Form(children ...Node) Node

Form represents an HTML form element.

func FormAttribute added in v1.0.1

func FormAttribute(v string) Node

FormAttribute sets the form attribute for elements.

func FormElement added in v1.0.1

func FormElement(children ...Node) Node

FormElement represents an HTML form element.

func Group added in v1.0.1

func Group(children ...Node) Node

Group is a node that groups children nodes.

func H1 added in v1.0.1

func H1(children ...Node) Node

H1 represents an HTML h1 element.

func H2 added in v1.0.1

func H2(children ...Node) Node

H2 represents an HTML h2 element.

func H3 added in v1.0.1

func H3(children ...Node) Node

H3 represents an HTML h3 element.

func H4 added in v1.0.1

func H4(children ...Node) Node

H4 represents an HTML h4 element.

func H5 added in v1.0.1

func H5(children ...Node) Node

H5 represents an HTML h5 element.

func H6 added in v1.0.1

func H6(children ...Node) Node

H6 represents an HTML h6 element.

func HGroup added in v1.0.1

func HGroup(children ...Node) Node

HGroup represents an HTML hgroup element.

func HTML added in v1.0.1

func HTML(children ...Node) Node

HTML represents an HTML html element.

func HTML5 added in v1.0.1

func HTML5(ctx Ctx, props HTML5Props, body ...Node) Node

HTML5 generates an HTML5 document based on the provided properties.

func HandlebarsTemplate added in v1.0.33

func HandlebarsTemplate(v string) Node

HandlebarsTemplate sets the handlebars-template attribute to specify the handlebars template for the response.

func Head(children ...Node) Node

Head represents an HTML head element.

func Header(children ...Node) Node

Header represents an HTML header element.

func Height added in v1.0.1

func Height(v string) Node

Height sets the height attribute for elements.

func Hr added in v1.0.1

func Hr(children ...Node) Node

Hr represents an HTML horizontal rule element.

func Href added in v1.0.1

func Href(v string) Node

Href sets the href attribute for anchor elements.

func HxBoost added in v1.0.1

func HxBoost(v bool) Node

HxBoost sets the hx-boost attribute to enable or disable boosting.

func HxConfirm added in v1.0.1

func HxConfirm(msg string) Node

HxConfirm sets the hx-confirm attribute to display a confirmation message.

func HxDelete added in v1.0.1

func HxDelete(url string) Node

HxDelete sets the hx-delete attribute to specify the URL for DELETE requests.

func HxDisable added in v1.0.1

func HxDisable() Node

HxDisable sets the hx-disable attribute to disable htmx functionality.

func HxDisabledElt added in v1.1.36

func HxDisabledElt(target string) Node

HxDisabledElt sets the hx-disable-elt attribute to disable the target element.

func HxEncoding added in v1.0.1

func HxEncoding(enc string) Node

HxEncoding sets the hx-encoding attribute to specify the encoding type for form submission.

func HxExt added in v1.0.1

func HxExt(ext string) Node

HxExt sets the hx-ext attribute to specify the file extension for file uploads.

func HxGet added in v1.0.1

func HxGet(url string) Node

HxGet sets the hx-get attribute to specify the URL for GET requests.

func HxInclude added in v1.0.32

func HxInclude(target string) Node

HxInclude sets the hx-include attribute to specify the target element for inclusion.

func HxIndicator added in v1.0.1

func HxIndicator(target string) Node

HxIndicator sets the hx-indicator attribute to specify the target element for showing an indicator.

func HxOn added in v1.0.1

func HxOn(target string, js string) Node

HxOn sets the hx-put-{target} attribute to specify the JavaScript code to execute on a PUT request.

func HxPath added in v1.0.1

func HxPath(url string) Node

HxPath sets the hx-patch attribute to specify the URL for PATCH requests.

func HxPost added in v1.0.1

func HxPost(url string) Node

HxPost sets the hx-post attribute to specify the URL for POST requests.

func HxPrompt added in v1.0.1

func HxPrompt(msg string) Node

HxPrompt sets the hx-prompt attribute to display a prompt message.

func HxPushUrl added in v1.0.1

func HxPushUrl(v bool) Node

HxPushUrl sets the hx-push-url attribute to enable or disable URL pushing.

func HxPut added in v1.0.1

func HxPut(url string) Node

HxPut sets the hx-put attribute to specify the URL for PUT requests.

func HxSelect added in v1.0.1

func HxSelect(target string) Node

HxSelect sets the hx-select attribute to specify the target element for selection.

func HxSelectOob added in v1.0.1

func HxSelectOob(target string) Node

HxSelectOob sets the hx-select-oob attribute to specify the target element for out-of-band selection.

func HxSwap added in v1.0.1

func HxSwap(target string) Node

HxSwap sets the hx-swap attribute to specify the target element for swapping.

func HxSwapOob added in v1.0.1

func HxSwapOob(target string) Node

HxSwapOob sets the hx-swap-oob attribute to specify the target element for out-of-band swapping.

func HxTarget added in v1.0.1

func HxTarget(target string) Node

HxTarget sets the hx-target attribute to specify the target element for the response.

func HxTrigger added in v1.0.1

func HxTrigger(target string) Node

HxTrigger sets the hx-trigger attribute to specify the target element for triggering an event.

func HxValidate added in v1.0.1

func HxValidate(v bool) Node

HxValidate sets the hx-validate attribute to enable or disable form validation.

func HyperScript added in v1.1.8

func HyperScript(v string) Node

HyperScript sets the _ attribute to specify the hyperscript for the response.

func I added in v1.0.1

func I(children ...Node) Node

I represents an HTML i element.

func ID added in v1.0.1

func ID(v string) Node

ID sets the id attribute for elements.

func IFrame added in v1.0.1

func IFrame(children ...Node) Node

IFrame represents an HTML iframe element.

func If added in v1.0.1

func If(condition bool, n Node) Node

If is a node that renders a child node if a condition is true.

func Img added in v1.0.1

func Img(children ...Node) Node

Img represents an HTML img element.

func Input added in v1.0.1

func Input(children ...Node) Node

Input represents an HTML input element.

func Ins added in v1.0.1

func Ins(children ...Node) Node

Ins represents an HTML ins element.

func Kbd added in v1.0.1

func Kbd(children ...Node) Node

Kbd represents an HTML kbd element.

func Label added in v1.0.3

func Label(children ...Node) Node

Label represents an HTML label element.

func Lang added in v1.0.1

func Lang(v string) Node

Lang sets the lang attribute for elements.

func Legend added in v1.0.1

func Legend(children ...Node) Node

Legend represents an HTML legend element.

func Li added in v1.0.1

func Li(children ...Node) Node

Li represents an HTML li element.

func Link(children ...Node) Node

Link represents an HTML link element.

func Loading added in v1.0.1

func Loading(v string) Node

Loading sets the loading attribute for elements.

func Loop added in v1.0.1

func Loop() Node

Loop sets the loop attribute for media elements.

func Main added in v1.0.1

func Main(children ...Node) Node

Main represents an HTML main element.

func Map added in v1.0.38

func Map(f func(i int) Node, children ...Node) []Node

Map loops and maps the content.

func Mark added in v1.0.1

func Mark(children ...Node) Node

Mark represents an HTML mark element.

func Max added in v1.0.1

func Max(v string) Node

Max sets the max attribute for input elements.

func MaxLength added in v1.0.1

func MaxLength(v string) Node

MaxLength sets the maxlength attribute for input elements.

func Meta added in v1.0.1

func Meta(children ...Node) Node

Meta represents an HTML meta element.

func Meter added in v1.0.1

func Meter(children ...Node) Node

Meter represents an HTML meter element.

func Method added in v1.0.1

func Method(v string) Node

Method sets the method attribute for form elements.

func Min added in v1.0.1

func Min(v string) Node

Min sets the min attribute for input elements.

func MinLength added in v1.0.1

func MinLength(v string) Node

MinLength sets the minlength attribute for input elements.

func Multiple added in v1.0.1

func Multiple() Node

Multiple sets the multiple attribute for input elements.

func MustacheTemplate added in v1.0.33

func MustacheTemplate(v string) Node

MustacheTemplate sets the mustache-template attribute to specify the mustache template for the response.

func Muted added in v1.0.1

func Muted() Node

Muted sets the muted attribute for media elements.

func Name added in v1.0.1

func Name(v string) Node

Name sets the name attribute for elements.

func Nav(children ...Node) Node

Nav represents an HTML nav element.

func NoScript added in v1.0.1

func NoScript(children ...Node) Node

NoScript represents an HTML noscript element.

func NunjucksTemplate added in v1.0.33

func NunjucksTemplate(v string) Node

NunjucksTemplate sets the nunjucks-template attribute to specify the nunjucks template for the response.

func Object added in v1.0.1

func Object(children ...Node) Node

Object represents an HTML object element.

func Ol added in v1.0.1

func Ol(children ...Node) Node

Ol represents an HTML ol element.

func OnClick added in v1.0.41

func OnClick(v string) Node

OnClick sets the onclick attribute for elements.

func OptGroup added in v1.0.1

func OptGroup(children ...Node) Node

OptGroup represents an HTML optgroup element.

func Option added in v1.0.1

func Option(children ...Node) Node

Option represents an HTML option element.

func P added in v1.0.1

func P(children ...Node) Node

P represents an HTML p element.

func Param added in v1.0.1

func Param(children ...Node) Node

Param represents an HTML param element.

func Path added in v1.0.2

func Path(children ...Node) Node

Path creates an SVG path element with the specified children. It is a convenience function that calls the Element function with "path" as the tag name.

func Pattern added in v1.0.1

func Pattern(v string) Node

Pattern sets the pattern attribute for input elements.

func Picture added in v1.0.1

func Picture(children ...Node) Node

Picture represents an HTML picture element.

func Placeholder added in v1.0.1

func Placeholder(v string) Node

Placeholder sets the placeholder attribute for input elements.

func PlaysInline added in v1.0.1

func PlaysInline() Node

PlaysInline sets the playsinline attribute for media elements.

func Poster added in v1.0.1

func Poster(v string) Node

Poster sets the poster attribute for video elements.

func Pre added in v1.0.1

func Pre(children ...Node) Node

Pre represents an HTML pre element.

func Preload added in v1.0.1

func Preload(v string) Node

Preload sets the preload attribute for media elements.

func Progress added in v1.0.1

func Progress(children ...Node) Node

Progress represents an HTML progress element.

func Q added in v1.0.1

func Q(children ...Node) Node

Q represents an HTML q element.

func Raw added in v1.0.1

func Raw(t string) Node

Raw is a node that renders raw HTML.

func Rawf added in v1.0.1

func Rawf(format string, a ...interface{}) Node

Rawf is a node that renders a formatted raw HTML.

func ReadOnly added in v1.0.1

func ReadOnly() Node

ReadOnly sets the readonly attribute for form elements.

func Reduce added in v1.0.38

func Reduce(f func(Node, Node) Node, children ...Node) Node

Reduce reduces the content to a single node.

func Rel added in v1.0.1

func Rel(v string) Node

Rel sets the rel attribute for link elements.

func Required added in v1.0.1

func Required() Node

Required sets the required attribute for form elements.

func Role added in v1.0.1

func Role(v string) Node

Role sets the role attribute for elements.

func RowSpan added in v1.0.1

func RowSpan(v string) Node

RowSpan sets the rowspan attribute for table cells.

func Rows added in v1.0.1

func Rows(v string) Node

Rows sets the rows attribute for textarea elements.

func S added in v1.0.1

func S(children ...Node) Node

S represents an HTML s element.

func SVG added in v1.0.1

func SVG(children ...Node) Node

SVG creates an SVG element with the specified children. It sets the "xmlns" attribute to "http://www.w3.org/2000/svg". The children are rendered inside a group element.

func Samp added in v1.0.1

func Samp(children ...Node) Node

Samp represents an HTML samp element.

func Script added in v1.0.1

func Script(children ...Node) Node

Script represents an HTML script element.

func Section added in v1.0.1

func Section(children ...Node) Node

Section represents an HTML section element.

func Select added in v1.0.1

func Select(children ...Node) Node

Select represents an HTML select element.

func Selected added in v1.0.1

func Selected() Node

Selected sets the selected attribute for option elements.

func Slot added in v1.0.33

func Slot(children ...Node) Node

Slot represents an HTML slot element.

func Small added in v1.0.1

func Small(children ...Node) Node

Small represents an HTML small element.

func Source added in v1.0.1

func Source(children ...Node) Node

Source represents an HTML source element.

func Span added in v1.0.1

func Span(children ...Node) Node

Span represents an HTML span element.

func Src added in v1.0.1

func Src(v string) Node

Src sets the src attribute for elements.

func SrcSet added in v1.0.1

func SrcSet(v string) Node

SrcSet sets the srcset attribute for elements.

func Step added in v1.0.1

func Step(v string) Node

Step sets the step attribute for input elements.

func Stroke added in v1.0.2

func Stroke(v string) Node

Stroke returns an SVG attribute node for specifying the stroke color. The stroke color determines the color used to stroke the SVG element. The value of the stroke color is specified as a string. Example usage: Stroke("blue")

func StrokeWidth added in v1.0.2

func StrokeWidth(v string) Node

StrokeWidth returns an SVG attribute node for specifying the stroke width. The stroke width determines the thickness of the stroke applied to an SVG element. The value of the stroke width is specified as a string. Example usage: StrokeWidth("2px")

func Strong added in v1.0.1

func Strong(children ...Node) Node

Strong represents an HTML strong element.

func StyleAttribute added in v1.0.1

func StyleAttribute(v string) Node

StyleAttribute sets the style attribute for elements.

func StyleElement added in v1.0.1

func StyleElement(children ...Node) Node

StyleElement represents an HTML style element.

func Sub added in v1.0.1

func Sub(children ...Node) Node

Sub represents an HTML sub element.

func Summary added in v1.0.1

func Summary(children ...Node) Node

Summary represents an HTML summary element.

func Sup added in v1.0.1

func Sup(children ...Node) Node

Sup represents an HTML sup element.

func TBody added in v1.0.1

func TBody(children ...Node) Node

TBody represents an HTML tbody element.

func TFoot added in v1.0.1

func TFoot(children ...Node) Node

TFoot represents an HTML tfoot element.

func THead added in v1.0.1

func THead(children ...Node) Node

THead represents an HTML thead element.

func TabIndex added in v1.0.1

func TabIndex(v string) Node

TabIndex sets the tabindex attribute for elements.

func Table added in v1.0.1

func Table(children ...Node) Node

Table represents an HTML table element.

func Target added in v1.0.1

func Target(v string) Node

Target sets the target attribute for elements.

func Td added in v1.0.1

func Td(children ...Node) Node

Td represents an HTML td element.

func Template added in v1.0.33

func Template(children ...Node) Node

Template represents an HTML template element.

func Text added in v1.0.1

func Text(t string) Node

Text is a node that renders a text.

func Textarea added in v1.0.1

func Textarea(children ...Node) Node

Textarea represents an HTML textarea element.

func Textf added in v1.0.1

func Textf(format string, a ...interface{}) Node

Textf is a node that renders a formatted text.

func Th added in v1.0.1

func Th(children ...Node) Node

Th represents an HTML th element.

func Time added in v1.0.1

func Time(children ...Node) Node

Time represents an HTML time element.

func Title added in v1.0.33

func Title(children ...Node) Node

Title represents an HTML title element.

func TitleAttribute added in v1.0.1

func TitleAttribute(v string) Node

TitleAttribute sets the title attribute for elements.

func TitleElement added in v1.0.1

func TitleElement(children ...Node) Node

TitleElement represents an HTML title element.

func Tr added in v1.0.1

func Tr(children ...Node) Node

Tr represents an HTML tr element.

func Track added in v1.0.33

func Track(children ...Node) Node

Track represents an HTML track element.

func Type added in v1.0.1

func Type(v string) Node

Type sets the type attribute for elements.

func U added in v1.0.1

func U(children ...Node) Node

U represents an HTML u element.

func Ul added in v1.0.1

func Ul(children ...Node) Node

Ul represents an HTML ul element.

func Value added in v1.0.1

func Value(v string) Node

Value sets the value attribute for elements.

func Var added in v1.0.1

func Var(children ...Node) Node

Var represents an HTML var element.

func Video added in v1.0.1

func Video(children ...Node) Node

Video represents an HTML video element.

func ViewBox added in v1.0.2

func ViewBox(v string) Node

ViewBox returns an SVG attribute node for specifying the viewBox. The viewBox defines the position and size of the SVG element's viewport. The value of the viewBox is specified as a string. Example usage: ViewBox("0 0 100 100")

func Wbr added in v1.0.1

func Wbr(children ...Node) Node

Wbr represents an HTML wbr element.

func Width added in v1.0.1

func Width(v string) Node

Width sets the width attribute for elements.

func XSLTTemplat added in v1.0.33

func XSLTTemplat(v string) Node

XSLTTemplat sets the xslt-template attribute to specify the xslt template for the response.

type NodeFunc added in v1.0.1

type NodeFunc func(io.Writer) error

NodeFunc is a function that renders a node.

func Element added in v1.0.1

func Element(name string, children ...Node) NodeFunc

Element is a node that renders an HTML element.

Example (A)
_ = Element("a").Render(os.Stdout)
Output:

<a></a>
Example (Div)
_ = Element("div").Render(os.Stdout)
Output:

<div></div>
Example (Tag)
package main

import (
	"os"

	htmx "github.com/zeiss/fiber-htmx"
)

func main() {
	_ = htmx.Element("div").Render(os.Stdout)
}
Output:

<div></div>

func (NodeFunc) Render added in v1.0.1

func (n NodeFunc) Render(w io.Writer) error

Render renders the node.

func (NodeFunc) String added in v1.0.1

func (n NodeFunc) String() string

String returns the node as a string.

func (NodeFunc) Type added in v1.0.1

func (n NodeFunc) Type() NodeType

Type returns the node type.

type NodeType added in v1.0.1

type NodeType int

NodeType is the type of a node.

type NodeTypeDescriptor added in v1.0.1

type NodeTypeDescriptor interface {
	Type() NodeType
}

NodeTypeDescriptor is a node that has a type.

type RangeLoop added in v1.0.38

type RangeLoop interface {
	// Filter loops and filters the content.
	Filter(f func(int) bool) RangeLoop
	// Map loops and maps the content.
	Map(f func(int) Node) RangeLoop
	// Group returns the nodes as a group.
	Group() Node
}

RangeLoop is a loop control structure.

func Range added in v1.0.38

func Range(nodes ...Node) RangeLoop

Range loops over the content.

type ResolveFunc added in v1.0.42

type ResolveFunc func(c *fiber.Ctx) (interface{}, interface{}, error)

ResolveFunc is a function that resolves locals for the context.

type Swap added in v1.0.2

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

Swap ...

func NewSwap added in v1.0.2

func NewSwap() *Swap

NewSwap ...

func (*Swap) FocusScroll added in v1.0.2

func (s *Swap) FocusScroll(focusScroll bool) *Swap

FocusScroll ...

func (*Swap) IgnoreTitle added in v1.0.2

func (s *Swap) IgnoreTitle(ignoreTitle bool) *Swap

IgnoreTitle ...

func (*Swap) Scroll added in v1.0.2

func (s *Swap) Scroll(direction HxSwapDirection, target ...string) *Swap

Scroll ...

func (*Swap) ScrollBottom added in v1.0.2

func (s *Swap) ScrollBottom(target ...string) *Swap

ScrollBottom ...

func (*Swap) ScrollTop added in v1.0.2

func (s *Swap) ScrollTop(target ...string) *Swap

ScrollTop ...

func (*Swap) Settle added in v1.0.2

func (s *Swap) Settle(swap ...time.Duration) *Swap

Settle modifies the amount of time that htmx will wait after receiving a response to settle the content

func (*Swap) Show added in v1.0.2

func (s *Swap) Show(direction HxSwapDirection, target ...string) *Swap

Show ...

func (*Swap) ShowBottom added in v1.0.2

func (s *Swap) ShowBottom(target ...string) *Swap

ShowBottom ...

func (*Swap) ShowTop added in v1.0.2

func (s *Swap) ShowTop(target ...string) *Swap

ShowTop ...

func (*Swap) String added in v1.0.2

func (s *Swap) String() string

String ...

func (*Swap) Style added in v1.0.2

func (s *Swap) Style(style HXSwapStyle) *Swap

Style ...

func (*Swap) Swap added in v1.0.2

func (s *Swap) Swap(swap ...time.Duration) *Swap

Swap modifies the amount of time that htmx will wait after receiving a response to swap the content

func (*Swap) Transition added in v1.0.2

func (s *Swap) Transition(transition bool) *Swap

Transition ...

type UnimplementedContext added in v1.0.42

type UnimplementedContext struct{}

UnimplementedContext is a helper type for unimplemented contexts.

func (*UnimplementedContext) Path added in v1.0.43

func (u *UnimplementedContext) Path() string

Path is a helper function to get the path from the context.

func (*UnimplementedContext) Values added in v1.0.42

func (u *UnimplementedContext) Values(key any, value ...any) (val any)

Values is a helper function to get the values from the context.

func (*UnimplementedContext) ValuesBool added in v1.0.42

func (u *UnimplementedContext) ValuesBool(key any, value ...any) (val bool)

ValuesBool is a helper function to get the values as a bool from the context.

func (*UnimplementedContext) ValuesInt added in v1.0.42

func (u *UnimplementedContext) ValuesInt(key any, value ...any) (val int)

ValuesInt is a helper function to get the values as an int from the context.

func (*UnimplementedContext) ValuesString added in v1.0.42

func (u *UnimplementedContext) ValuesString(key any, value ...any) (val string)

ValuesString is a helper function to get the values as a string from the context.

type UnimplementedController added in v1.0.42

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

UnimplementedController is the default controller implementation.

func (*UnimplementedController) Delete added in v1.0.42

func (c *UnimplementedController) Delete() error

Delete is called when the controller is executed with the DELETE method.

func (*UnimplementedController) Finalize added in v1.0.42

func (c *UnimplementedController) Finalize() error

Finalize is called after the controller is executed.

func (*UnimplementedController) Get added in v1.0.42

func (c *UnimplementedController) Get() error

Get is called when the controller is executed with the GET method.

func (*UnimplementedController) Hx added in v1.0.42

func (c *UnimplementedController) Hx() *Htmx

Hx returns the htmx instance.

func (*UnimplementedController) Init added in v1.0.42

func (c *UnimplementedController) Init(hx *Htmx) error

Init is called when the controller is initialized.

func (*UnimplementedController) Options added in v1.0.42

func (c *UnimplementedController) Options() error

Options is called when the controller is executed with the OPTIONS method.

func (*UnimplementedController) Patch added in v1.0.42

func (c *UnimplementedController) Patch() error

Patch is called when the controller is executed with the PATCH method.

func (*UnimplementedController) Post added in v1.0.42

func (c *UnimplementedController) Post() error

Post is called when the controller is executed with the POST method.

func (*UnimplementedController) Prepare added in v1.0.42

func (c *UnimplementedController) Prepare() error

Prepare is called before the controller is executed.

func (*UnimplementedController) Put added in v1.0.42

func (c *UnimplementedController) Put() error

Put is called when the controller is executed with the PUT method.

Directories

Path Synopsis
components
icons
Package icons provides a set of icons that can be used in the application.
Package icons provides a set of icons that can be used in the application.
internal

Jump to

Keyboard shortcuts

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