web

package module
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2020 License: MIT Imports: 10 Imported by: 17

README

web - package for mostly html related rendering

Documentation

Overview

Package web provides html writing capabilities.

In most cases when writing interactive webapplications you should stick to html/template package. This package however can be suitable when writing documentation or generating websites.

article := Article(
   Class("fancy"),
   H1("Title of my article"),
)
page := NewPage("", Html(Body(article)))
page.WriteTo(os.Stdout)

By default the page is written as html, expected.

<!DOCTYPE html>

<html>
<body>
<article class="fancy">
<h1>Title of my article</h1>

</article>
</body>
</html>

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckLink(file, rel string, n *html.Node, broken chan BrokenLink)
func CheckLinks(root string, broken chan BrokenLink)

Types

type Attribute

type Attribute struct {
	Name string
	Val  string
}

func Alt

func Alt(v string) *Attribute

Alt returns a alt="v" attribute

func Charset

func Charset(v string) *Attribute

Charset returns a charset="v" attribute

func Class

func Class(v string) *Attribute

Class returns a class="v" attribute

func Content

func Content(v string) *Attribute

Content returns a content="v" attribute

func Href

func Href(v string) *Attribute

Href returns a href="v" attribute

func Id

func Id(v string) *Attribute

Id returns a id="v" attribute

func Lang

func Lang(v string) *Attribute

Lang returns a lang="v" attribute

func Name

func Name(v string) *Attribute

Name returns a name="v" attribute

func Rel

func Rel(v string) *Attribute

Rel returns a rel="v" attribute

func Src

func Src(v string) *Attribute

Src returns a src="v" attribute

func Type

func Type(v string) *Attribute

Type returns a type="v" attribute

func (*Attribute) String

func (a *Attribute) String() string
type BrokenLink struct {
	File string
	Ref  string
	Err  error
}

func (*BrokenLink) String

func (l *BrokenLink) String() string

type Element

type Element struct {
	Children   []interface{}
	Name       string
	Attributes []*Attribute
	// contains filtered or unexported fields
}

func A

func A(c ...interface{}) *Element

A returns a <a> element with optional children or attributes

func Abbr

func Abbr(c ...interface{}) *Element

Abbr returns a <abbr> element with optional children or attributes

func Acronym

func Acronym(c ...interface{}) *Element

Acronym returns a <acronym> element with optional children or attributes

func Address

func Address(c ...interface{}) *Element

Address returns a <address> element with optional children or attributes

func Article

func Article(c ...interface{}) *Element

Article returns a <article> element with optional children or attributes

func Aside

func Aside(c ...interface{}) *Element

Aside returns a <aside> element with optional children or attributes

func B

func B(c ...interface{}) *Element

B returns a <b> element with optional children or attributes

func Base

func Base(c ...interface{}) *Element

Base returns a <base/> element with optional attributes

func Big

func Big(c ...interface{}) *Element

Big returns a <big> element with optional children or attributes

func Blockquote

func Blockquote(c ...interface{}) *Element

Blockquote returns a <blockquote> element with optional children or attributes

func Body

func Body(c ...interface{}) *Element

Body returns a <body> element with optional children or attributes

func Br

func Br(c ...interface{}) *Element

Br returns a <br/> element with optional attributes

func Button

func Button(c ...interface{}) *Element

Button returns a <button> element with optional children or attributes

func Cite

func Cite(c ...interface{}) *Element

Cite returns a <cite> element with optional children or attributes

func Code

func Code(c ...interface{}) *Element

Code returns a <code> element with optional children or attributes

func Dd

func Dd(c ...interface{}) *Element

Dd returns a <dd> element with optional children or attributes

func Del

func Del(c ...interface{}) *Element

Del returns a <del> element with optional children or attributes

func Details

func Details(c ...interface{}) *Element

Details returns a <details> element with optional children or attributes

func Dfn

func Dfn(c ...interface{}) *Element

Dfn returns a <dfn> element with optional children or attributes

func Div

func Div(c ...interface{}) *Element

Div returns a <div> element with optional children or attributes

func Dl

func Dl(c ...interface{}) *Element

Dl returns a <dl> element with optional children or attributes

func Dt

func Dt(c ...interface{}) *Element

Dt returns a <dt> element with optional children or attributes

func Footer(c ...interface{}) *Element

Footer returns a <footer> element with optional children or attributes

func Form

func Form(c ...interface{}) *Element

Form returns a <form> element with optional children or attributes

func H1

func H1(c ...interface{}) *Element

H1 returns a <h1> element with optional children or attributes

func H2

func H2(c ...interface{}) *Element

H2 returns a <h2> element with optional children or attributes

func H3

func H3(c ...interface{}) *Element

H3 returns a <h3> element with optional children or attributes

func H4

func H4(c ...interface{}) *Element

H4 returns a <h4> element with optional children or attributes

func H5

func H5(c ...interface{}) *Element

H5 returns a <h5> element with optional children or attributes

func H6

func H6(c ...interface{}) *Element

H6 returns a <h6> element with optional children or attributes

func Head(c ...interface{}) *Element

Head returns a <head> element with optional children or attributes

func Header(c ...interface{}) *Element

Header returns a <header> element with optional children or attributes

func Hgroup

func Hgroup(c ...interface{}) *Element

Hgroup returns a <hgroup> element with optional children or attributes

func Hr

func Hr(c ...interface{}) *Element

Hr returns a <hr/> element with optional attributes

func Html

func Html(c ...interface{}) *Element

Html returns a <html> element with optional children or attributes

func I

func I(c ...interface{}) *Element

I returns a <i> element with optional children or attributes

func Img

func Img(c ...interface{}) *Element

Img returns a <img/> element with optional attributes

func Input

func Input(c ...interface{}) *Element

Input returns a <input/> element with optional attributes

func Ins

func Ins(c ...interface{}) *Element

Ins returns a <ins> element with optional children or attributes

func Kbd

func Kbd(c ...interface{}) *Element

Kbd returns a <kbd> element with optional children or attributes

func Keygen

func Keygen(c ...interface{}) *Element

Keygen returns a <keygen/> element with optional attributes

func Label

func Label(c ...interface{}) *Element

Label returns a <label> element with optional children or attributes

func Legend

func Legend(c ...interface{}) *Element

Legend returns a <legend> element with optional children or attributes

func Li

func Li(c ...interface{}) *Element

Li returns a <li> element with optional children or attributes

func Link(c ...interface{}) *Element

Link returns a <link/> element with optional attributes

func Mark

func Mark(c ...interface{}) *Element

Mark returns a <mark> element with optional children or attributes

func Menu(c ...interface{}) *Element

Menu returns a <menu> element with optional children or attributes

func Meta

func Meta(c ...interface{}) *Element

Meta returns a <meta/> element with optional attributes

func Meter

func Meter(c ...interface{}) *Element

Meter returns a <meter> element with optional children or attributes

func Nav(c ...interface{}) *Element

Nav returns a <nav> element with optional children or attributes

func NewElement

func NewElement(Name string, childOrAttr ...interface{}) *Element

func NewSimpleElement

func NewSimpleElement(Name string, childOrAttr ...interface{}) *Element

func Noscript

func Noscript(c ...interface{}) *Element

Noscript returns a <noscript> element with optional children or attributes

func Ol

func Ol(c ...interface{}) *Element

Ol returns a <ol> element with optional children or attributes

func Optgroup

func Optgroup(c ...interface{}) *Element

Optgroup returns a <optgroup> element with optional children or attributes

func Option

func Option(c ...interface{}) *Element

Option returns a <option> element with optional children or attributes

func Output

func Output(c ...interface{}) *Element

Output returns a <output> element with optional children or attributes

func P

func P(c ...interface{}) *Element

P returns a <p> element with optional children or attributes

func Pre

func Pre(c ...interface{}) *Element

Pre returns a <pre> element with optional children or attributes

func Quote

func Quote(c ...interface{}) *Element

Quote returns a <quote> element with optional children or attributes

func Script

func Script(c ...interface{}) *Element

Script returns a <script> element with optional children or attributes

func Section

func Section(c ...interface{}) *Element

Section returns a <section> element with optional children or attributes

func Select

func Select(c ...interface{}) *Element

Select returns a <select> element with optional children or attributes

func Span

func Span(c ...interface{}) *Element

Span returns a <span> element with optional children or attributes

func Style

func Style(c ...interface{}) *Element

Style returns a <style> element with optional children or attributes

func Sub

func Sub(c ...interface{}) *Element

Sub returns a <sub> element with optional children or attributes

func Summary

func Summary(c ...interface{}) *Element

Summary returns a <summary> element with optional children or attributes

func Sup

func Sup(c ...interface{}) *Element

Sup returns a <sup> element with optional children or attributes

func Table

func Table(c ...interface{}) *Element

Table returns a <table> element with optional children or attributes

func Tbody

func Tbody(c ...interface{}) *Element

Tbody returns a <tbody> element with optional children or attributes

func Td

func Td(c ...interface{}) *Element

Td returns a <td> element with optional children or attributes

func Textarea

func Textarea(c ...interface{}) *Element

Textarea returns a <textarea> element with optional children or attributes

func Th

func Th(c ...interface{}) *Element

Th returns a <th> element with optional children or attributes

func Thead

func Thead(c ...interface{}) *Element

Thead returns a <thead> element with optional children or attributes

func Title

func Title(c ...interface{}) *Element

Title returns a <title> element with optional children or attributes

func Tr

func Tr(c ...interface{}) *Element

Tr returns a <tr> element with optional children or attributes

func U

func U(c ...interface{}) *Element

U returns a <u> element with optional children or attributes

func Ul

func Ul(c ...interface{}) *Element

Ul returns a <ul> element with optional children or attributes

func Var

func Var(c ...interface{}) *Element

Var returns a <var> element with optional children or attributes

func (*Element) String

func (t *Element) String() string

func (*Element) With

func (t *Element) With(childOrAttr ...interface{}) *Element

type HtmlWriter

type HtmlWriter struct {
	*nexus.Printer
	// contains filtered or unexported fields
}

func NewHtmlWriter

func NewHtmlWriter(w io.Writer) *HtmlWriter

func (*HtmlWriter) WriteHtml

func (p *HtmlWriter) WriteHtml(t interface{}) (int64, error)

type MarkdownWriter

type MarkdownWriter struct {
	*nexus.Printer
	// contains filtered or unexported fields
}

func NewMarkdownWriter

func NewMarkdownWriter(w io.Writer) *MarkdownWriter

func (*MarkdownWriter) WriteMarkdown

func (p *MarkdownWriter) WriteMarkdown(e *Element)

type Page

type Page struct {
	Filename string
	*Element
}

func NewPage

func NewPage(filename string, el *Element) *Page

func (*Page) SaveTo

func (p *Page) SaveTo(dir string) error

func (*Page) WriteTo

func (p *Page) WriteTo(w io.Writer) (int64, error)
Example
article := Article(
	Class("fancy"),
	H1("Title of my article"),
)
page := NewPage("", Html(Body(article)))
page.WriteTo(os.Stdout)
Output:

<!DOCTYPE html>

<html>
<body>
<article class="fancy">
<h1>Title of my article</h1>

</article>
</body>
</html>

Directories

Path Synopsis
Package apidoc is a way to define self documenting HTTP API's.
Package apidoc is a way to define self documenting HTTP API's.
cmd
toc
toc working with links and table of contents
toc working with links and table of contents

Jump to

Keyboard shortcuts

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