blocks

package
v1.6.8 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2024 License: GPL-2.0 Imports: 34 Imported by: 0

Documentation

Overview

templ: version: v0.2.707

Index

Constants

This section is empty.

Variables

View Source
var (
	AppConfig *apps.AppConfig
)
View Source
var (
	JSContext = telepath.NewContext()
)

Functions

func NewAppConfig

func NewAppConfig() *apps.AppConfig

func RenderBlock

func RenderBlock(w io.Writer, block Block, value any, context ctx.Context) error

func RenderBlockForm

func RenderBlockForm(w io.Writer, widget *BlockWidget, ctx *BlockContext, errors []error) error

func RenderBlockWidget

func RenderBlockWidget(w io.Writer, widget *BlockWidget, blockCtx *BlockContext, errors []error) templ.Component

Types

type BaseBlock

type BaseBlock struct {
	Name_      string
	Template   string
	FormField  fields.Field
	Validators []func(interface{}) error
	Default    func() interface{}

	LabelFunc func() string
	HelpFunc  func() string
}

func NewBaseBlock

func NewBaseBlock(opts ...OptFunc[*BaseBlock]) *BaseBlock

func (*BaseBlock) Adapter

func (b *BaseBlock) Adapter() telepath.Adapter

func (*BaseBlock) Clean

func (b *BaseBlock) Clean(value interface{}) (interface{}, error)

func (*BaseBlock) Field

func (b *BaseBlock) Field() fields.Field

func (*BaseBlock) FormContext

func (b *BaseBlock) FormContext(name string, value interface{}, context ctx.Context) *BlockContext

func (*BaseBlock) GetDefault

func (b *BaseBlock) GetDefault() interface{}

func (*BaseBlock) HelpText

func (b *BaseBlock) HelpText() string

func (*BaseBlock) Label

func (b *BaseBlock) Label() string

func (*BaseBlock) Media

func (b *BaseBlock) Media() media.Media

func (*BaseBlock) Name

func (b *BaseBlock) Name() string

func (*BaseBlock) Render

func (b *BaseBlock) Render(w io.Writer, value interface{}, context ctx.Context) error

func (*BaseBlock) RenderForm

func (b *BaseBlock) RenderForm(w io.Writer, id, name string, value interface{}, errors []error, context ctx.Context) error

func (*BaseBlock) SetField

func (b *BaseBlock) SetField(field fields.Field)

func (*BaseBlock) SetName

func (b *BaseBlock) SetName(name string)

func (*BaseBlock) Validate

func (b *BaseBlock) Validate(value interface{}) []error

func (*BaseBlock) ValueFromDataDict

func (b *BaseBlock) ValueFromDataDict(data url.Values, files map[string][]filesystem.FileHeader, name string) (interface{}, []error)

func (*BaseBlock) ValueOmittedFromData

func (b *BaseBlock) ValueOmittedFromData(data url.Values, files map[string][]filesystem.FileHeader, name string) bool

func (*BaseBlock) ValueToForm

func (b *BaseBlock) ValueToForm(value interface{}) interface{}

func (*BaseBlock) ValueToGo

func (b *BaseBlock) ValueToGo(value interface{}) (interface{}, error)

type BaseBlockValidationError

type BaseBlockValidationError[T comparable] struct {
	Errors         map[T][]error
	NonBlockErrors []error
}

func NewBlockErrors

func NewBlockErrors[T comparable](errors ...error) *BaseBlockValidationError[T]

func (*BaseBlockValidationError[T]) AddError

func (m *BaseBlockValidationError[T]) AddError(key T, err ...error) *BaseBlockValidationError[T]

func (*BaseBlockValidationError[T]) AddNonBlockError

func (m *BaseBlockValidationError[T]) AddNonBlockError(err error)

func (*BaseBlockValidationError[T]) Error

func (m *BaseBlockValidationError[T]) Error() string

func (*BaseBlockValidationError[T]) Get

func (m *BaseBlockValidationError[T]) Get(key T) []error

func (*BaseBlockValidationError[T]) HasErrors

func (m *BaseBlockValidationError[T]) HasErrors() bool

func (*BaseBlockValidationError[T]) Len

func (m *BaseBlockValidationError[T]) Len() int

func (*BaseBlockValidationError[T]) MarshalJSON

func (m *BaseBlockValidationError[T]) MarshalJSON() ([]byte, error)

type Block

type Block interface {
	Name() string
	SetName(name string)
	Label() string
	HelpText() string
	Field() fields.Field
	SetField(field fields.Field)
	RenderForm(w io.Writer, id, name string, value interface{}, errors []error, context ctx.Context) error
	Render(w io.Writer, value interface{}, context ctx.Context) error
	GetDefault() interface{}
	telepath.AdapterGetter
	media.MediaDefiner
	widgets.FormValuer
	forms.Validator
	forms.Cleaner
}

type BlockContext

type BlockContext struct {
	Request_  *http.Request
	BlockDef  Block
	ID        string
	Name      string
	BlockHTML template.HTML
	Value     interface{}
	Errors    []error
	Attrs     map[string]string
	Context   ctx.Context
}

func NewBlockContext

func NewBlockContext(b Block, context ctx.Context) *BlockContext

func (*BlockContext) Get

func (bc *BlockContext) Get(name string) interface{}

func (*BlockContext) Request

func (bc *BlockContext) Request() *http.Request

func (*BlockContext) Set

func (bc *BlockContext) Set(name string, value interface{})

type BlockFormField

type BlockFormField struct {
	*fields.BaseField
	Block Block
}

func BlockField

func BlockField(block Block, opts ...func(fields.Field)) *BlockFormField

func (*BlockFormField) Clean

func (bw *BlockFormField) Clean(value interface{}) (interface{}, error)

func (*BlockFormField) Validate

func (bw *BlockFormField) Validate(value interface{}) []error

func (*BlockFormField) ValueToForm

func (bw *BlockFormField) ValueToForm(value interface{}) interface{}

func (*BlockFormField) ValueToGo

func (bw *BlockFormField) ValueToGo(value interface{}) (interface{}, error)

type BlockWidget

type BlockWidget struct {
	BlockDef Block
}

func NewBlockWidget

func NewBlockWidget(blockDef Block) *BlockWidget

func (*BlockWidget) Clean

func (bw *BlockWidget) Clean(value interface{}) (interface{}, error)

func (*BlockWidget) FormType added in v1.6.7

func (bw *BlockWidget) FormType() string

func (*BlockWidget) GetContextData

func (bw *BlockWidget) GetContextData(id, name string, value interface{}, attrs map[string]string) ctx.Context

func (*BlockWidget) Hide

func (bw *BlockWidget) Hide(hidden bool)

func (*BlockWidget) IdForLabel

func (bw *BlockWidget) IdForLabel(name string) string

func (*BlockWidget) IsHidden

func (bw *BlockWidget) IsHidden() bool

func (*BlockWidget) Media

func (bw *BlockWidget) Media() media.Media

func (*BlockWidget) Render

func (bw *BlockWidget) Render(w io.Writer, id, name string, value interface{}, attrs map[string]string) error

func (*BlockWidget) RenderWithErrors

func (bw *BlockWidget) RenderWithErrors(w io.Writer, id, name string, value interface{}, errors []error, attrs map[string]string) error

func (*BlockWidget) SetAttrs

func (bw *BlockWidget) SetAttrs(attrs map[string]string)

func (*BlockWidget) Validate

func (bw *BlockWidget) Validate(value interface{}) []error

func (*BlockWidget) ValueFromDataDict

func (bw *BlockWidget) ValueFromDataDict(data url.Values, files map[string][]filesystem.FileHeader, name string) (interface{}, []error)

func (*BlockWidget) ValueOmittedFromData

func (bw *BlockWidget) ValueOmittedFromData(data url.Values, files map[string][]filesystem.FileHeader, name string) bool

func (*BlockWidget) ValueToForm

func (bw *BlockWidget) ValueToForm(value interface{}) interface{}

func (*BlockWidget) ValueToGo

func (bw *BlockWidget) ValueToGo(value interface{}) (interface{}, error)

type FieldBlock

type FieldBlock struct {
	*BaseBlock
}

func CharBlock

func CharBlock(opts ...func(*FieldBlock)) *FieldBlock

func DateBlock

func DateBlock(opts ...func(*FieldBlock)) *FieldBlock

func DateTimeBlock

func DateTimeBlock(opts ...func(*FieldBlock)) *FieldBlock

func EmailBlock

func EmailBlock(opts ...func(*FieldBlock)) *FieldBlock

func NewFieldBlock

func NewFieldBlock(opts ...func(*FieldBlock)) *FieldBlock

func NumberBlock

func NumberBlock(opts ...func(*FieldBlock)) *FieldBlock

func PasswordBlock

func PasswordBlock(opts ...func(*FieldBlock)) *FieldBlock

func TextBlock

func TextBlock(opts ...func(*FieldBlock)) *FieldBlock

func (*FieldBlock) Adapter

func (b *FieldBlock) Adapter() telepath.Adapter

func (*FieldBlock) RenderForm

func (b *FieldBlock) RenderForm(w io.Writer, id, name string, value interface{}, errors []error, c ctx.Context) error

func (*FieldBlock) RenderHTML

func (b *FieldBlock) RenderHTML() string

func (*FieldBlock) RenderTempl

func (b *FieldBlock) RenderTempl(w io.Writer, id, name string, value interface{}, telepath string, errors []error, tplCtx ctx.Context) templ.Component

type Length

type Length interface {
	Len() int
}

type ListBlock

type ListBlock struct {
	*BaseBlock
	Child Block
	Min   int
	Max   int
}

func NewListBlock

func NewListBlock(block Block, minMax ...int) *ListBlock

func (*ListBlock) Adapter

func (m *ListBlock) Adapter() telepath.Adapter

func (*ListBlock) Clean

func (l *ListBlock) Clean(value interface{}) (interface{}, error)

func (*ListBlock) GetDefault

func (l *ListBlock) GetDefault() interface{}

func (*ListBlock) MaxNum

func (l *ListBlock) MaxNum() int

func (*ListBlock) MinNum

func (l *ListBlock) MinNum() int

func (*ListBlock) RenderForm

func (l *ListBlock) RenderForm(w io.Writer, id, name string, value interface{}, errors []error, tplCtx ctx.Context) error

func (*ListBlock) RenderTempl

func (l *ListBlock) RenderTempl(w io.Writer, id, name string, valueArr []*ListBlockValue, telepath string, listBlockErrors *BaseBlockValidationError[int], tplCtx ctx.Context) templ.Component

func (*ListBlock) Validate

func (l *ListBlock) Validate(value interface{}) []error

func (*ListBlock) ValueFromDataDict

func (l *ListBlock) ValueFromDataDict(d url.Values, files map[string][]filesystem.FileHeader, name string) (interface{}, []error)

func (*ListBlock) ValueOmittedFromData

func (b *ListBlock) ValueOmittedFromData(data url.Values, files map[string][]filesystem.FileHeader, name string) bool

func (*ListBlock) ValueToForm

func (l *ListBlock) ValueToForm(value interface{}) interface{}

func (*ListBlock) ValueToGo

func (l *ListBlock) ValueToGo(value interface{}) (interface{}, error)

type ListBlockValue

type ListBlockValue struct {
	ID    uuid.UUID   `json:"id"`
	Data  interface{} `json:"data"`
	Order int         `json:"order"`
}

type OptFunc

type OptFunc[T any] func(T)

func WithHelpText

func WithHelpText[T any](text string) OptFunc[T]

func WithLabel

func WithLabel[T any](label string) OptFunc[T]

func WithValidators

func WithValidators[T any](validators ...func(interface{}) error) OptFunc[T]

type StructBlock

type StructBlock struct {
	*BaseBlock
	Fields *orderedmap.OrderedMap[string, Block]
	ToGo   func(map[string]interface{}) (interface{}, error)
	ToForm func(interface{}) (map[string]interface{}, error)
}

func NewStructBlock

func NewStructBlock() *StructBlock

func (*StructBlock) Adapter

func (m *StructBlock) Adapter() telepath.Adapter

func (*StructBlock) AddField

func (m *StructBlock) AddField(name string, block Block)

func (*StructBlock) Clean

func (m *StructBlock) Clean(value interface{}) (interface{}, error)

func (*StructBlock) Field

func (m *StructBlock) Field() fields.Field

func (*StructBlock) GetDefault

func (m *StructBlock) GetDefault() interface{}

func (*StructBlock) Name

func (m *StructBlock) Name() string

func (*StructBlock) RenderForm

func (m *StructBlock) RenderForm(w io.Writer, id, name string, value interface{}, errors []error, tplCtx ctx.Context) error

func (*StructBlock) RenderTempl

func (b *StructBlock) RenderTempl(w io.Writer, id, name string, valueMap map[string]interface{}, telepath string, errors *BaseBlockValidationError[string], tplCtx ctx.Context) templ.Component

func (*StructBlock) SetName

func (m *StructBlock) SetName(name string)

func (*StructBlock) Validate

func (m *StructBlock) Validate(value interface{}) []error

func (*StructBlock) ValueFromDataDict

func (m *StructBlock) ValueFromDataDict(d url.Values, files map[string][]filesystem.FileHeader, name string) (interface{}, []error)

func (*StructBlock) ValueOmittedFromData

func (m *StructBlock) ValueOmittedFromData(data url.Values, files map[string][]filesystem.FileHeader, name string) bool

func (*StructBlock) ValueToForm

func (m *StructBlock) ValueToForm(value interface{}) interface{}

func (*StructBlock) ValueToGo

func (m *StructBlock) ValueToGo(value interface{}) (interface{}, error)

Jump to

Keyboard shortcuts

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