element

package
v2.12.2 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2015 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IdForbidden               flag // element should not have an id attribute
	ClassForbidden                 // element should not have a class attribute
	SelfClosing                    // element is selfclosing and contains no content
	Inline                         // element is an inline element (only for visible elements)
	FormField                      // element is a field of a form
	Invisible                      // element doesn't render anything visible
	WithoutEscaping                // element does not escape inner Text
	WithoutDecoration              // element just prints the InnerHtml
	JavascriptSpecialEscaping      // content contains javascript and needs special escaping or </
)

Variables

This section is empty.

Functions

func AttrsString

func AttrsString(ø *Element) (res string)

prepare the id attribute for output

func InnerHtml

func InnerHtml(ø *Element) (res string)

func InnerHtmlBf

func InnerHtmlBf(ø *Element, w io.Writer) (num int64, err error)

func Is

func Is(ø *Element, f flag) bool

Is checks if a given flag is set, e.g.

Is(Inline)

checks for the Inline flag

func Post

func Post(ø *Element, w io.Writer) (num int, err error)

Post writes properties of an element to w after the inner elements are written to w

func Pre

func Pre(ø *Element, w io.Writer) (num int, err error)

Pre writes properties of an element to w before the inner elements are written to w

Types

type Element

type Element struct {
	Id         types.Id
	Descr      types.Descr
	Parent     ElementLike
	Attributes []types.Attribute
	Classes    []types.Class
	Children   []builtin.Stringer
	Styles     []types.Style
	// contains filtered or unexported fields
}

the base of what becomes a tag when printed

func Elements

func Elements(objects ...interface{}) (t *Element)

empty list of elements and others

func NewElement

func NewElement(tag string, flags ...flag) (ø *Element)

contruct a new element with some flags.

the tag constructors A(), Body(),... use these method, see tags.go file for examples

use it for your own tags

the following flags are supported

IdForbidden                        // element should not have an id attribute
ClassForbidden                     // element should not have a class attribute
SelfClosing                        // element is selfclosing and contains no content
Inline                             // element is an inline element (only for visible elements)
Field                              // element is a field of a form
Invisible                          // element doesn't render anything visible
WithoutEscaping                    // element does not escape inner Text
WithoutDecoration                  // element just prints the InnerHtml

see Add() and Set() methods for how to modify the Element

func (*Element) Add

func (ø *Element) Add(objects ...interface{})

adds new inner content or properties based on Stringer objects and returns an error if changes could not be applied

the following types are handled in a special way:

  • Descr: sets a description of the eleent, that with be rendered to a comment
  • Style: set a single style
  • Styles: sets multiple styles
  • Attr: set a single attribute // do not set id or class via Attr(s) directly, use Id() and Class() instead
  • Attrs: sets multiple attribute
  • Class: adds a class
  • Id: sets the id
  • *Css: applies the css, see ApplyCss()

the following types are added to the inner content:

  • Text: ís escaped if the WithoutEscaping flag isn't set
  • Html: is never escaped

If the Stringer can be casted to an Elementer (as Element can), it is added to the inner content as well otherwise it is handled like Text(), that means any type implementing Stringer can be added as (escaped) text func (ø *Element) Add(objects ...interface{}) ElementLike {

func (*Element) HTML

func (ø *Element) HTML() string

func (*Element) Selector

func (ø *Element) Selector() string

func (*Element) ServeHTTP

func (ø *Element) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Element) String

func (ø *Element) String() (res string)

returns the html with inner content (and the own tags if WithoutDecoration is not set)

func (*Element) Tag

func (ø *Element) Tag() string

func (*Element) Template

func (e *Element) Template(name string) *template.Template

func (*Element) WriteTo

func (ø *Element) WriteTo(w io.Writer) (num int64, err error)

WriteTo does implement io.WriterTo interface

type ElementLike

type ElementLike interface {
	// Tag returns the HTML tag
	Tag() string

	// HTML returns the HTML string
	HTML() string

	// String returns the same as HTML
	String() string

	// Add adds different objects to the element
	Add(objects ...interface{})
}

ElementLike behaves like an HTML Element.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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