Documentation ¶
Index ¶
- Constants
- Variables
- func ForEach[T ElementConstraint](s T, f func(int, T))
- func NewBuffer(bufLen int, panicOnError ...bool) *elementBuffer
- type Attr
- type Document
- func (d *Document) Body() *Element
- func (d *Document) Buffer() *elementBuffer
- func (d *Document) Bytes() []byte
- func (d *Document) GetElementByID(id string) *Element
- func (d *Document) GetElementsByClassName(className string) []*Element
- func (d *Document) GetElementsByTagName(tagName string) []*Element
- func (d *Document) Head() *Element
- func (d *Document) Len() int
- func (d *Document) Render(w io.Writer) error
- func (d *Document) Root() *Element
- func (d *Document) String() string
- type Element
- func (e *Element) A(href string) *Element
- func (e *Element) Abbr() *Element
- func (e *Element) Add(children ...*Element) *Element
- func (e *Element) Address() *Element
- func (e *Element) Area() *Element
- func (e *Element) Article() *Element
- func (e *Element) Aside() *Element
- func (e *Element) AsyncForEach(fn func(*Element) bool)
- func (e *Element) Attr(k string, v ...string) *Element
- func (e *Element) AttrBool(k string, v bool) *Element
- func (e *Element) AttrSemiCol(k string, v ...string) *Element
- func (e *Element) Audio() *Element
- func (e *Element) B() *Element
- func (e *Element) Bdi() *Element
- func (e *Element) Bdo() *Element
- func (e *Element) Blockquote() *Element
- func (e *Element) Body() *Element
- func (e *Element) Br() *Element
- func (e *Element) Button() *Element
- func (e *Element) Canvas() *Element
- func (e *Element) Caption() *Element
- func (e *Element) Cite() *Element
- func (e *Element) Class(class ...string) *Element
- func (e *Element) Code() *Element
- func (e *Element) Col() *Element
- func (e *Element) Colgroup() *Element
- func (e *Element) Command() *Element
- func (e *Element) Datalist() *Element
- func (e *Element) Dd() *Element
- func (e *Element) Del() *Element
- func (e *Element) DelAttr(k string) *Element
- func (e *Element) Details() *Element
- func (e *Element) Dfn() *Element
- func (e *Element) Div() *Element
- func (e *Element) Dl() *Element
- func (e *Element) Dt() *Element
- func (e *Element) Element(elementType string) *Element
- func (e *Element) Em() *Element
- func (e *Element) Embed() *Element
- func (e *Element) Fieldset() *Element
- func (e *Element) Figcaption() *Element
- func (e *Element) Figure() *Element
- func (e *Element) Footer() *Element
- func (e *Element) For(start, iterations, step int, f func(int) *Element) *Element
- func (e *Element) ForEach(f func(int, *Element)) *Element
- func (e *Element) Form() *Element
- func (e *Element) GetAttr(k string) (stringsAttr []string, boolAttr, found bool)
- func (e *Element) GetElementByElement(elem *Element) *Element
- func (e *Element) GetElementByID(id string) *Element
- func (e *Element) GetElementsByClassName(className string) []*Element
- func (e *Element) GetElementsByTagName(tagName string) []*Element
- func (e *Element) H1() *Element
- func (e *Element) H2() *Element
- func (e *Element) H3() *Element
- func (e *Element) H4() *Element
- func (e *Element) H5() *Element
- func (e *Element) H6() *Element
- func (e *Element) HTML(s string) *Element
- func (e *Element) Header() *Element
- func (e *Element) Hr() *RestrainedElement
- func (e *Element) I() *Element
- func (e *Element) ID(id string) *Element
- func (e *Element) Iframe() *Element
- func (e *Element) Img(src string, alt ...string) *Element
- func (e *Element) Input() *RestrainedElement
- func (e *Element) Ins() *Element
- func (e *Element) Kbd() *Element
- func (e *Element) Keygen() *Element
- func (e *Element) Label() *Element
- func (e *Element) Legend() *Element
- func (e *Element) Main() *Element
- func (e *Element) Map() *Element
- func (e *Element) Mark() *Element
- func (e *Element) Menu() *Element
- func (e *Element) MetaCharset(v string) *RestrainedElement
- func (e *Element) MetaTag(name string, content string) *RestrainedElement
- func (e *Element) Meter() *Element
- func (e *Element) Nav() *Element
- func (e *Element) NextChild() *Element
- func (e *Element) NoClose() *Element
- func (e *Element) Object() *Element
- func (e *Element) Ol() *HTMLLIST
- func (e *Element) Optgroup() *Element
- func (e *Element) Output() *Element
- func (e *Element) P() *Element
- func (e *Element) Param() *Element
- func (e *Element) Pre() *Element
- func (e *Element) PrevChild() *Element
- func (e *Element) Progress() *Element
- func (e *Element) Q() *Element
- func (e *Element) Rp() *Element
- func (e *Element) Rt() *Element
- func (e *Element) Ruby() *Element
- func (e *Element) S() *Element
- func (e *Element) Samp() *Element
- func (e *Element) Section() *Element
- func (e *Element) Select(name string) *HTMLSELECT
- func (e *Element) Small() *Element
- func (e *Element) Source() *Element
- func (e *Element) Span() *Element
- func (e *Element) String() string
- func (e *Element) Strong() *Element
- func (e *Element) Sub() *Element
- func (e *Element) Summary() *Element
- func (e *Element) Sup() *Element
- func (e *Element) Table() *HTMLTABLE
- func (e *Element) Text(s string) *Element
- func (e *Element) Textarea() *Element
- func (e *Element) Textf(format string, a ...interface{}) *Element
- func (e *Element) Time() *Element
- func (e *Element) Track() *Element
- func (e *Element) U() *Element
- func (e *Element) Ul() *HTMLLIST
- func (e *Element) Var() *Element
- func (e *Element) Video() *Element
- func (e *Element) Wbr() *Element
- type ElementConstraint
- type HTMLLIST
- type HTMLSELECT
- type HTMLTABLE
- type RestrainedElement
Constants ¶
const DOCTYPE string = "<!DOCTYPE html>\r\n"
Default document type declaration
Variables ¶
var ErrOverflow = errors.New("elementBuffer: buffer overflow")
Overflows are not recoverable, and will cause a panic.
Functions ¶
func ForEach ¶
func ForEach[T ElementConstraint](s T, f func(int, T))
Types ¶
type Attr ¶
type Attr[T any] struct { Key string // The key of the attribute. Value T // The value of the attribute. Delimiter string // The delimiter to use when rendering the value. // contains filtered or unexported fields }
Attr represents an attribute of an element.
func NewBoolAttr ¶
NewBoolAttr creates a new boolean attribute.
func NewStringAttr ¶
NewStringAttr creates a new string attribute.
type Document ¶
type Document struct {
// contains filtered or unexported fields
}
Document represents an HTML document
It is a wrapper around a predefined HTML() element.
func (*Document) Buffer ¶
func (d *Document) Buffer() *elementBuffer
Buffer returns the document as an elementBuffer
func (*Document) GetElementByID ¶
Get an element by its ID.
func (*Document) GetElementsByClassName ¶
Get elements by their class name.
func (*Document) GetElementsByTagName ¶
Get elements by their tag name.
type Element ¶
type Element struct { Type string // The type of element, e.g. "div", "span", "input", etc. InnerText string // The inner text of the element, if any. AutoClose bool // Whether or not the element is self closing. Children []*Element // List of child elements. BoolAttrs []Attr[bool] // List of boolean attributes. SemicolAttrs []Attr[[]string] // List of attributes that are separated by semicolons. Attrs []Attr[[]string] // List of attributes that are separated by spaces. // contains filtered or unexported fields }
Element is a single HTML element.
func Add ¶
func Add[T1, T2 ElementConstraint](elem T1, children ...T2) *Element
Add adds a child to the element.
func UnRestrain ¶
func UnRestrain[T ElementConstraint](e T) *Element
func (*Element) AsyncForEach ¶
Loop over all inner elements recursively asynchronously.
func (*Element) AttrSemiCol ¶
AttrSemiCol adds an attribute to the element.
func (*Element) Blockquote ¶
func (*Element) Class ¶
Class sets the class attribute of the element. If the element already has a class attribute, it will be overwritten. If the class is an empty string, the class attribute will be removed.
func (*Element) Figcaption ¶
func (*Element) GetElementByElement ¶
Get an element by another element!
func (*Element) GetElementByID ¶
Get inner elements by ID
func (*Element) GetElementsByClassName ¶
Get inner elements by classname
func (*Element) GetElementsByTagName ¶
Get inner elements by tag name
func (*Element) HTML ¶
Writes raw HTML to the element.
Returns the element on which this method is called.
func (*Element) Hr ¶
func (e *Element) Hr() *RestrainedElement
func (*Element) ID ¶
ID sets the id attribute of the element. If the element already has an id attribute, it will be overwritten. If the id is an empty string, the id attribute will be removed.
func (*Element) Input ¶
func (e *Element) Input() *RestrainedElement
TYPE -> (NAME, ID) -> PLACEHOLDER -> VALUE
func (*Element) MetaCharset ¶
func (e *Element) MetaCharset(v string) *RestrainedElement
func (*Element) NextChild ¶
NextChild returns the next child element of the current elements parent. If the current element is the last child, nil is returned.
func (*Element) PrevChild ¶
PrevChild returns the previous child element of the current elements parent. If the current element is the first child, nil is returned.
func (*Element) Select ¶
func (e *Element) Select(name string) *HTMLSELECT
Takes the text to be displayed and a list of items to be selected from
func (*Element) Text ¶
Write text to the element.
Returns the element on which this method is called.
type ElementConstraint ¶
type ElementConstraint interface { *Element | *HTMLLIST | *HTMLSELECT | *HTMLTABLE | *RestrainedElement }
type HTMLSELECT ¶
type HTMLSELECT Element
func (*HTMLSELECT) Option ¶
func (e *HTMLSELECT) Option(value, text string) *Element
type RestrainedElement ¶
type RestrainedElement Element
func Restrain ¶
func Restrain[T ElementConstraint](e T) *RestrainedElement
func (*RestrainedElement) Attr ¶
func (e *RestrainedElement) Attr(k string, v ...string) *RestrainedElement
This method is used to set an attribute on an element. It returns the element for inlining purposes.
func (*RestrainedElement) AttrBool ¶
func (e *RestrainedElement) AttrBool(k string, v bool) *RestrainedElement
This method is used to set a boolean attribute on an element. It returns the element for inlining purposes.
func (*RestrainedElement) AttrSemicol ¶
func (e *RestrainedElement) AttrSemicol(k string, v ...string) *RestrainedElement
This method is used to set an attribute on an element. It returns the element for inlining purposes.