ds

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package ds provides typed helpers for Datastar HTML attributes.

Datastar's parameterized plugins use a colon separator (e.g. data-on:click), NOT a hyphen (data-on-click). A hyphen is silently ignored as an unknown plugin. This package makes that mistake impossible by construction.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Attr

func Attr(name, expr string) templ.Attributes

Attr returns a data-attr:<name> attribute.

func Bind

func Bind(signal string) templ.Attributes

Bind returns a data-bind:<signal> attribute.

func Class

func Class(value string) templ.Attributes

Class returns a data-class attribute (object syntax).

func ClassToggle

func ClassToggle(name, expr string) templ.Attributes

ClassToggle returns a data-class:<name> attribute (single class toggle).

func Computed

func Computed(name, expr string) templ.Attributes

Computed returns a data-computed:<name> attribute.

func Delete

func Delete(url string, opts ...ActionOption) string

Delete returns a @delete('url') expression with the CSRF token header.

func DeleteOnce

func DeleteOnce(url string) string

DeleteOnce returns a @delete('url') expression with CSRF but without retries.

func Effect

func Effect(expr string) templ.Attributes

Effect returns a data-effect attribute.

func Get

func Get(url string, opts ...ActionOption) string

Get returns a @get('url') expression.

ds.Get("/api/data")                // → @get('/api/data')
ds.Get("/api/data", ds.WithRetries(3)) // → @get('/api/data', {retryMaxCount: 3})

func GetOnce

func GetOnce(url string) string

GetOnce returns a @get('url') expression without retries.

ds.GetOnce("/api/data") // → @get('/api/data', {retryMaxCount: 0})

func Indicator

func Indicator(name string) templ.Attributes

Indicator returns a data-indicator:<name> attribute.

func Init

func Init(expr string) templ.Attributes

Init returns a data-init attribute.

func Merge

func Merge(attrs ...templ.Attributes) templ.Attributes

Merge combines multiple templ.Attributes into one. Later values overwrite earlier ones for the same key.

func On

func On(event, expr string) templ.Attributes

On returns a data-on:<event> attribute.

ds.On("click", expr) → {"data-on:click": expr}

func OnClick

func OnClick(expr string) templ.Attributes

OnClick is shorthand for On("click", expr).

func Patch

func Patch(url string, opts ...ActionOption) string

Patch returns a @patch('url') expression with the CSRF token header.

func PatchOnce

func PatchOnce(url string) string

PatchOnce returns a @patch('url') expression with CSRF but without retries.

func Post

func Post(url string, opts ...ActionOption) string

Post returns a @post('url') expression with the CSRF token header.

ds.Post("/api/submit")                // → @post('/api/submit', {headers: {…}})
ds.Post("/api/submit", ds.WithRetries(5)) // → @post('/api/submit', {headers: {…}, retryMaxCount: 5})

func PostOnce

func PostOnce(url string) string

PostOnce returns a @post('url') expression with CSRF but without retries.

func Put

func Put(url string, opts ...ActionOption) string

Put returns a @put('url') expression with the CSRF token header.

func PutOnce

func PutOnce(url string) string

PutOnce returns a @put('url') expression with CSRF but without retries.

func Ref

func Ref(name string) templ.Attributes

Ref returns a data-ref:<name> attribute.

func Show

func Show(expr string) templ.Attributes

Show returns a data-show attribute.

func Signals

func Signals(value string) templ.Attributes

Signals returns a data-signals attribute.

func Style

func Style(prop, expr string) templ.Attributes

Style returns a data-style:<prop> attribute.

func Text

func Text(expr string) templ.Attributes

Text returns a data-text attribute.

Types

type ActionOption

type ActionOption func(*actionConfig)

ActionOption customizes a backend action expression (@get, @post, etc.).

func WithContentType

func WithContentType(ct string) ActionOption

WithContentType sets the content type for the action. Use "form" to send multipart/form-data (file uploads).

func WithRetries

func WithRetries(n int) ActionOption

WithRetries sets the maximum number of retry attempts. Use 0 to disable retries entirely.

Jump to

Keyboard shortcuts

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