go.h: github.com/daaku/go.h Index | Files

package h

import "github.com/daaku/go.h"

Package h provides a HTML generation abstraction for Go. It does so by allowing you to write some verbose and often annoying looking but extremely arguably simple and idiomatic Go library to generate HTML for the purposes of rendering in web browsers.

This approach though verbose allows for building powerful abstracitons with simple looking APIs. Look at https://godoc.org/github.com/daaku/go.h?importers for some examples.

**Unstable API. Work in progress.**

Index

Package Files

extra.go h.go html.go primitives.go

Constants

const (
    Post = "post"
    Get  = "get"
)

Method names for use with Forms.

func Render Uses

func Render(ctx context.Context, h HTML) (string, error)

Render HTML as a string.

func Write Uses

func Write(ctx context.Context, w io.Writer, h HTML) (int, error)

Write HTML into a writer.

type A Uses

type A struct {
    ID     string                 `h:"attr"`
    Class  string                 `h:"attr"`
    Style  string                 `h:"attr"`
    Title  string                 `h:"attr"`
    HREF   string                 `h:"attr"`
    Target string                 `h:"attr"`
    Rel    string                 `h:"attr"`
    Inner  HTML                   `h:"inner"`
    Data   map[string]interface{} `h:"dict"`
}

A renders a HTML <a> tag.

func (*A) HTML Uses

func (a *A) HTML(ctx context.Context) (HTML, error)

HTML renders the content.

type Address Uses

type Address struct {
    ID    string                 `h:"attr"`
    Class string                 `h:"attr"`
    Style string                 `h:"attr"`
    Data  map[string]interface{} `h:"dict"`
    Inner HTML                   `h:"inner"`
}

Address renders a HTML <address> tag.

func (*Address) HTML Uses

func (p *Address) HTML(ctx context.Context) (HTML, error)

HTML renders the content.

type Aside Uses

type Aside struct {
    ID    string                 `h:"attr"`
    Class string                 `h:"attr"`
    Style string                 `h:"attr"`
    Data  map[string]interface{} `h:"dict"`
    Inner HTML                   `h:"inner"`
}

Aside renders a HTML <aside> tag.

func (*Aside) HTML Uses

func (d *Aside) HTML(ctx context.Context) (HTML, error)

HTML renders the content.

type Attributes Uses

type Attributes map[string]interface{}

Attributes are automatically rendered and automatically render most primitive types.

func (Attributes) Write Uses

func (attrs Attributes) Write(w io.Writer, prefix string) (int, error)

Render attributes with using the optional key prefix.

type Body Uses

type Body struct {
    ID    string `h:"attr"`
    Class string `h:"attr"`
    Style string `h:"attr"`
    Inner HTML   `h:"inner"`
}

Body renders a HTML <body> tag.

func (*Body) HTML Uses

func (b *Body) HTML(ctx context.Context) (HTML, error)

HTML renders the content.

type Br Uses

type Br struct{}

Br renders a HTML <br> tag.

func (*Br) HTML Uses

func (p *Br) HTML(ctx context.Context) (HTML, error)

HTML renders the content.

type Button Uses

type Button struct {
    ID    string                 `h:"attr"`
    Class string                 `h:"attr"`
    Type  string                 `h:"attr"`
    Style string                 `h:"attr"`
    Title string                 `h:"attr"`
    Data  map[string]interface{} `h:"dict"`
    Inner HTML                   `h:"inner"`
}

Button renders a HTML <button> tag.

func (*Button) HTML Uses

func (b *Button) HTML(ctx context.Context) (HTML, error)

HTML renders the content.

type Div Uses

type Div struct {
    ID    string                 `h:"attr"`
    Class string                 `h:"attr"`
    Style string                 `h:"attr"`
    Data  map[string]interface{} `h:"dict"`
    Inner HTML                   `h:"inner"`
}

Div renders a HTML <div> tag.

func (*Div) HTML Uses

func (d *Div) HTML(ctx context.Context) (HTML, error)

HTML renders the content.

type Document Uses

type Document struct {
    XMLNS XMLNS
    Inner HTML
    ID    string
    Lang  string
}

Document renders a HTML <document> tag.

func (*Document) HTML Uses

func (d *Document) HTML(ctx context.Context) (HTML, error)

HTML renders the content.

type FieldSet Uses

type FieldSet struct {
    ID    string `h:"attr"`
    Class string `h:"attr"`
    Style string `h:"attr"`
    Inner HTML   `h:"inner"`
}

FieldSet renders a HTML <fieldset> tag.

func (*FieldSet) HTML Uses

func (f *FieldSet) HTML(ctx context.Context) (HTML, error)

HTML renders the content.

type FigCaption Uses

type FigCaption struct {
    ID    string                 `h:"attr"`
    Class string                 `h:"attr"`
    Style string                 `h:"attr"`
    Data  map[string]interface{} `h:"dict"`
    Inner HTML                   `h:"inner"`
}

FigCaption renders a HTML <figcaption> tag.

func (*FigCaption) HTML Uses

func (p *FigCaption) HTML(ctx context.Context) (HTML, error)

HTML renders the content.

type Figure Uses

type Figure struct {
    ID    string                 `h:"attr"`
    Class string                 `h:"attr"`
    Style string                 `h:"attr"`
    Data  map[string]interface{} `h:"dict"`
    Inner HTML                   `h:"inner"`
}

Figure renders a HTML <figure> tag.

func (*Figure) HTML Uses

func (p *Figure) HTML(ctx context.Context) (HTML, error)

HTML renders the content.

type Footer struct {
    ID    string                 `h:"attr"`
    Class string                 `h:"attr"`
    Style string                 `h:"attr"`
    Data  map[string]interface{} `h:"dict"`
    Inner HTML                   `h:"inner"`
}

Footer renders a HTML <footer> tag.

func (*Footer) HTML Uses

func (d *Footer) HTML(ctx context.Context) (HTML, error)

HTML renders the content.

type Form Uses

type Form struct {
    ID      string `h:"attr"`
    Class   string `h:"attr"`
    Style   string `h:"attr"`
    Action  string `h:"attr"`
    Method  string `h:"attr"`
    EncType string `h:"attr"`
    Target  string `h:"attr"`
    Title   string `h:"attr"`
    Inner   HTML   `h:"inner"`
}

Form renders a HTML <form> tag.

func (*Form) HTML Uses

func (f *Form) HTML(ctx context.Context) (HTML, error)

HTML renders the content.

type Frag Uses

type Frag []HTML

Frag is a Primitive that renders a slice of HTML.

func (Frag) HTML Uses

func (f Frag) HTML(ctx context.Context) (HTML, error)

HTML renders the content.

func (Frag) Write Uses

func (f Frag) Write(ctx context.Context, w io.Writer) (int, error)

type H1 Uses

type H1 struct {
    ID    string `h:"attr"`
    Class string `h:"attr"`
    Style string `h:"attr"`
    Title string `h:"attr"`
    Inner HTML   `h:"inner"`
}

H1 renders a HTML <h1> tag.

func (*H1) HTML Uses

func (h *H1) HTML(ctx context.Context) (HTML, error)

HTML renders the content.

type H2 Uses

type H2 struct {
    ID    string `h:"attr"`
    Class string `h:"attr"`
    Style string `h:"attr"`
    Title string `h:"attr"`
    Inner HTML   `h:"inner"`
}

H2 renders a HTML <h2> tag.

func (*H2) HTML Uses

func (h *H2) HTML(ctx context.Context) (HTML, error)

HTML renders the content.

type H3 Uses

type H3 struct {
    ID    string `h:"attr"`
    Class string `h:"attr"`
    Style string `h:"attr"`
    Title string `h:"attr"`
    Inner HTML   `h:"inner"`
}

H3 renders a HTML <h3> tag.

func (*H3) HTML Uses

func (h *H3) HTML(ctx context.Context) (HTML, error)

HTML renders the content.

type H4 Uses

type H4 struct {
    ID    string `h:"attr"`
    Class string `h:"attr"`
    Style string `h:"attr"`
    Title string `h:"attr"`
    Inner HTML   `h:"inner"`
}

H4 renders a HTML <h4> tag.

func (*H4) HTML Uses

func (h *H4) HTML(ctx context.Context) (HTML, error)

HTML renders the content.

type H5 Uses

type H5 struct {
    ID    string `h:"attr"`
    Class string `h:"attr"`
    Style string `h:"attr"`
    Title string `h:"attr"`
    Inner HTML   `h:"inner"`
}

H5 renders a HTML <h5> tag.

func (*H5) HTML Uses

func (h *H5) HTML(ctx context.Context) (HTML, error)

HTML renders the content.

type H6 Uses

type H6 struct {
    ID    string `h:"attr"`
    Class string `h:"attr"`
    Style string `h:"attr"`
    Title string `h:"attr"`
    Inner HTML   `h:"inner"`
}

H6 renders a HTML <h6> tag.

func (*H6) HTML Uses

func (h *H6) HTML(ctx context.Context) (HTML, error)

HTML renders the content.

type HTML Uses

type HTML interface {
    HTML(context.Context) (HTML, error)
}

HTML that renders HTML. HTML is a recursive type which is eventually made up of Primitives.

func Compile Uses

func Compile(ctx context.Context, h HTML) HTML

Compile static HTML into HTML. Will panic if there are errors.

func HiddenInputs Uses

func HiddenInputs(values url.Values) HTML

HiddenInputs renders some HTML for the given url.Values. It does so inside a div with display: none.

type Head struct {
    Inner HTML `h:"inner"`
}

Head renders a HTML <head> tag.

func (*Head) HTML Uses

func (h *Head) HTML(ctx context.Context) (HTML, error)

HTML renders the content.

type Header struct {
    ID    string                 `h:"attr"`
    Class string                 `h:"attr"`
    Style string                 `h:"attr"`
    Data  map[string]interface{} `h:"dict"`
    Inner HTML                   `h:"inner"`
}

Header renders a HTML <header> tag.

func (*Header) HTML Uses

func (d *Header) HTML(ctx context.Context) (HTML, error)

HTML renders the content.

type I Uses

type I struct {
    ID    string                 `h:"attr"`
    Class string                 `h:"attr"`
    Style string                 `h:"attr"`
    Inner HTML                   `h:"inner"`
    Data  map[string]interface{} `h:"dict"`
}

I renders a HTML <i> tag.

func (*I) HTML Uses

func (i *I) HTML(ctx context.Context) (HTML, error)

HTML renders the content.

type Iframe Uses

type Iframe struct {
    ID              string `h:"attr"`
    Class           string `h:"attr"`
    Style           string `h:"attr"`
    Src             string `h:"attr"`
    Width           int    `h:"attr"`
    Height          int    `h:"attr"`
    FrameBorder     int    `h:"attr"`
    AllowFullScreen bool   `h:"attr"`
}

Iframe renders a HTML <iframe> tag.

func (*Iframe) HTML Uses

func (t *Iframe) HTML(ctx context.Context) (HTML, error)

HTML renders the content.

type Img Uses

type Img struct {
    ID    string                 `h:"attr"`
    Class string                 `h:"attr"`
    Style string                 `h:"attr"`
    Src   string                 `h:"attr"`
    Alt   string                 `h:"attr"`
    Inner HTML                   `h:"inner"`
    Data  map[string]interface{} `h:"dict"`
}

Img renders a HTML <img> tag.

func (*Img) HTML Uses

func (t *Img) HTML(ctx context.Context) (HTML, error)

HTML renders the content.

type Input Uses

type Input struct {
    ID          string                 `h:"attr"`
    Class       string                 `h:"attr"`
    Name        string                 `h:"attr"`
    Style       string                 `h:"attr"`
    Type        string                 `h:"attr"`
    Value       string                 `h:"attr"`
    Src         string                 `h:"attr"`
    Placeholder string                 `h:"attr"`
    Checked     bool                   `h:"attr"`
    Multiple    bool                   `h:"attr"`
    Data        map[string]interface{} `h:"dict"`
    Inner       HTML                   `h:"inner"`
}

Input renders a HTML <input> tag.

func (*Input) HTML Uses

func (i *Input) HTML(ctx context.Context) (HTML, error)

HTML renders the content.

type Label Uses

type Label struct {
    ID    string `h:"attr"`
    Class string `h:"attr"`
    Style string `h:"attr"`
    Title string `h:"attr"`
    For   string `h:"attr"`
    Inner HTML   `h:"inner"`
}

Label renders a HTML <label> tag.

func (*Label) HTML Uses

func (l *Label) HTML(ctx context.Context) (HTML, error)

HTML renders the content.

type Legend Uses

type Legend struct {
    ID    string `h:"attr"`
    Class string `h:"attr"`
    Style string `h:"attr"`
    Inner HTML   `h:"inner"`
}

Legend renders a HTML <legend> tag.

func (*Legend) HTML Uses

func (l *Legend) HTML(ctx context.Context) (HTML, error)

HTML renders the content.

type Li Uses

type Li struct {
    ID    string `h:"attr"`
    Class string `h:"attr"`
    Style string `h:"attr"`
    Title string `h:"attr"`
    Inner HTML   `h:"inner"`
}

Li renders a HTML <li> tag.

func (*Li) HTML Uses

func (l *Li) HTML(ctx context.Context) (HTML, error)

HTML renders the content.

type Link struct {
    HREF string `h:"attr"`
    Type string `h:"attr"`
    Rel  string `h:"attr"`
}

Link renders a HTML <link> tag.

func (*Link) HTML Uses

func (l *Link) HTML(ctx context.Context) (HTML, error)

HTML renders the content.

type LinkStyle Uses

type LinkStyle struct {
    HREF string
}

LinkStyle provides the common CSS Style Sheet tag.

func (*LinkStyle) HTML Uses

func (l *LinkStyle) HTML(ctx context.Context) (HTML, error)

HTML renders the tag.

type Main Uses

type Main struct {
    ID    string                 `h:"attr"`
    Class string                 `h:"attr"`
    Style string                 `h:"attr"`
    Data  map[string]interface{} `h:"dict"`
    Inner HTML                   `h:"inner"`
}

Main renders a HTML <main> tag.

func (*Main) HTML Uses

func (d *Main) HTML(ctx context.Context) (HTML, error)

HTML renders the content.

type Meta Uses

type Meta struct {
    Charset  string `h:"attr"`
    Name     string `h:"attr"`
    Property string `h:"attr"`
    Content  string `h:"attr"`
}

Meta renders a HTML <meta> tag.

func (*Meta) HTML Uses

func (m *Meta) HTML(ctx context.Context) (HTML, error)

HTML renders the content.

type Nav struct {
    ID    string                 `h:"attr"`
    Class string                 `h:"attr"`
    Style string                 `h:"attr"`
    Data  map[string]interface{} `h:"dict"`
    Inner HTML                   `h:"inner"`
}

Nav renders a HTML <nav> tag.

func (d *Nav) HTML(ctx context.Context) (HTML, error)

HTML renders the content.

type Node Uses

type Node struct {
    Tag         string
    Attributes  Attributes
    Inner       HTML
    SelfClosing bool
}

Node is a primitive to generate a HTML node with the given configuration.

func (*Node) HTML Uses

func (n *Node) HTML(ctx context.Context) (HTML, error)

HTML renders the content.

func (*Node) Write Uses

func (n *Node) Write(ctx context.Context, w io.Writer) (int, error)

Write the generated markup for a Node.

type Option Uses

type Option struct {
    ID       string                 `h:"attr"`
    Class    string                 `h:"attr"`
    Style    string                 `h:"attr"`
    Title    string                 `h:"attr"`
    Value    string                 `h:"attr"`
    Selected bool                   `h:"attr"`
    Data     map[string]interface{} `h:"dict"`
    Inner    HTML                   `h:"inner"`
}

Option renders a HTML <option> tag.

func (*Option) HTML Uses

func (o *Option) HTML(ctx context.Context) (HTML, error)

HTML renders the content.

type P Uses

type P struct {
    ID    string                 `h:"attr"`
    Class string                 `h:"attr"`
    Style string                 `h:"attr"`
    Data  map[string]interface{} `h:"dict"`
    Inner HTML                   `h:"inner"`
}

P renders a HTML <p> tag.

func (*P) HTML Uses

func (p *P) HTML(ctx context.Context) (HTML, error)

HTML renders the content.

type Pre Uses

type Pre struct {
    ID    string `h:"attr"`
    Class string `h:"attr"`
    Style string `h:"attr"`
    Inner HTML   `h:"inner"`
}

Pre renders a HTML <pre> tag.

func (*Pre) HTML Uses

func (d *Pre) HTML(ctx context.Context) (HTML, error)

HTML renders the content.

type Primitive Uses

type Primitive interface {
    Write(context.Context, io.Writer) (int, error)
}

Primitive generates HTML. They are terminal, as opposed to recursive like HTML. Primitive types satisfy HTML, but it is an error to use them as such.

type ReflectNode Uses

type ReflectNode struct {
    Tag         string
    Node        interface{}
    SelfClosing bool
}

ReflectNode uses reflection to generate a HTML from a struct.

func (*ReflectNode) HTML Uses

func (n *ReflectNode) HTML(ctx context.Context) (HTML, error)

HTML renders the content.

func (*ReflectNode) Write Uses

func (n *ReflectNode) Write(ctx context.Context, w io.Writer) (int, error)

Write the generated markup for a ReflectNode.

type Script Uses

type Script struct {
    Src   string `h:"attr"`
    Async bool   `h:"attr"`
    Inner HTML   `h:"inner"`
}

Script renders a HTML <script> tag.

func (*Script) HTML Uses

func (s *Script) HTML(ctx context.Context) (HTML, error)

HTML renders the content.

type Select Uses

type Select struct {
    ID       string `h:"attr"`
    Class    string `h:"attr"`
    Name     string `h:"attr"`
    Style    string `h:"attr"`
    Title    string `h:"attr"`
    Multiple bool   `h:"attr"`
    Size     int    `h:"size"`
    Inner    HTML   `h:"inner"`
}

Select renders a HTML <select> tag.

func (*Select) HTML Uses

func (s *Select) HTML(ctx context.Context) (HTML, error)

HTML renders the content.

type Small Uses

type Small struct {
    ID    string                 `h:"attr"`
    Class string                 `h:"attr"`
    Style string                 `h:"attr"`
    Data  map[string]interface{} `h:"dict"`
    Inner HTML                   `h:"inner"`
}

Small renders a HTML <small> tag.

func (*Small) HTML Uses

func (d *Small) HTML(ctx context.Context) (HTML, error)

HTML renders the content.

type Span Uses

type Span struct {
    ID    string `h:"attr"`
    Class string `h:"attr"`
    Style string `h:"attr"`
    Inner HTML   `h:"inner"`
}

Span renders a HTML <span> tag.

func (*Span) HTML Uses

func (s *Span) HTML(ctx context.Context) (HTML, error)

HTML renders the content.

type String Uses

type String string

String is a Primitive that renders a string of text. The contents are encoded using html.EscapeString.

func (String) HTML Uses

func (s String) HTML(ctx context.Context) (HTML, error)

HTML renders the content.

type Strong Uses

type Strong struct {
    ID    string `h:"attr"`
    Class string `h:"attr"`
    Style string `h:"attr"`
    Title string `h:"attr"`
    Inner HTML   `h:"inner"`
}

Strong renders a HTML <strong> tag.

func (*Strong) HTML Uses

func (s *Strong) HTML(ctx context.Context) (HTML, error)

HTML renders the content.

type Style Uses

type Style struct {
    ID    string `h:"attr"`
    Inner HTML   `h:"inner"`
}

Style renders a HTML <style> tag.

func (*Style) HTML Uses

func (s *Style) HTML(ctx context.Context) (HTML, error)

HTML renders the content.

type Table Uses

type Table struct {
    ID    string `h:"attr"`
    Class string `h:"attr"`
    Style string `h:"attr"`
    Inner HTML   `h:"inner"`
}

Table renders a HTML <table> tag.

func (*Table) HTML Uses

func (t *Table) HTML(ctx context.Context) (HTML, error)

HTML renders the content.

type Tbody Uses

type Tbody struct {
    ID    string `h:"attr"`
    Class string `h:"attr"`
    Style string `h:"attr"`
    Inner HTML   `h:"inner"`
}

Tbody renders a HTML <tbody> tag.

func (*Tbody) HTML Uses

func (t *Tbody) HTML(ctx context.Context) (HTML, error)

HTML renders the content.

type Td Uses

type Td struct {
    ID    string `h:"attr"`
    Class string `h:"attr"`
    Style string `h:"attr"`
    Inner HTML   `h:"inner"`
}

Td renders a HTML <td> tag.

func (*Td) HTML Uses

func (t *Td) HTML(ctx context.Context) (HTML, error)

HTML renders the content.

type Textarea Uses

type Textarea struct {
    ID    string `h:"attr"`
    Class string `h:"attr"`
    Style string `h:"attr"`
    Name  string `h:"attr"`
    Inner HTML   `h:"inner"`
}

Textarea renders a HTML <textarea> tag.

func (*Textarea) HTML Uses

func (t *Textarea) HTML(ctx context.Context) (HTML, error)

HTML renders the content.

type Th Uses

type Th struct {
    ID    string `h:"attr"`
    Class string `h:"attr"`
    Style string `h:"attr"`
    Scope string `h:"attr"`
    Inner HTML   `h:"inner"`
}

Th renders a HTML <th> tag.

func (*Th) HTML Uses

func (t *Th) HTML(ctx context.Context) (HTML, error)

HTML renders the content.

type Thead Uses

type Thead struct {
    ID    string `h:"attr"`
    Class string `h:"attr"`
    Style string `h:"attr"`
    Inner HTML   `h:"inner"`
}

Thead renders a HTML <thead> tag.

func (*Thead) HTML Uses

func (t *Thead) HTML(ctx context.Context) (HTML, error)

HTML renders the content.

type Title Uses

type Title Frag

Title renders a HTML <title> tag.

func (*Title) HTML Uses

func (t *Title) HTML(ctx context.Context) (HTML, error)

HTML renders the content.

type Tr Uses

type Tr struct {
    ID    string                 `h:"attr"`
    Class string                 `h:"attr"`
    Style string                 `h:"attr"`
    Data  map[string]interface{} `h:"dict"`
    Inner HTML                   `h:"inner"`
}

Tr renders a HTML <tr> tag.

func (*Tr) HTML Uses

func (t *Tr) HTML(ctx context.Context) (HTML, error)

HTML renders the content.

type Ul Uses

type Ul struct {
    ID    string `h:"attr"`
    Class string `h:"attr"`
    Style string `h:"attr"`
    Title string `h:"attr"`
    Inner HTML   `h:"inner"`
}

Ul renders a HTML <ul> tag.

func (*Ul) HTML Uses

func (ul *Ul) HTML(ctx context.Context) (HTML, error)

HTML renders the content.

type Unsafe Uses

type Unsafe string

Unsafe is a Primitive that renders a string of HTML. The contents are NOT encoded and allows for HTML to be included as is. You should not use this to render user generated content.

func (Unsafe) HTML Uses

func (u Unsafe) HTML(ctx context.Context) (HTML, error)

HTML renders the content.

func (Unsafe) Write Uses

func (u Unsafe) Write(ctx context.Context, w io.Writer) (int, error)

type UnsafeBytes Uses

type UnsafeBytes []byte

UnsafeBytes is a Primitive that renders bytes of HTML. The contents are NOT encoded and allows for HTML to be included as is. You should not use this to render user generated content.

func (UnsafeBytes) HTML Uses

func (u UnsafeBytes) HTML(ctx context.Context) (HTML, error)

HTML renders the content.

func (UnsafeBytes) Write Uses

func (u UnsafeBytes) Write(ctx context.Context, w io.Writer) (int, error)

type XMLNS Uses

type XMLNS map[string]string

XMLNS auto prefixes each attribute key with "xmlns:" in the output.

func (XMLNS) Attributes Uses

func (ns XMLNS) Attributes() Attributes

Attributes returns the attributes to render.

Package h imports 11 packages (graph) and is imported by 12 packages. Updated 2016-08-19. Refresh now. Tools for package owners.