web

package module
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 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>
Example
c := NewCSS()
c.Media = "@media screen"
c.Style("#x", "margin: 0 0")
c.WriteTo(os.Stdout)
Output:

@media screen{
#x {
margin: 0 0;
}
}

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)

func WalkElements added in v0.10.0

func WalkElements(root *Element, fn func(e *Element))

Types

type Attribute

type Attribute struct {
	Name string
	Val  string
}

func Action added in v0.8.3

func Action(v string) *Attribute

Action returns a action="v" attribute

func Alt

func Alt(v string) *Attribute

Alt returns a alt="v" attribute

func Attr added in v0.9.0

func Attr(name string, val interface{}) *Attribute

func Autocomplete added in v0.8.3

func Autocomplete(v string) *Attribute

Autocomplete returns a autocomplete="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 Method added in v0.8.3

func Method(v string) *Attribute

Method returns a method="v" attribute

func Name

func Name(v string) *Attribute

Name returns a name="v" attribute

func OnBlur added in v0.9.0

func OnBlur(v string) *Attribute

OnBlur returns a onBlur="v" attribute

func OnFocus added in v0.9.0

func OnFocus(v string) *Attribute

OnFocus returns a onFocus="v" attribute

func OnLoad added in v0.9.0

func OnLoad(v string) *Attribute

OnLoad returns a onLoad="v" attribute

func OnMouseDown added in v0.9.0

func OnMouseDown(v string) *Attribute

OnMouseDown returns a onMouseDown="v" attribute

func OnMouseOut added in v0.9.0

func OnMouseOut(v string) *Attribute

OnMouseOut returns a onMouseOut="v" attribute

func OnMouseOver added in v0.9.0

func OnMouseOver(v string) *Attribute

OnMouseOver returns a onMouseOver="v" attribute

func OnMouseUp added in v0.9.0

func OnMouseUp(v string) *Attribute

OnMouseUp returns a onMouseUp="v" attribute

func OnMouseWheel added in v0.9.0

func OnMouseWheel(v string) *Attribute

OnMouseWheel returns a onMouseWheel="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 Tabindex added in v0.8.3

func Tabindex(v string) *Attribute

Tabindex returns a tabindex="v" attribute

func Type

func Type(v string) *Attribute

Type returns a type="v" attribute

func Value added in v0.8.3

func Value(v string) *Attribute

Value returns a value="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 CSS added in v0.9.0

type CSS struct {
	Media string
	// contains filtered or unexported fields
}

func NewCSS added in v0.9.0

func NewCSS() *CSS

func (*CSS) Style added in v0.9.0

func (c *CSS) Style(selector string, propvals ...string)

func (*CSS) WriteTo added in v0.9.0

func (r *CSS) WriteTo(w io.Writer) (int64, error)

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 an <a> element with optional children or attributes

func Abbr

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

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

func Acronym

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

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

func Address

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

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

func Article

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

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

func Aside

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

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

func B

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

B returns an <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 an <big> element with optional children or attributes

func Blockquote

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

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

func Body

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

Body returns an <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 an <button> element with optional children or attributes

func Cite

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

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

func Code

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

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

func Dd

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

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

func Del

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

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

func Details

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

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

func Dfn

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

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

func Div

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

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

func Dl

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

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

func Dt

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

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

func Em added in v0.8.3

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

Em returns an <em> element with optional children or attributes

func Fieldset added in v0.8.3

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

Fieldset returns an <fieldset> element with optional children or attributes

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

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

func Form

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

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

func H1

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

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

func H2

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

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

func H3

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

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

func H4

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

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

func H5

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

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

func H6

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

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

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

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

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

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

func Hgroup

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

Hgroup returns an <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 an <html> element with optional children or attributes

func I

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

I returns an <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 an <ins> element with optional children or attributes

func Kbd

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

Kbd returns an <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 an <label> element with optional children or attributes

func Legend

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

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

func Li

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

Li returns an <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 an <mark> element with optional children or attributes

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

Menu returns an <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 an <meter> element with optional children or attributes

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

Nav returns an <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 an <noscript> element with optional children or attributes

func Ol

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

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

func Optgroup

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

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

func Option

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

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

func Output

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

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

func P

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

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

func Pre

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

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

func Quote

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

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

func Script

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

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

func Section

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

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

func Select

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

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

func Span

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

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

func Style

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

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

func Sub

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

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

func Summary

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

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

func Sup

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

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

func Table

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

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

func Tbody

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

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

func Td

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

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

func Textarea

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

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

func Th

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

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

func Thead

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

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

func Title

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

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

func Tr

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

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

func U

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

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

func Ul

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

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

func Var

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

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

func (*Element) String

func (t *Element) String() string

func (*Element) Text added in v0.10.0

func (t *Element) Text() string

func (*Element) With

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

func (*Element) WriteTo added in v0.9.0

func (t *Element) WriteTo(w io.Writer) (int64, error)

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"),
	P(
		"before ", A(Href("http://example.com"), "example"),
		" after",
	),
)
page := NewPage("", Html(Body(article)))
page.WriteTo(os.Stdout)
Output:

<!DOCTYPE html>

<html>
<body>
<article class="fancy">
<h1>Title of my article</h1>
<p>before <a href="http://example.com">example</a> after</p>
</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