htm

package module
v2.0.0-...-1a3749f Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

README

HTM

WARNING

This is a very early alpha not ready for production use.

Sample Code

See examples/hello/main.go for a full sample.

htm.ListenAndServe("127.0.0.1:1512", h.Html(
    h.Head(
        h.Title("Hello, World"),
    ),
    h.Body(
        h.Div(htm.Text("Hello, World")),
    ),
))

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ListenAndServe

func ListenAndServe(addr string, f Fragment) error

func MakeDynamicContext

func MakeDynamicContext(ctx context.Context) (context.Context, error)

func Render

func Render(ctx context.Context, w io.Writer, frag Fragment) error

func RequestFromContext

func RequestFromContext(ctx context.Context) (*http.Request, bool)

func WalkTree

func WalkTree(ctx context.Context, frag Fragment) error

Types

type Class

type Class string

func (Class) Children

func (Class) Children(ctx context.Context) ([]Fragment, error)

Children implements Fragment.

func (Class) Render

func (c Class) Render(ctx context.Context, parent Node) error

Render implements Fragment.

type DynamicFunc

type DynamicFunc func(ctx context.Context) ([]Fragment, error)

type Fragment

type Fragment interface {
	Children(ctx context.Context) ([]Fragment, error)
	Render(ctx context.Context, parent Node) error
}

func Attr

func Attr(key string, value string) Fragment

func Dynamic

func Dynamic(handler DynamicFunc) Fragment

func NewHtmlFragment

func NewHtmlFragment(tag string, children ...Fragment) Fragment

func Route

func Route(url string, f Fragment) Fragment

type Group

type Group []Fragment

func (Group) Children

func (g Group) Children(ctx context.Context) ([]Fragment, error)

Children implements Fragment.

func (Group) Render

func (g Group) Render(ctx context.Context, parent Node) error

Render implements Fragment.

type Node

type Node interface {
	AddClass(class string) error
	AddChild(node Node) error
	AddAttribute(key string, value string) error
}

type Text

type Text string

func (Text) Children

func (Text) Children(ctx context.Context) ([]Fragment, error)

func (Text) Render

func (t Text) Render(ctx context.Context, parent Node) error

Render implements Fragment.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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