htmlg

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2023 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Send added in v0.1.6

func Send(w http.ResponseWriter, statusCode int, s string) (int, error)

Send writes a HTML string to the given response writer. It sets the content-type header to "text/html; charset=utf-8" and writes the given status code.

func SendStringer added in v0.1.6

func SendStringer(w http.ResponseWriter, statusCode int, s Stringer) (int, error)

SendStringer renders and writes a Stringer to the given response writer. It sets the content-type header to "text/html; charset=utf-8" and writes the given status code.

Types

type Element added in v0.1.6

type Element struct {
	// contains filtered or unexported fields
}

Element represents a HTML element with a tag and optional attribute and inner HTML. Use Create to instanciate an element.

func Create added in v0.1.6

func Create(t string, opts ...Modifier) *Element

Create instanciates a new Element with the given tag.

func (*Element) Apply added in v0.1.6

func (e *Element) Apply(opts ...Modifier) *Element

Apply mutates this element using the given modifier(s).

func (*Element) HTMLString added in v0.1.6

func (e *Element) HTMLString() string

HTMLString returns a valid HTML representation of this element.

func (*Element) Tag added in v0.1.6

func (e *Element) Tag() string

type Fragment added in v0.0.16

type Fragment []Stringer

Fragment represents a group of HTMLStringers. This can be several HTML sibling elements.

func NewFragment added in v0.0.16

func NewFragment(siblings ...Stringer) Fragment

NewFragment returns a fragment made of the given HTMLStringers.

func (Fragment) HTMLString added in v0.0.16

func (f Fragment) HTMLString() string

HTMLString returns the concatenated underyling HTMLStringers.

type Modifier added in v0.1.6

type Modifier func(*Element)

Modifier performs a mutation on an element. Eg. Changing its internal state (for ex: adding an attribute)

func AddChild added in v0.1.6

func AddChild(s ...Stringer) Modifier

func SetAttr added in v0.1.6

func SetAttr(newAttr [2]string) Modifier

func SetAttrs added in v0.1.6

func SetAttrs(newAttrs ...[2]string) Modifier

func SetTag added in v0.1.6

func SetTag(t string) Modifier

func Style added in v0.1.6

func Style(d ...cssg.Decl) Modifier

Sets the inline style of the element to the given CSS declarations.

func WithString added in v0.1.6

func WithString(s string) Modifier

func WithText added in v0.1.6

func WithText(lines ...string) Modifier

func Wrap added in v0.1.6

func Wrap(s ...Stringer) Modifier

type String added in v0.1.6

type String string

String represents a literal HTML string.

func Text added in v0.1.6

func Text(s ...string) String

Text returns an Stringer that returns given strings with <br> tags in between them.

func (String) HTMLString added in v0.1.6

func (s String) HTMLString() string

HTMLString returns the underlying string without modification.

type Stringer added in v0.1.6

type Stringer interface {
	HTMLString() string
}

Stringer can generate a valid HTML string.

Jump to

Keyboard shortcuts

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