Documentation ¶
Index ¶
- func ErrPrependPath(err error, path ...string) error
- func GetDataFromRequest(params ...string) func(r *http.Request) Data
- type A
- type Attributes
- func (a *Attributes) Bool(name string, active bool) *Attributes
- func (a *Attributes) Copy() *Attributes
- func (a *Attributes) Delete(name string) *Attributes
- func (a *Attributes) Ensure() *Attributes
- func (a *Attributes) Get(key string) (string, bool)
- func (a *Attributes) IsEmpty() bool
- func (a *Attributes) String(name string, value string) *Attributes
- func (a *Attributes) Strings(name string, values ...string) *Attributes
- func (a *Attributes) Write(w io.Writer) error
- type Button
- type Component
- type ComponentTag
- type Data
- type Div
- type Document
- type Element
- type Elements
- type Fragment
- type Generator
- type H
- type Header
- type Img
- type Input
- type Interaction
- type IterGenerator
- type LI
- type Middleware
- type OL
- type P
- type Page
- func (p *Page) Add(component Component)
- func (p *Page) AtPath(segments ...string) *Page
- func (p *Page) Build() (http.Handler, error)
- func (p *Page) Init(c Component) Element
- func (p *Page) Path(segments ...string) string
- func (p *Page) Render(element Element) (http.Handler, error)
- func (p *Page) Use(middleware ...Middleware)
- type PathError
- type Raw
- type RawError
- type Reference
- type RenderFunc
- type Request
- type Scope
- type ScrollPosition
- type Span
- type Swap
- type SwapMethod
- type TBlock
- type TWith
- type Tag
- type TemplateHandler
- type Trigger
- type TriggerMethod
- type UL
- type ValidationFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ErrPrependPath ¶
ErrPrependPath either adds the path to an existing PathError or creates a new one.
Types ¶
type A ¶
type A struct { ID string Classes []string Attrs *Attributes Hidden bool Href string Content Component }
A is a shorthand for an "a" Tag.
type Attributes ¶
Attributes defines a map of attributes for use in a Tag. Attributes are rendered in alphabetical order. Attributes are stored as Elements to allow for templating.
func Attrs ¶
func Attrs() *Attributes
Attrs creates a new Attributes. This should be used over creating them manually.
func (*Attributes) Bool ¶
func (a *Attributes) Bool(name string, active bool) *Attributes
Bool adds a named flag to the attributes if active is true.
func (*Attributes) Copy ¶
func (a *Attributes) Copy() *Attributes
Copy returns a shallow copy of the attributes.
func (*Attributes) Delete ¶
func (a *Attributes) Delete(name string) *Attributes
func (*Attributes) Ensure ¶
func (a *Attributes) Ensure() *Attributes
Ensure guarantees that the Attributes are not nil.
func (*Attributes) Get ¶
func (a *Attributes) Get(key string) (string, bool)
Get returns the first value of the attribute if it exists.
func (*Attributes) IsEmpty ¶
func (a *Attributes) IsEmpty() bool
IsEmpty returns true if there are no attributes.
func (*Attributes) String ¶
func (a *Attributes) String(name string, value string) *Attributes
String adds a named value to the attributes if it is not empty.
func (*Attributes) Strings ¶
func (a *Attributes) Strings(name string, values ...string) *Attributes
Slice adds a named list of values to the attributes if it is not empty.
type Button ¶
type Button struct { ID string Classes []string Attr *Attributes Content Component Hidden bool Disabled bool }
Button is a shorthand for a "button" Tag.
type Component ¶
type Component interface { // Init converts the component into an Element based on the contextual data of the Framework. Init(p *Page) (Element, error) }
Component defines the high level abstraction of an HTML element. Components are decomposed into an Element through the Init call.
type ComponentTag ¶
type ComponentTag struct { Name string Attrs *Attributes Content Component }
ComponentTag creates a html tag with the given name.
type Data ¶
Data represents a neutral representation of data that is passed through any method HTMX requests.
func GetAllDataFromRequest ¶
GetAllDataFromRequest returns all Data from the request. Handles both GET and POST requests.
func (Data) Merge ¶
Merge merges two Data maps together. The addition map will overwrite any existing keys.
func (Data) SetInResponse ¶
func (d Data) SetInResponse(w http.ResponseWriter, r *http.Request)
SetValuesInResponse sets the data Data in the response. Handles both GET and POST requests.
type Div ¶
type Div struct { ID string Classes []string Attrs *Attributes Hidden bool Content Component }
Div is a shorthand for a "div" Tag.
type Document ¶
type Document struct { // Header defines Component to be rendered in between the <head> tags. Header Component // Body defines the Component to be rendered in between the <body> tags. Body Component }
Document the baseline component of an HTML document.
type Element ¶
type Element interface { Render(w io.Writer) error Validate() error FindAttrs() (*Attributes, error) }
Element defines the low level abstraction of an HTML element. Elements write directly to an io.Writer and are used to build a html/template.
type Elements ¶
type Elements []Element
Elements defines a slice of Elements that can be used as a single Element.
func (Elements) FindAttrs ¶
func (e Elements) FindAttrs() (*Attributes, error)
type Fragment ¶
type Fragment []Component
Fragment defines a slice of Components that can be used as a single Component.
type Generator ¶
Generator used to generate content for building templates.
func NewDefaultGenerator ¶
func NewDefaultGenerator() Generator
type H ¶
type H struct { ID string Classes []string Attrs *Attributes Hidden bool Level int Content Component }
H is a shorthand for a "h*" Tag.
type Header ¶
type Header struct { ID string Classes []string Attr *Attributes Hidden bool Content Component }
Header is a shorthand for a "header" Tag.
type Input ¶
type Input struct { ID string Classes []string Attr *Attributes Hidden bool Type string Name string Value string Disabled bool }
Input is a shorthand for an "input" Tag.
type Interaction ¶
type Interaction struct { Name string // contains filtered or unexported fields }
Interaction defines a set of Swaps, Triggers, and Updates. Swaps define changes to the content of the page. Triggers define what can cause the Interaction to occur. Updates define changes to the backing data. All interactions are named to mount the interaction to the current page path.
func NewInteraction ¶
func NewInteraction(name string) *Interaction
NewInteraction creates a new Interaction with the given name.
func (*Interaction) AddSwap ¶
func (i *Interaction) AddSwap(a *Swap) *Interaction
AddSwap adds a Swap to the Interaction.
func (*Interaction) AddTrigger ¶
func (i *Interaction) AddTrigger(t *Trigger) *Interaction
AddTrigger adds a Trigger to the Interaction.
func (*Interaction) Handle ¶
func (i *Interaction) Handle(f func(*http.Request)) *Interaction
Handle adds a handler to the Interaction.
func (*Interaction) Swap ¶
func (i *Interaction) Swap() *Swap
Swap creates a new Swap for the Interaction.
func (*Interaction) Trigger ¶
func (i *Interaction) Trigger() *Trigger
Trigger creates a new Trigger for the Interaction.
type IterGenerator ¶
func (*IterGenerator) NewID ¶
func (b *IterGenerator) NewID(prefix string) string
type LI ¶
type LI struct { ID string Classes []string Attrs *Attributes Hidden bool Content Component }
LI is a shorthand for a "li" Tag.
type Middleware ¶
func UpdateParams ¶
func UpdateParams(names ...string) Middleware
UpdateParams updates the passed values into the Query Params of the response. Handles both GET and POST requests.
type OL ¶
type OL struct { ID string Classes []string Attrs *Attributes Hidden bool Items []LI }
OL is a shorthand for an "ol" Tag.
type P ¶
type P struct { ID string Classes []string Attrs *Attributes Hidden bool Content Component }
P is a shorthand for a "p" Tag.
type Page ¶
type Page struct { // PathPrefix defines the current prefix for a component to build requests from. PathPrefix string // Index collects all the interactive components of the page. Index map[string]Request // The template to use for rendering components. Template *template.Template // Generator provides generated content for initializing elements. Generator Generator }
Page defines a single page application.
func (*Page) Add ¶
Add adds a component to the request at this pages current path. This is when a Component is initialized through Init into elements.
func (*Page) AtPath ¶
AtPath returns a new Page with the with the segments appended to the current path. Resources are shared between both new and old page, only the path is different.
func (*Page) Init ¶
Init initializes a component and returns its created element. This handles the error without the Component from having to. This is a convenience method for Components to use to initialize other components/contents.
func (*Page) Render ¶
Render creates a new http.Handler for the given element. This will run validation and rendering on the element.
func (*Page) Use ¶
func (p *Page) Use(middleware ...Middleware)
Use adds middleware to the request at this pages current path.
type Raw ¶
type Raw string
Raw defines the most simple Element that defines purely string data.
func (Raw) FindAttrs ¶
func (r Raw) FindAttrs() (*Attributes, error)
type RawError ¶
type RawError struct {
Err error
}
func (RawError) FindAttrs ¶
func (r RawError) FindAttrs() (*Attributes, error)
type Reference ¶
type Reference struct { // Target is the Component that is being referenced. Target Component // TODO: These feel wrong // ValidationFunc is an optional function to run when this reference is validated. // This is monatomic, so will only ever be called once. ValidationFunc ValidationFunc // RenderFunc is an optional function to run when this reference is rendered. RenderFunc RenderFunc // Initialized is the initialized Element, if it has been initialized. Initialized Element // Page is the page that the Reference is rendered initialized at. // This is stored so any content generated during validation can be added relative to the same location the content // is rendered. Page *Page }
Reference wraps a Component to allow for referencing during validation and rendering.
func (*Reference) FindAttrs ¶
func (m *Reference) FindAttrs() (*Attributes, error)
type Request ¶
type Request struct { Elements Elements Middleware []Middleware }
Request defines a single interactive endpoint.
type ScrollPosition ¶
type ScrollPosition string
ScrollPosition is the location to Scroll or Show in the SwapMethod.
const ( ScrollTop ScrollPosition = "top" ScrollBottom ScrollPosition = "bottom" )
type Span ¶
type Span struct { ID string Classes []string Attrs *Attributes Hidden bool Content Component }
Span is a shorthand for a "span" Tag.
type Swap ¶
type Swap struct {
// contains filtered or unexported fields
}
Swap defines the application of new content to a target. This can occur either in or out of bounds. If out of bounds, the contents will be updated to include the id of the contents.
func NewSwap ¶
func NewSwap() *Swap
Creates a new Swap. This defines the application of new content to a target. This can occur either in or out of bounds.
func (*Swap) Method ¶
func (s *Swap) Method(m SwapMethod) *Swap
Method sets the swap method to replace the target with.
func (*Swap) OutOfBounds ¶
OutOfBounds sets the Swap to be out of bounds.
type SwapMethod ¶
type SwapMethod string
SwapMethod defines the method of swapping content. See https://htmx.org/docs/#swapping
const ( SwapInnerHTML SwapMethod = "innerHTML" SwapOuterHTML SwapMethod = "outerHTML" SwapAfterBegin SwapMethod = "afterbegin" SwapBeforeBegin SwapMethod = "beforebegin" SwapAfterEnd SwapMethod = "afterend" SwapBeforeEnd SwapMethod = "beforeend" SwapDelete SwapMethod = "delete" SwapNone SwapMethod = "none" )
func (SwapMethod) FocusScroll ¶
func (s SwapMethod) FocusScroll(enabled bool) SwapMethod
FocusScroll sets the SwapMethod to scroll to the focused element when the content is swapped.
func (SwapMethod) Scroll ¶
func (s SwapMethod) Scroll(target ScrollPosition) SwapMethod
Scroll sets the SwapMethod to scroll the target to the given ScrollPosition when the content is swapped.
func (SwapMethod) Show ¶
func (s SwapMethod) Show(target ScrollPosition) SwapMethod
Show sets the SwapMethod to show the target at the given ScrollPosition when the content is swapped.
type TWith ¶
TWith defines a template block to be executed with . being set to the result of the Func.
type Tag ¶
type Tag struct { // Name of this tag. Name string // Attr defines the list of Attributes for this tag. Attrs *Attributes // Content defines the contents this wraps. Content Element }
Tag defines the lowest level HTML generic tag element.
func (*Tag) FindAttrs ¶
func (t *Tag) FindAttrs() (*Attributes, error)
type TemplateHandler ¶
func (TemplateHandler) ExecuteWith ¶
func (TemplateHandler) ServeHTTP ¶
func (t TemplateHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
func (TemplateHandler) ServeHTTPWithData ¶
func (t TemplateHandler) ServeHTTPWithData(w http.ResponseWriter, r *http.Request, data Data)
type Trigger ¶
Trigger defines something that can cause an Interaction to occur. Each Trigger can contain a set of values to be sent with the request.
func (*Trigger) Method ¶
func (t *Trigger) Method(m TriggerMethod) *Trigger
type TriggerMethod ¶
type TriggerMethod string
TriggerMethod defines the method of triggering an Interaction. See https://htmx.org/docs/#triggers
const ( TriggerLoad TriggerMethod = "load" TriggerRevealed TriggerMethod = "revealed" TriggerClick TriggerMethod = "click" TriggerChange TriggerMethod = "change" TriggerSubmit TriggerMethod = "submit" )
func (TriggerMethod) Changed ¶
func (t TriggerMethod) Changed() TriggerMethod
Changed sets the TriggerMethod to trigger when the value of the target changes.
func (TriggerMethod) Delay ¶
func (t TriggerMethod) Delay(delay time.Duration) TriggerMethod
Delay sets the TriggerMethod to trigger after the given delay. If a new event is triggered before the delay, the timer is reset.
func (TriggerMethod) Throttle ¶
func (t TriggerMethod) Throttle(delay time.Duration) TriggerMethod
Throttle sets the TriggerMethod to trigger at most once every delay. If a new event is triggered before the delay, the event is ignored.
type UL ¶
type UL struct { ID string Classes []string Attrs *Attributes Hidden bool Items []LI }
UL is a shorthand for a "ul" Tag.