util

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package util provides utility functions for godom package, enhancing the flexibility and ease of use in creating and manipulating the DOM.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DelayedAttribute

func DelayedAttribute(attribute types.Attribute) types.Attribute

DelayedAttribute wraps the provided types.Attribute such that it renders every time the containing types.Element is rendered. This allows attributes to be dynamically determined during the rendering phase.

func DelayedElement

func DelayedElement(creator ElementCreator) types.Element

DelayedElement returns a godom.Element that is constructed immediately before rendering. This allows for dynamic adaptation of parts of the DOM between its construction and rendering phases.

func IfAttr

func IfAttr(condition bool, attribute types.Attribute) types.Attribute

IfAttr returns a godom.Attribute that is applied to the godom.Element based on the given condition. If the condition is true, the provided attribute is applied; otherwise, a no-op attribute is applied.

func IfElem

func IfElem(condition bool, element types.Element) types.Element

IfElem returns a godom.Element based on the given condition. If the condition is true, the provided element is returned; otherwise, an empty element is returned.

func Map

func Map[T any](data []T, creator func(T) types.Element) types.Element

Map takes a slice of data and a creator function that transforms each data item into a godom.Element. It returns a group of elements created from the data slice.

func RenderToString

func RenderToString(element types.Element) (string, error)

RenderToString renders a given types.Element to its string representation. This is useful when the HTML generated by godoc needs to be used in another context or module.

Types

type ElementCreator

type ElementCreator func() types.Element

ElementCreator defines a function type that creates and returns a godom.Element.

Jump to

Keyboard shortcuts

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