Documentation
¶
Overview ¶
helpers.go provides utility functions for working with dynamic data in minty. These helpers bridge the gap between JavaScript's dynamic object model and Go's static type system, making it easier to work with map[string]interface{} data commonly encountered when migrating from React/JavaScript.
Import with: import mi "github.com/ha1tch/minty"
Package minty provides ultra-concise HTML generation for Go web applications. Import with: import mi "github.com/ha1tch/minty"
Index ¶
- Variables
- func All(items []interface{}, pred Predicate) bool
- func Any(items []interface{}, pred Predicate) bool
- func Avg(items []interface{}, key string) float64
- func Bool(m map[string]interface{}, key string) bool
- func Contains(m map[string]interface{}, key, substr string) bool
- func ContainsI(m map[string]interface{}, key, substr string) bool
- func Count(items []interface{}, pred Predicate) int
- func Eq(m map[string]interface{}, key, val string) bool
- func FilterItems(items []interface{}, pred Predicate) []interface{}
- func Find(items []interface{}, pred Predicate) interface{}
- func Float(m map[string]interface{}, key string) float64
- func GetHTMXCurrentURL(r *http.Request) string
- func GetHTMXTarget(r *http.Request) string
- func GetHTMXTrigger(r *http.Request) string
- func GetHTMXTriggerName(r *http.Request) string
- func GroupItems(items []interface{}, key string) map[string][]interface{}
- func Gt(m map[string]interface{}, key string, val int) bool
- func Gte(m map[string]interface{}, key string, val int) bool
- func HTMXHandler(fullPageTemplate H, fragmentTemplate H) http.HandlerFunc
- func HTMXHandlerFunc(fullPageFn func(*http.Request) H, fragmentFn func(*http.Request) H) http.HandlerFunc
- func HTMXStopPolling(w http.ResponseWriter)
- func Int(m map[string]interface{}, key string) int
- func IsHTMX(r *http.Request) bool
- func IsHTMXBoosted(r *http.Request) bool
- func Lt(m map[string]interface{}, key string, val int) bool
- func Lte(m map[string]interface{}, key string, val int) bool
- func MaxInt(items []interface{}, key string) int
- func MinInt(items []interface{}, key string) int
- func Ne(m map[string]interface{}, key, val string) bool
- func Pluck(items []interface{}, key string) []string
- func PluckInt(items []interface{}, key string) []int
- func Render(template H, w io.Writer) error
- func RenderFragment(template H, w http.ResponseWriter) error
- func RenderFragmentWithTrigger(template H, w http.ResponseWriter, triggerEvents string) error
- func RenderHandler(template H) http.HandlerFunc
- func RenderHandlerFunc(fn func(*http.Request) H) http.HandlerFunc
- func RenderToString(template H) string
- func SanitizeInput(input string) string
- func SetHTMXLocation(w http.ResponseWriter, url string)
- func SetHTMXPushURL(w http.ResponseWriter, url string)
- func SetHTMXRedirect(w http.ResponseWriter, url string)
- func SetHTMXRefresh(w http.ResponseWriter)
- func SetHTMXReplaceURL(w http.ResponseWriter, url string)
- func SetHTMXReswap(w http.ResponseWriter, strategy string)
- func SetHTMXRetarget(w http.ResponseWriter, selector string)
- func SetHTMXTrigger(w http.ResponseWriter, events string)
- func SetHTMXTriggerAfterSettle(w http.ResponseWriter, events string)
- func SetHTMXTriggerAfterSwap(w http.ResponseWriter, events string)
- func SortBy(items []interface{}, key string, dir SortDir) []interface{}
- func SortByMulti(items []interface{}, fields ...SortField) []interface{}
- func Str(m map[string]interface{}, key string) string
- func Sum(items []interface{}, key string) int
- func SumFloat(items []interface{}, key string) float64
- func ToMap(v interface{}) map[string]interface{}
- func ToSlice(v interface{}) []interface{}
- func Truthy(v interface{}) bool
- type Attribute
- func AbbrAttr(value string) Attribute
- func Accept(value string) Attribute
- func AccessKey(value string) Attribute
- func Action(url string) Attribute
- func Alt(text string) Attribute
- func AriaChecked(value bool) Attribute
- func AriaDescribedby(value string) Attribute
- func AriaDisabled(value bool) Attribute
- func AriaExpanded(value bool) Attribute
- func AriaHidden(value bool) Attribute
- func AriaLabel(value string) Attribute
- func AriaLabelledby(value string) Attribute
- func AriaSelected(value bool) Attribute
- func Async() Attribute
- func Attr(name, value string) Attribute
- func Autocomplete(value string) Attribute
- func Autofocus() Attribute
- func Autoplay() Attribute
- func Charset(value string) Attribute
- func Checked() Attribute
- func CiteAttr(value string) Attribute
- func Class(value string) Attribute
- func Cols(value int) Attribute
- func Colspan(value int) Attribute
- func Content(value string) Attribute
- func ContentEditable(value bool) Attribute
- func Controls() Attribute
- func Crossorigin(value string) Attribute
- func Cx(value string) Attribute
- func Cy(value string) Attribute
- func D(value string) Attribute
- func Data(name, value string) Attribute
- func DataAttr(name, value string) Attribute
- func Datetime(value string) Attribute
- func Defer() Attribute
- func Dir(value string) Attribute
- func Disabled() Attribute
- func Download(filename string) Attribute
- func Enctype(value string) Attribute
- func Fill(value string) Attribute
- func For(value string) Attribute
- func Form(value string) Attribute
- func Formaction(value string) Attribute
- func Formenctype(value string) Attribute
- func Formmethod(value string) Attribute
- func Formnovalidate() Attribute
- func Formtarget(value string) Attribute
- func Headers(value string) Attribute
- func Height(value interface{}) Attribute
- func Hidden() Attribute
- func High(value float64) Attribute
- func Href(url string) Attribute
- func Hreflang(value string) Attribute
- func HtmxBoost() Attribute
- func HtmxConfirm(message string) Attribute
- func HtmxDelete(url string) Attribute
- func HtmxExt(extensions string) Attribute
- func HtmxGet(url string) Attribute
- func HtmxHeaders(headers string) Attribute
- func HtmxInclude(selector string) Attribute
- func HtmxIndicator(selector string) Attribute
- func HtmxLoadingClass() Attribute
- func HtmxPatch(url string) Attribute
- func HtmxPost(url string) Attribute
- func HtmxPreserve() Attribute
- func HtmxPrompt(message string) Attribute
- func HtmxPushURL(url string) Attribute
- func HtmxPut(url string) Attribute
- func HtmxReplaceURL(url string) Attribute
- func HtmxSwap(strategy string) Attribute
- func HtmxSwapOOB(value string) Attribute
- func HtmxSync(value string) Attribute
- func HtmxTarget(selector string) Attribute
- func HtmxTrigger(trigger string) Attribute
- func HtmxVals(values string) Attribute
- func HttpEquiv(value string) Attribute
- func HxConfirm(message string) Attribute
- func HxDelete(url string) Attribute
- func HxGet(url string) Attribute
- func HxInclude(selector string) Attribute
- func HxIndicator(selector string) Attribute
- func HxPatch(url string) Attribute
- func HxPost(url string) Attribute
- func HxPut(url string) Attribute
- func HxSwap(strategy string) Attribute
- func HxTarget(selector string) Attribute
- func HxTrigger(trigger string) Attribute
- func HxVals(values string) Attribute
- func ID(value string) Attribute
- func Lang(value string) Attribute
- func List(value string) Attribute
- func Loop() Attribute
- func Low(value float64) Attribute
- func Max(value interface{}) Attribute
- func MaxLength(value int) Attribute
- func Media(value string) Attribute
- func Method(value string) Attribute
- func Min(value interface{}) Attribute
- func MinLength(value int) Attribute
- func Multiple() Attribute
- func Muted() Attribute
- func Name(value string) Attribute
- func Novalidate() Attribute
- func Open() Attribute
- func Optimum(value float64) Attribute
- func Pattern(value string) Attribute
- func Placeholder(value string) Attribute
- func Points(value string) Attribute
- func Poster(url string) Attribute
- func Preload(value string) Attribute
- func R(value string) Attribute
- func Readonly() Attribute
- func Referrerpolicy(value string) Attribute
- func Rel(value string) Attribute
- func Required() Attribute
- func Role(value string) Attribute
- func Rows(value int) Attribute
- func Rowspan(value int) Attribute
- func Scope(value string) Attribute
- func Selected() Attribute
- func Size(value int) Attribute
- func Sizes(value string) Attribute
- func Spellcheck(value bool) Attribute
- func Src(url string) Attribute
- func Srcset(value string) Attribute
- func Step(value interface{}) Attribute
- func Stroke(value string) Attribute
- func StrokeWidth(value string) Attribute
- func Style(value string) Attribute
- func TabIndex(value int) Attribute
- func Target(value string) Attribute
- func Title(value string) Attribute
- func Translate(value bool) Attribute
- func Type(value string) Attribute
- func Value(value string) Attribute
- func ViewBox(value string) Attribute
- func Width(value interface{}) Attribute
- type BooleanAttribute
- type Builder
- func (b *Builder) A(args ...interface{}) Node
- func (b *Builder) Abbr(children ...interface{}) Node
- func (b *Builder) Address(children ...interface{}) Node
- func (b *Builder) Area(attrs ...Attribute) Node
- func (b *Builder) Article(children ...interface{}) Node
- func (b *Builder) Aside(children ...interface{}) Node
- func (b *Builder) Audio(children ...interface{}) Node
- func (b *Builder) B(children ...interface{}) Node
- func (b *Builder) Base(attrs ...Attribute) Node
- func (b *Builder) Bdi(children ...interface{}) Node
- func (b *Builder) Bdo(children ...interface{}) Node
- func (b *Builder) Blockquote(children ...interface{}) Node
- func (b *Builder) Body(children ...interface{}) Node
- func (b *Builder) Br() Node
- func (b *Builder) Button(args ...interface{}) Node
- func (b *Builder) Canvas(children ...interface{}) Node
- func (b *Builder) Caption(children ...interface{}) Node
- func (b *Builder) Circle(children ...interface{}) Node
- func (b *Builder) Cite(children ...interface{}) Node
- func (b *Builder) Code(children ...interface{}) Node
- func (b *Builder) Col(attrs ...Attribute) Node
- func (b *Builder) Colgroup(children ...interface{}) Node
- func (b *Builder) Data(children ...interface{}) Node
- func (b *Builder) Datalist(children ...interface{}) Node
- func (b *Builder) Dd(children ...interface{}) Node
- func (b *Builder) Defs(children ...interface{}) Node
- func (b *Builder) Del(children ...interface{}) Node
- func (b *Builder) Details(children ...interface{}) Node
- func (b *Builder) Dfn(children ...interface{}) Node
- func (b *Builder) Dialog(children ...interface{}) Node
- func (b *Builder) Div(children ...interface{}) Node
- func (b *Builder) Dl(children ...interface{}) Node
- func (b *Builder) Dt(children ...interface{}) Node
- func (b *Builder) Em(children ...interface{}) Node
- func (b *Builder) Embed(attrs ...Attribute) Node
- func (b *Builder) Fieldset(children ...interface{}) Node
- func (b *Builder) Footer(children ...interface{}) Node
- func (b *Builder) Form(args ...interface{}) Node
- func (b *Builder) G(children ...interface{}) Node
- func (b *Builder) H1(children ...interface{}) Node
- func (b *Builder) H2(children ...interface{}) Node
- func (b *Builder) H3(children ...interface{}) Node
- func (b *Builder) H4(children ...interface{}) Node
- func (b *Builder) H5(children ...interface{}) Node
- func (b *Builder) H6(children ...interface{}) Node
- func (b *Builder) Head(children ...interface{}) Node
- func (b *Builder) Header(children ...interface{}) Node
- func (b *Builder) Hgroup(children ...interface{}) Node
- func (b *Builder) Hr(attrs ...Attribute) Node
- func (b *Builder) Html(children ...interface{}) Node
- func (b *Builder) I(children ...interface{}) Node
- func (b *Builder) Iframe(children ...interface{}) Node
- func (b *Builder) Img(attrs ...Attribute) Node
- func (b *Builder) Input(attrs ...Attribute) Node
- func (b *Builder) Ins(children ...interface{}) Node
- func (b *Builder) Kbd(children ...interface{}) Node
- func (b *Builder) Label(args ...interface{}) Node
- func (b *Builder) Legend(children ...interface{}) Node
- func (b *Builder) Li(children ...interface{}) Node
- func (b *Builder) Line(children ...interface{}) Node
- func (b *Builder) Link(attrs ...Attribute) Node
- func (b *Builder) Main(children ...interface{}) Node
- func (b *Builder) Map(children ...interface{}) Node
- func (b *Builder) Mark(children ...interface{}) Node
- func (b *Builder) Math(children ...interface{}) Node
- func (b *Builder) Menu(children ...interface{}) Node
- func (b *Builder) Meta(attrs ...Attribute) Node
- func (b *Builder) Meter(children ...interface{}) Node
- func (b *Builder) Nav(children ...interface{}) Node
- func (b *Builder) Noscript(children ...interface{}) Node
- func (b *Builder) Object(children ...interface{}) Node
- func (b *Builder) Ol(children ...interface{}) Node
- func (b *Builder) Optgroup(args ...interface{}) Node
- func (b *Builder) Option(args ...interface{}) Node
- func (b *Builder) Output(children ...interface{}) Node
- func (b *Builder) P(children ...interface{}) Node
- func (b *Builder) Param(attrs ...Attribute) Node
- func (b *Builder) Path(children ...interface{}) Node
- func (b *Builder) Picture(children ...interface{}) Node
- func (b *Builder) Polygon(children ...interface{}) Node
- func (b *Builder) Polyline(children ...interface{}) Node
- func (b *Builder) Pre(children ...interface{}) Node
- func (b *Builder) Progress(children ...interface{}) Node
- func (b *Builder) Q(children ...interface{}) Node
- func (b *Builder) Rect(children ...interface{}) Node
- func (b *Builder) Rp(children ...interface{}) Node
- func (b *Builder) Rt(children ...interface{}) Node
- func (b *Builder) Ruby(children ...interface{}) Node
- func (b *Builder) S(children ...interface{}) Node
- func (b *Builder) Samp(children ...interface{}) Node
- func (b *Builder) Script(children ...interface{}) Node
- func (b *Builder) Section(children ...interface{}) Node
- func (b *Builder) Select(args ...interface{}) Node
- func (b *Builder) Slot(children ...interface{}) Node
- func (b *Builder) Small(children ...interface{}) Node
- func (b *Builder) Source(attrs ...Attribute) Node
- func (b *Builder) Span(children ...interface{}) Node
- func (b *Builder) Strong(children ...interface{}) Node
- func (b *Builder) Style(children ...interface{}) Node
- func (b *Builder) Sub(children ...interface{}) Node
- func (b *Builder) Summary(children ...interface{}) Node
- func (b *Builder) Sup(children ...interface{}) Node
- func (b *Builder) Svg(children ...interface{}) Node
- func (b *Builder) SvgText(children ...interface{}) Node
- func (b *Builder) Table(children ...interface{}) Node
- func (b *Builder) Tbody(children ...interface{}) Node
- func (b *Builder) Td(children ...interface{}) Node
- func (b *Builder) Template(children ...interface{}) Node
- func (b *Builder) Text(content string) Node
- func (b *Builder) Textarea(args ...interface{}) Node
- func (b *Builder) Tfoot(children ...interface{}) Node
- func (b *Builder) Th(children ...interface{}) Node
- func (b *Builder) Thead(children ...interface{}) Node
- func (b *Builder) Time(children ...interface{}) Node
- func (b *Builder) Title(text string) Node
- func (b *Builder) Tr(children ...interface{}) Node
- func (b *Builder) Track(attrs ...Attribute) Node
- func (b *Builder) U(children ...interface{}) Node
- func (b *Builder) Ul(children ...interface{}) Node
- func (b *Builder) Use(children ...interface{}) Node
- func (b *Builder) Var(children ...interface{}) Node
- func (b *Builder) Video(children ...interface{}) Node
- func (b *Builder) Wbr() Node
- type DarkMode
- type DarkModeConfig
- type DarkModeOption
- type Element
- type FilterOption
- type Fragment
- type H
- func ArticleLayout(title, author string, publishDate string, content H) H
- func AutoRefresh(url string, interval string) H
- func BreadcrumbNavigation(links []NavLink) H
- func CardLayout(title string, content H, actions H) H
- func Component(className string, content H) H
- func Container(content H) H
- func Document(title string, headNodes []Node, body Node) H
- func ErrorMessage(message string) H
- func FlexLayout(direction, justify, align string, content H) H
- func FormField(label, name, fieldType, value, errorMsg string, required bool, ...) H
- func FullLayout(title string, nav, main, aside, footer H) H
- func GridLayout(columns string, gap string, content H) H
- func HTMXForm(method, action, targetSelector string, children ...interface{}) H
- func HTMXLoadingIndicator(text string) H
- func HTMXLoadingSpinner() H
- func If(condition bool, template H) H
- func IfElse(condition bool, trueTemplate, falseTemplate H) H
- func InfiniteScroll(loadURL, targetSelector string) H
- func InfoMessage(message string) H
- func Join[T any](items []T, renderer func(T) H, separator H) H
- func Layout(title string, content H) H
- func LayoutWithCSS(title string, cssURL string, content H) H
- func LayoutWithMeta(title, description string, keywords []string, content H) H
- func LiveSearch(searchURL, targetSelector, placeholder string) H
- func Map[T any](items []T, renderer func(T) H) H
- func ModalLayout(id, title string, content, actions H) H
- func Navigation(links []NavLink) H
- func Notification(message, notificationType string) H
- func Paginate[T any](items []T, page, perPage int, renderer func([]T, PaginationInfo) H) H
- func Partition[T any](items []T, predicate func(T) bool, trueRenderer, falseRenderer func([]T) H) H
- func ProgressBar(progressURL string, targetSelector string) H
- func SearchWithFilters(searchURL string, filters []FilterOption) H
- func SectionLayout(heading string, content H) H
- func SelectField(label, name, value, errorMsg string, required bool, options []SelectOption) H
- func SkipLink(href, text string) H
- func SuccessMessage(message string) H
- func TabContainer(tabs []Tab, activeTab string) H
- func TextareaField(label, name, value, errorMsg string, required bool, rows, cols int) H
- func Unless(condition bool, template H) H
- func VisuallyHidden(content H) H
- func WarningMessage(message string) H
- func When[T comparable](value T, cases []WhenCase[T], defaultTemplate H) H
- func WithDefault[T any](items []T, template H, defaultTemplate H) H
- type NavLink
- type Node
- func Chunk[T any](items []T, chunkSize int, renderer func([]T) H) []Node
- func Each[T any](items []T, renderer func(T) H) []Node
- func EachWithIndex[T any](items []T, renderer func(int, T) H) []Node
- func Filter[T any](items []T, predicate func(T) bool, renderer func(T) H) []Node
- func GroupBy[T any, K comparable](items []T, keyFn func(T) K, renderer func(K, []T) H) []Node
- func IfTruthy(v interface{}, then H) Node
- func IfTruthyElse(v interface{}, then, els H) Node
- func NewFragment(nodes ...Node) Node
- func Range(start, end int, renderer func(int) H) []Node
- func Raw(content string) Node
- func RawHTML(content string) Node
- func Repeat(count int, template H) []Node
- func Skip[T any](items []T, n int, renderer func(T) H) []Node
- func Take[T any](items []T, n int, renderer func(T) H) []Node
- func Txt(content string) Node
- type PaginationInfo
- type Predicate
- func And(predicates ...Predicate) Predicate
- func Or(predicates ...Predicate) Predicate
- func Where(key, val string) Predicate
- func WhereContains(key, substr string) Predicate
- func WhereContainsI(key, substr string) Predicate
- func WhereGt(key string, val int) Predicate
- func WhereGte(key string, val int) Predicate
- func WhereLt(key string, val int) Predicate
- func WhereNot(key, val string) Predicate
- func WhereTruthy(key string) Predicate
- type RawNode
- type SelectOption
- type SortDir
- type SortField
- type StringAttribute
- type Tab
- type TextNode
- type ValidationError
- type ValidationResult
- type WhenCase
Constants ¶
This section is empty.
Variables ¶
var B = &Builder{}
Global builder instance using standard Minty alias pattern
var HTMXSwapStrategies = struct { InnerHTML string OuterHTML string BeforeBegin string AfterBegin string BeforeEnd string AfterEnd string Delete string None string }{ InnerHTML: "innerHTML", OuterHTML: "outerHTML", BeforeBegin: "beforebegin", AfterBegin: "afterbegin", BeforeEnd: "beforeend", AfterEnd: "afterend", Delete: "delete", None: "none", }
HTMXSwapStrategies provides constants for common swap strategies.
var HTMXTriggers = struct { Click string Change string KeyUp string KeyDown string Input string Load string Revealed string Intersect string SubmitForm string ChangeDelayed string KeyUpDelayed string InputDelayed string }{ Click: "click", Change: "change", KeyUp: "keyup", KeyDown: "keydown", Input: "input", Load: "load", Revealed: "revealed", Intersect: "intersect", SubmitForm: "submit", ChangeDelayed: "change delay:500ms", KeyUpDelayed: "keyup changed delay:300ms", InputDelayed: "input delay:300ms", }
HTMXTriggers provides constants for common trigger patterns.
Functions ¶
func All ¶ added in v0.1.0
All returns true if all items match the predicate.
Usage:
allPublished := mi.All(posts, mi.Where("status", "published"))
func Any ¶ added in v0.1.0
Any returns true if any item matches the predicate.
Usage:
hasPublished := mi.Any(posts, mi.Where("status", "published"))
func Avg ¶ added in v0.1.0
Avg returns the average of an integer field across all items.
Usage:
avgViews := mi.Avg(posts, "views")
func Bool ¶ added in v0.1.0
Bool safely extracts a bool from a map. Returns false if key is missing or value is not a boolean.
Usage:
post := map[string]interface{}{"published": true}
mi.Bool(post, "published") // true
mi.Bool(post, "missing") // false
func Contains ¶ added in v0.1.0
Contains checks if a map field (as string) contains a substring. Case-sensitive by default.
Usage:
if mi.Contains(post, "title", "Go") { ... }
func ContainsI ¶ added in v0.1.0
ContainsI checks if a map field contains a substring (case-insensitive).
Usage:
if mi.ContainsI(post, "title", "go") { ... }
func Count ¶ added in v0.1.0
Count returns the number of items that match the predicate.
Usage:
publishedCount := mi.Count(posts, mi.Where("status", "published"))
func Eq ¶ added in v0.1.0
Eq checks if a map field equals a string value.
Usage:
if mi.Eq(post, "status", "published") { ... }
func FilterItems ¶ added in v0.1.0
func FilterItems(items []interface{}, pred Predicate) []interface{}
FilterItems returns items from a slice that match the predicate.
Usage:
published := mi.FilterItems(posts, mi.Where("status", "published"))
popular := mi.FilterItems(posts, func(item interface{}) bool {
p := item.(map[string]interface{})
return mi.Int(p, "views") > 1000
})
func Find ¶ added in v0.1.0
func Find(items []interface{}, pred Predicate) interface{}
Find returns the first item that matches the predicate, or nil if not found.
Usage:
featured := mi.Find(posts, mi.Where("featured", "true"))
func Float ¶ added in v0.1.0
Float safely extracts a float64 from a map. Returns 0 if key is missing or value cannot be converted to float64.
Usage:
product := map[string]interface{}{"price": 19.99}
mi.Float(product, "price") // 19.99
func GetHTMXCurrentURL ¶
GetHTMXCurrentURL returns the current URL of the browser.
func GetHTMXTarget ¶
GetHTMXTarget returns the target element ID from HTMX request headers.
func GetHTMXTrigger ¶
GetHTMXTrigger returns the ID of the element that triggered the request.
func GetHTMXTriggerName ¶
GetHTMXTriggerName returns the name of the event that triggered the request.
func GroupItems ¶ added in v0.1.0
GroupItems groups items by a string field value.
Usage:
byStatus := mi.GroupItems(posts, "status")
// map[string][]interface{}{"published": [...], "draft": [...]}
func Gt ¶ added in v0.1.0
Gt checks if a map field is greater than an int value.
Usage:
if mi.Gt(post, "likes", 0) { ... }
func HTMXHandler ¶
func HTMXHandler(fullPageTemplate H, fragmentTemplate H) http.HandlerFunc
HTMXHandler creates an HTTP handler that automatically handles HTMX vs full page requests.
func HTMXHandlerFunc ¶
func HTMXHandlerFunc(fullPageFn func(*http.Request) H, fragmentFn func(*http.Request) H) http.HandlerFunc
HTMXHandlerFunc creates an HTTP handler from functions that return templates.
func HTMXStopPolling ¶
func HTMXStopPolling(w http.ResponseWriter)
HTMXStopPolling stops HTMX polling by returning 286 status.
func Int ¶ added in v0.1.0
Int safely extracts an int from a map. Returns 0 if key is missing or value cannot be converted to int. Handles int, float64, and string types.
Usage:
post := map[string]interface{}{"views": 42, "rating": 4.5}
mi.Int(post, "views") // 42
mi.Int(post, "rating") // 4 (truncated)
mi.Int(post, "missing") // 0
func IsHTMXBoosted ¶
IsHTMXBoosted checks if the request was boosted by HTMX.
func MaxInt ¶ added in v0.1.0
MaxInt returns the maximum value of an integer field.
Usage:
maxViews := mi.MaxInt(posts, "views")
func MinInt ¶ added in v0.1.0
MinInt returns the minimum value of an integer field.
Usage:
minViews := mi.MinInt(posts, "views")
func Ne ¶ added in v0.1.0
Ne checks if a map field does not equal a string value.
Usage:
if mi.Ne(post, "status", "draft") { ... }
func Pluck ¶ added in v0.1.0
Pluck extracts a single field from each item as a slice of strings.
Usage:
titles := mi.Pluck(posts, "title") // []string{"Hello", "World", ...}
func PluckInt ¶ added in v0.1.0
PluckInt extracts a single integer field from each item.
Usage:
viewCounts := mi.PluckInt(posts, "views") // []int{100, 200, ...}
func RenderFragment ¶
func RenderFragment(template H, w http.ResponseWriter) error
RenderFragment renders an HTML fragment for HTMX responses.
func RenderFragmentWithTrigger ¶
func RenderFragmentWithTrigger(template H, w http.ResponseWriter, triggerEvents string) error
RenderFragmentWithTrigger renders a fragment and sets trigger events.
func RenderHandler ¶
func RenderHandler(template H) http.HandlerFunc
RenderHandler creates an HTTP handler that renders a Minty template.
func RenderHandlerFunc ¶
func RenderHandlerFunc(fn func(*http.Request) H) http.HandlerFunc
RenderHandlerFunc creates an HTTP handler from a function that returns a template.
func RenderToString ¶
RenderToString renders a template and returns the HTML as a string.
func SanitizeInput ¶
SanitizeInput performs basic input sanitization.
func SetHTMXLocation ¶
func SetHTMXLocation(w http.ResponseWriter, url string)
SetHTMXLocation sets the HX-Location response header for client-side redirects.
func SetHTMXPushURL ¶
func SetHTMXPushURL(w http.ResponseWriter, url string)
SetHTMXPushURL sets the HX-Push-Url response header to update browser history.
func SetHTMXRedirect ¶
func SetHTMXRedirect(w http.ResponseWriter, url string)
SetHTMXRedirect sets the HX-Redirect response header for full redirects.
func SetHTMXRefresh ¶
func SetHTMXRefresh(w http.ResponseWriter)
SetHTMXRefresh sets the HX-Refresh response header to refresh the page.
func SetHTMXReplaceURL ¶
func SetHTMXReplaceURL(w http.ResponseWriter, url string)
SetHTMXReplaceURL sets the HX-Replace-Url response header to replace current URL.
func SetHTMXReswap ¶
func SetHTMXReswap(w http.ResponseWriter, strategy string)
SetHTMXReswap sets the HX-Reswap response header to change swap behavior.
func SetHTMXRetarget ¶
func SetHTMXRetarget(w http.ResponseWriter, selector string)
SetHTMXRetarget sets the HX-Retarget response header to change the target.
func SetHTMXTrigger ¶
func SetHTMXTrigger(w http.ResponseWriter, events string)
SetHTMXTrigger sets the HX-Trigger response header to trigger client-side events.
func SetHTMXTriggerAfterSettle ¶
func SetHTMXTriggerAfterSettle(w http.ResponseWriter, events string)
SetHTMXTriggerAfterSettle sets the HX-Trigger-After-Settle response header.
func SetHTMXTriggerAfterSwap ¶
func SetHTMXTriggerAfterSwap(w http.ResponseWriter, events string)
SetHTMXTriggerAfterSwap sets the HX-Trigger-After-Swap response header.
func SortBy ¶ added in v0.1.0
SortBy returns a new slice sorted by the given field. The original slice is not modified.
Usage:
byDate := mi.SortBy(posts, "date", mi.Desc) byTitle := mi.SortBy(posts, "title", mi.Asc)
func SortByMulti ¶ added in v0.1.0
func SortByMulti(items []interface{}, fields ...SortField) []interface{}
func Str ¶ added in v0.1.0
Str safely extracts a string from a map. Returns empty string if key is missing or value is not a string (falls back to fmt.Sprint for other types).
Usage:
post := map[string]interface{}{"title": "Hello", "views": 42}
mi.Str(post, "title") // "Hello"
mi.Str(post, "views") // "42" (converted)
mi.Str(post, "missing") // ""
func Sum ¶ added in v0.1.0
Sum returns the sum of an integer field across all items.
Usage:
totalViews := mi.Sum(posts, "views")
func SumFloat ¶ added in v0.1.0
SumFloat returns the sum of a float field across all items.
Usage:
totalRevenue := mi.SumFloat(orders, "amount")
func ToMap ¶ added in v0.1.0
func ToMap(v interface{}) map[string]interface{}
ToMap safely converts an interface{} to map[string]interface{}. Returns nil if conversion fails.
Usage:
if m := mi.ToMap(item); m != nil {
title := mi.Str(m, "title")
}
func ToSlice ¶ added in v0.1.0
func ToSlice(v interface{}) []interface{}
ToSlice safely converts an interface{} to []interface{}. Returns nil if conversion fails.
func Truthy ¶ added in v0.1.0
func Truthy(v interface{}) bool
Truthy performs a JavaScript-like truthy check on a value. Returns false for: nil, false, 0, 0.0, "", empty slices Returns true for everything else.
Usage:
mi.Truthy(nil) // false
mi.Truthy("") // false
mi.Truthy(0) // false
mi.Truthy("hello") // true
mi.Truthy(42) // true
mi.Truthy([]int{1,2,3}) // true
Types ¶
type Attribute ¶
type Attribute interface {
Apply(*Element)
}
Attribute represents an HTML attribute that can be applied to elements.
func AriaChecked ¶
AriaChecked creates an aria-checked attribute.
func AriaDescribedby ¶
AriaDescribedby creates an aria-describedby attribute.
func AriaDisabled ¶
AriaDisabled creates an aria-disabled attribute.
func AriaExpanded ¶
AriaExpanded creates an aria-expanded attribute.
func AriaHidden ¶
AriaHidden creates an aria-hidden attribute.
func AriaLabelledby ¶
AriaLabelledby creates an aria-labelledby attribute.
func AriaSelected ¶
AriaSelected creates an aria-selected attribute.
func Attr ¶
Attr creates an arbitrary attribute with the given name and value. Use this for attributes not covered by specific helper functions, such as SVG attributes or custom attributes.
func Autocomplete ¶
Autocomplete creates an autocomplete attribute.
func ContentEditable ¶
ContentEditable creates a contenteditable attribute.
func Crossorigin ¶
Crossorigin creates a crossorigin attribute.
func Formaction ¶
Formaction creates a formaction attribute.
func Formenctype ¶
Formenctype creates a formenctype attribute.
func Formmethod ¶
Formmethod creates a formmethod attribute.
func Formnovalidate ¶
func Formnovalidate() Attribute
Formnovalidate creates a formnovalidate boolean attribute.
func Formtarget ¶
Formtarget creates a formtarget attribute.
func HtmxBoost ¶
func HtmxBoost() Attribute
HtmxBoost creates an hx-boost attribute for progressive enhancement.
func HtmxConfirm ¶
HtmxConfirm creates an hx-confirm attribute for confirmation dialogs.
func HtmxDelete ¶
HtmxDelete creates an hx-delete attribute for HTMX DELETE requests.
func HtmxHeaders ¶
HtmxHeaders creates an hx-headers attribute for custom headers.
func HtmxInclude ¶
HtmxInclude creates an hx-include attribute to include additional form data.
func HtmxIndicator ¶
HtmxIndicator creates an hx-indicator attribute to show loading indicators.
func HtmxLoadingClass ¶
func HtmxLoadingClass() Attribute
HtmxLoadingClass creates an htmx-indicator class for loading states.
func HtmxPreserve ¶
func HtmxPreserve() Attribute
HtmxPreserve creates an hx-preserve attribute to preserve elements during swaps.
func HtmxPrompt ¶
HtmxPrompt creates an hx-prompt attribute for user input prompts.
func HtmxPushURL ¶
HtmxPushURL creates an hx-push-url attribute for browser history.
func HtmxReplaceURL ¶
HtmxReplaceURL creates an hx-replace-url attribute to replace current URL.
func HtmxSwapOOB ¶
HtmxSwapOOB creates an hx-swap-oob attribute for out-of-band swaps.
func HtmxTarget ¶
HtmxTarget creates an hx-target attribute to specify where to place response.
func HtmxTrigger ¶
HtmxTrigger creates an hx-trigger attribute to specify what triggers the request.
func HxIndicator ¶
HxIndicator is an alias for HtmxIndicator
func Placeholder ¶
Placeholder creates a placeholder attribute.
func Referrerpolicy ¶
Referrerpolicy creates a referrerpolicy attribute.
func StrokeWidth ¶
StrokeWidth creates a stroke-width attribute for SVG elements.
type BooleanAttribute ¶
type BooleanAttribute struct {
Name string
}
BooleanAttribute represents a boolean HTML attribute.
func (BooleanAttribute) Apply ¶
func (ba BooleanAttribute) Apply(element *Element)
Apply adds the boolean attribute to an element.
type Builder ¶
type Builder struct{}
Builder provides methods for creating HTML elements with the Minty pattern.
func (*Builder) Blockquote ¶
Blockquote creates a <blockquote> element.
type DarkMode ¶
type DarkMode struct {
// contains filtered or unexported fields
}
DarkMode provides framework-agnostic dark mode support for minty applications. It generates the necessary JavaScript for theme detection, persistence, and toggling.
Supported frameworks:
- Tailwind CSS (class="dark" on html element)
- Bootstrap 5.3+ (data-bs-theme="dark" attribute)
- Custom CSS variable schemes (any data-* attribute)
Not supported (by design):
- MUI, Vuetify, Angular Material (require framework-specific state management)
See DARKMODE.md for architectural rationale.
func DarkModeAttr ¶
func DarkModeAttr(attrName, lightValue, darkValue string, opts ...DarkModeOption) *DarkMode
DarkModeAttr creates a dark mode handler using a custom attribute. Use this for CSS variable schemes that respond to data attributes.
Example for custom CSS:
:root[data-theme="dark"] { --bg: #1a1a1a; --text: #fff; }
:root[data-theme="light"] { --bg: #fff; --text: #1a1a1a; }
darkMode := mi.DarkModeAttr("data-theme", "light", "dark")
func DarkModeBootstrap ¶
func DarkModeBootstrap(opts ...DarkModeOption) *DarkMode
DarkModeBootstrap creates a dark mode handler configured for Bootstrap 5.3+. Bootstrap uses data-bs-theme="dark" attribute on the html element.
func DarkModeTailwind ¶
func DarkModeTailwind(opts ...DarkModeOption) *DarkMode
DarkModeTailwind creates a dark mode handler configured for Tailwind CSS. Tailwind uses class="dark" on the html element.
func NewDarkMode ¶
func NewDarkMode(opts ...DarkModeOption) *DarkMode
NewDarkMode creates a dark mode handler with Tailwind defaults. Use DarkModeTailwind(), DarkModeBootstrap(), or DarkModeAttr() for framework-specific presets.
func (*DarkMode) Script ¶
Script generates the JavaScript for dark mode initialisation. Place this in the <head> to prevent flash of wrong theme on page load.
Example:
b.Head(
b.Script(mi.Raw(`tailwind.config = { darkMode: 'class' }`)),
darkMode.Script(b),
)
func (*DarkMode) ScriptRaw ¶
ScriptRaw returns the raw JavaScript string without wrapping in a script tag. Useful when combining with other scripts.
type DarkModeConfig ¶
type DarkModeConfig struct {
// Toggle mechanism
UseClass bool // true = toggle class, false = toggle attribute
ClassName string // Class name to toggle (e.g., "dark")
AttrName string // Attribute name (e.g., "data-bs-theme")
LightValue string // Attribute value for light mode
DarkValue string // Attribute value for dark mode
// Persistence
StorageKey string // localStorage key, default "theme"
Default string // "system", "light", or "dark"
// UI
LightIcon string // Icon shown when in light mode (clicking goes dark)
DarkIcon string // Icon shown when in dark mode (clicking goes light)
IconID string // ID for the icon element
// Output
Minify bool // Minify generated JavaScript
}
DarkModeConfig holds configuration for dark mode behaviour.
type DarkModeOption ¶
type DarkModeOption func(*DarkModeConfig)
DarkModeOption configures a DarkMode instance.
func DarkModeDefault ¶
func DarkModeDefault(d string) DarkModeOption
DarkModeDefault sets the default theme when no preference is stored. Valid values: "system" (follows OS preference), "light", "dark"
func DarkModeIconID ¶
func DarkModeIconID(id string) DarkModeOption
DarkModeIconID sets the ID for the icon element inside the toggle button.
func DarkModeIcons ¶
func DarkModeIcons(lightIcon, darkIcon string) DarkModeOption
DarkModeIcons sets the icons for the toggle button. lightIcon is shown when in light mode (clicking switches to dark). darkIcon is shown when in dark mode (clicking switches to light).
func DarkModeMinify ¶
func DarkModeMinify() DarkModeOption
DarkModeMinify enables JavaScript minification.
func DarkModeSVGIcons ¶
func DarkModeSVGIcons() DarkModeOption
DarkModeSVGIcons uses Heroicon SVG icons instead of emoji. This provides better cross-platform consistency.
func DarkModeStorage ¶
func DarkModeStorage(key string) DarkModeOption
DarkModeStorage sets the localStorage key for persistence.
type FilterOption ¶
type Fragment ¶
type Fragment struct {
Children []Node
}
Fragment represents a collection of nodes without a wrapper element.
type H ¶
H represents a template function that generates HTML.
func ArticleLayout ¶
ArticleLayout creates a layout optimized for article content.
func AutoRefresh ¶
AutoRefresh creates an element that automatically refreshes via HTMX.
func BreadcrumbNavigation ¶
BreadcrumbNavigation creates a breadcrumb navigation.
func CardLayout ¶
CardLayout creates a card-style layout component.
func Document ¶
Document creates a complete HTML document structure. It takes a title string, head nodes slice, and body node.
func ErrorMessage ¶
ErrorMessage creates a styled error message.
func FlexLayout ¶
FlexLayout creates a flexbox layout container.
func FormField ¶
func FormField(label, name, fieldType, value, errorMsg string, required bool, attributes ...Attribute) H
FormField creates a form field with label, input, and error display.
func FullLayout ¶
FullLayout creates a complete HTML5 layout with semantic structure.
func GridLayout ¶
Grid creates a CSS Grid layout container.
func HTMXLoadingIndicator ¶
HTMXLoadingIndicator creates a loading indicator for HTMX requests.
func HTMXLoadingSpinner ¶
func HTMXLoadingSpinner() H
HTMXLoadingSpinner creates a CSS-based loading spinner.
func IfElse ¶
IfElse returns the trueTemplate if condition is true, otherwise returns falseTemplate.
func InfiniteScroll ¶
InfiniteScroll creates an element that triggers infinite scroll loading.
func Layout ¶
Layout creates a simple HTML page layout with title and content. This is the basic layout pattern for Week 2.
func LayoutWithCSS ¶
LayoutWithCSS creates a layout with custom CSS styles.
func LayoutWithMeta ¶
LayoutWithMeta creates a layout with custom meta tags.
func LiveSearch ¶
LiveSearch creates a live search input with HTMX.
func ModalLayout ¶
ModalLayout creates a modal dialog layout.
func Notification ¶
Notification creates a notification that can be dismissed.
func Paginate ¶
func Paginate[T any](items []T, page, perPage int, renderer func([]T, PaginationInfo) H) H
func ProgressBar ¶
ProgressBar creates a progress bar that updates via HTMX.
func SearchWithFilters ¶
func SearchWithFilters(searchURL string, filters []FilterOption) H
SearchWithFilters creates a search interface with filter options.
func SectionLayout ¶
Section creates a semantic section with optional heading.
func SelectField ¶
func SelectField(label, name, value, errorMsg string, required bool, options []SelectOption) H
SelectField creates a select field with options.
func SuccessMessage ¶
SuccessMessage creates a styled success message.
func TabContainer ¶
func TextareaField ¶
TextareaField creates a textarea field with label and error display.
func VisuallyHidden ¶
VisuallyHidden creates content that's hidden visually but available to screen readers.
func WarningMessage ¶
WarningMessage creates a styled warning message.
type Node ¶
Node represents any HTML content that can be rendered.
func Each ¶
Each renders a slice of items using the provided renderer function. Returns a slice of Nodes that can be spread into parent elements.
func EachWithIndex ¶
EachWithIndex renders a slice of items with index using the provided renderer function.
func GroupBy ¶
func GroupBy[T any, K comparable](items []T, keyFn func(T) K, renderer func(K, []T) H) []Node
GroupBy groups items by a key function and renders each group.
func IfTruthy ¶ added in v0.1.0
IfTruthy renders content only if the value is truthy (JavaScript-like). This is useful for conditionally showing content based on map values without explicit nil/empty checks.
Usage:
mi.IfTruthy(post["category"], func(b *mi.Builder) mi.Node {
return b.Span(mi.Class("category"), mi.Str(post, "category"))
})
func IfTruthyElse ¶ added in v0.1.0
IfTruthyElse renders 'then' if value is truthy, otherwise renders 'els'.
Usage:
mi.IfTruthyElse(user["avatar"],
func(b *mi.Builder) mi.Node { return b.Img(mi.Src(mi.Str(user, "avatar"))) },
func(b *mi.Builder) mi.Node { return b.Span("No avatar") },
)
func NewFragment ¶
NewFragment creates a fragment containing the given nodes.
type PaginationInfo ¶
Paginate renders items with pagination support.
type Predicate ¶ added in v0.1.0
type Predicate func(interface{}) bool
Predicate is a function that tests if an item matches a condition.
func And ¶ added in v0.1.0
And combines multiple predicates with AND logic.
Usage:
result := mi.Filter(posts, mi.And(
mi.Where("status", "published"),
mi.WhereGt("views", 100),
))
func Or ¶ added in v0.1.0
Or combines multiple predicates with OR logic.
Usage:
result := mi.Filter(posts, mi.Or(
mi.Where("status", "published"),
mi.Where("status", "featured"),
))
func Where ¶ added in v0.1.0
Where creates a predicate that checks if a map field equals a string value.
Usage:
published := mi.Filter(posts, mi.Where("status", "published"))
func WhereContains ¶ added in v0.1.0
WhereContains creates a predicate that checks if a map field contains a substring.
Usage:
goPosts := mi.Filter(posts, mi.WhereContains("title", "Go"))
func WhereContainsI ¶ added in v0.1.0
WhereContainsI creates a case-insensitive contains predicate.
func WhereGt ¶ added in v0.1.0
WhereGt creates a predicate that checks if a map field is > an int value.
Usage:
popular := mi.Filter(posts, mi.WhereGt("views", 1000))
func WhereGte ¶ added in v0.1.0
WhereGte creates a predicate that checks if a map field is >= an int value.
func WhereLt ¶ added in v0.1.0
WhereLt creates a predicate that checks if a map field is < an int value.
func WhereNot ¶ added in v0.1.0
WhereNot creates a predicate that checks if a map field does NOT equal a value.
Usage:
notDraft := mi.Filter(posts, mi.WhereNot("status", "draft"))
func WhereTruthy ¶ added in v0.1.0
WhereTruthy creates a predicate that checks if a map field is truthy.
Usage:
withCategory := mi.Filter(posts, mi.WhereTruthy("category"))
type RawNode ¶
type RawNode struct {
Content string
}
RawNode represents unescaped HTML content (use with caution).
type SelectOption ¶
SelectOption represents an option in a select field.
type SortField ¶ added in v0.1.0
SortByMulti sorts by multiple fields in order of priority. Each field can have its own sort direction.
Usage:
sorted := mi.SortByMulti(posts,
mi.SortField{"status", mi.Asc},
mi.SortField{"date", mi.Desc},
)
type StringAttribute ¶
StringAttribute represents an attribute with a string value.
func (StringAttribute) Apply ¶
func (sa StringAttribute) Apply(element *Element)
Apply adds the string attribute to an element.
type ValidationError ¶
ValidationError represents a form validation error.
func ValidateEmail ¶
func ValidateEmail(value, fieldName string) *ValidationError
ValidateEmail checks if a value is a valid email format.
func ValidateMaxLength ¶
func ValidateMaxLength(value, fieldName string, maxLen int) *ValidationError
ValidateMaxLength checks maximum length.
func ValidateMinLength ¶
func ValidateMinLength(value, fieldName string, minLen int) *ValidationError
ValidateMinLength checks minimum length.
func ValidateRequired ¶
func ValidateRequired(value, fieldName string) *ValidationError
ValidateRequired checks if a field is not empty.
type ValidationResult ¶
type ValidationResult struct {
IsValid bool
Errors []ValidationError
}
ValidationResult represents the result of form validation.
func (*ValidationResult) AddError ¶
func (vr *ValidationResult) AddError(field, message string)
AddError adds a validation error to the result.
func (*ValidationResult) GetError ¶
func (vr *ValidationResult) GetError(field string) string
GetError returns the first error for a specific field, or empty string if none.
func (*ValidationResult) HasError ¶
func (vr *ValidationResult) HasError(field string) bool
HasError checks if there's an error for a specific field.
type WhenCase ¶
type WhenCase[T comparable] struct { Value T Template H }
When provides multiple condition/template pairs (like a switch statement).
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
domains
|
|
|
mintycart
Package mintycart provides pure e-commerce domain logic for the Minty System.
|
Package mintycart provides pure e-commerce domain logic for the Minty System. |
|
mintyfin
Package mintyfin provides pure finance domain logic for the Minty System.
|
Package mintyfin provides pure finance domain logic for the Minty System. |
|
mintymove
Package mintymove provides pure logistics and movement domain logic for the Minty System.
|
Package mintymove provides pure logistics and movement domain logic for the Minty System. |
|
Package mintydyn provides dynamic UI components with automatic pattern detection for the Minty HTML generation library.
|
Package mintydyn provides dynamic UI components with automatic pattern detection for the Minty HTML generation library. |
|
Package mintyex provides UI helper functions for the Minty System.
|
Package mintyex provides UI helper functions for the Minty System. |
|
Package mintytypes provides pure business types, interfaces, and utilities.
|
Package mintytypes provides pure business types, interfaces, and utilities. |
|
Package mintyui provides theme-based UI components and utilities for building consistent user interfaces across domains.
|
Package mintyui provides theme-based UI components and utilities for building consistent user interfaces across domains. |
|
presentation
|
|
|
mintycartui
Package mintycartui provides UI presentation adapters for the mintycart domain.
|
Package mintycartui provides UI presentation adapters for the mintycart domain. |
|
mintyfinui
Package mintyfinui provides UI presentation adapters for the mintyfin domain.
|
Package mintyfinui provides UI presentation adapters for the mintyfin domain. |
|
mintymoveui
Package mintymoveui provides UI presentation adapters for the mintymove domain.
|
Package mintymoveui provides UI presentation adapters for the mintymove domain. |
|
themes
|
|
|
bootstrap
Package bootstrap provides a Bootstrap 5 theme implementation for mintyui
|
Package bootstrap provides a Bootstrap 5 theme implementation for mintyui |
|
bulma
Package bulma provides a Bulma CSS theme implementation for mintyui
|
Package bulma provides a Bulma CSS theme implementation for mintyui |
|
material
Package material provides a Material Design theme implementation for mintyui
|
Package material provides a Material Design theme implementation for mintyui |
|
tailwind
Package tailwind provides a Tailwind CSS theme implementation for mintyui
|
Package tailwind provides a Tailwind CSS theme implementation for mintyui |