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

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

Render HTML as a string.

func Write

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

Write HTML into a writer.

type A

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

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

HTML renders the content.

type Address

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

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

HTML renders the content.

type Aside

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

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

HTML renders the content.

type Attributes

type Attributes map[string]interface{}

Attributes are automatically rendered and automatically render most primitive types.

func (Attributes) Write

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

Render attributes with using the optional key prefix.

type Body

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

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

HTML renders the content.

type Br

type Br struct{}

Br renders a HTML <br> tag.

func (*Br) HTML

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

HTML renders the content.

type Button

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

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

HTML renders the content.

type Div

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

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

HTML renders the content.

type Document

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

Document renders a HTML <document> tag.

func (*Document) HTML

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

HTML renders the content.

type FieldSet

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

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

HTML renders the content.

type FigCaption

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

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

HTML renders the content.

type Figure

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

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

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

HTML renders the content.

type Form

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

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

HTML renders the content.

type Frag

type Frag []HTML

Frag is a Primitive that renders a slice of HTML.

func (Frag) HTML

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

HTML renders the content.

func (Frag) Write

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

type H1

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

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

HTML renders the content.

type H2

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

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

HTML renders the content.

type H3

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

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

HTML renders the content.

type H4

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

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

HTML renders the content.

type H5

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

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

HTML renders the content.

type H6

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

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

HTML renders the content.

type HTML

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

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

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

func HiddenInputs

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

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

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

HTML renders the content.

type I

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

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

HTML renders the content.

type Iframe

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

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

HTML renders the content.

type Img

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

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

HTML renders the content.

type Input

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

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

HTML renders the content.

type Label

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

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

HTML renders the content.

type Legend

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

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

HTML renders the content.

type Li

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

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

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

HTML renders the content.

type LinkStyle

type LinkStyle struct {
    HREF string
}

LinkStyle provides the common CSS Style Sheet tag.

func (*LinkStyle) HTML

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

HTML renders the tag.

type Main

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

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

HTML renders the content.

type Meta

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

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

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

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

HTML renders the content.

func (*Node) Write

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

Write the generated markup for a Node.

type Option

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

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

HTML renders the content.

type P

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

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

HTML renders the content.

type Pre

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

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

HTML renders the content.

type Primitive

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

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

ReflectNode uses reflection to generate a HTML from a struct.

func (*ReflectNode) HTML

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

HTML renders the content.

func (*ReflectNode) Write

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

Write the generated markup for a ReflectNode.

type Script

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

Script renders a HTML <script> tag.

func (*Script) HTML

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

HTML renders the content.

type Select

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

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

HTML renders the content.

type Small

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

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

HTML renders the content.

type Span

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

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

HTML renders the content.

type String

type String string

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

func (String) HTML

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

HTML renders the content.

type Strong

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

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

HTML renders the content.

type Style

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

Style renders a HTML <style> tag.

func (*Style) HTML

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

HTML renders the content.

type Table

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

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

HTML renders the content.

type Tbody

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

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

HTML renders the content.

type Td

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

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

HTML renders the content.

type Textarea

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

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

HTML renders the content.

type Th

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

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

HTML renders the content.

type Thead

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

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

HTML renders the content.

type Title

type Title Frag

Title renders a HTML <title> tag.

func (*Title) HTML

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

HTML renders the content.

type Tr

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

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

HTML renders the content.

type Ul

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

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

HTML renders the content.

type Unsafe

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

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

HTML renders the content.

func (Unsafe) Write

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

type UnsafeBytes

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

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

HTML renders the content.

func (UnsafeBytes) Write

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

type XMLNS

type XMLNS map[string]string

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

func (XMLNS) Attributes

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-01-11. Refresh now. Tools for package owners.