objhtml

package module
v0.0.0-...-b716d53 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2019 License: Apache-2.0 Imports: 13 Imported by: 0

README

objhtml

Implemented full generation of all basic html elements

Usage:

go get "github.com/linkonoid/objhtml"

Little demo web-server for testing:

Open /example folder, compile test.go and start server example.exe Open browser 127.0.0.1:9000

Documentation

Index

Constants

View Source
const (
	OnClick     = "onclick"
	OnChange    = "onchange"
	OnKeyPress  = "onkeypress"
	OnAbort     = "onabort"
	OnBlur      = "onblur"
	OnDblclick  = "ondblclick"
	OnError     = "onerror"
	OnFocus     = "onfocus"
	OnKeydown   = "onkeydown"
	OnKeyup     = "onkeyup"
	OnLoad      = "onload"
	OnMousedown = "onmousedown"
	OnMousemove = "onmousemove"
	OnMouseout  = "onmouseout"
	OnMouseover = "onmouseover"
	OnMouseup   = "onmouseup"
	OnReset     = "onreset"
	OnResize    = "onresize"
	OnSelect    = "onselect"
	OnSubmit    = "onsubmit"
	OnUnload    = "onunload"
)
View Source
const (
	TypeTextHtml   = "text/html"
	TypeJavascript = "text/javascript"
	TypeCss        = "text/css"
)

Content types

View Source
const (
	ButtonButton = "button"
	ButtonReset  = "reset"
	ButtonSubmit = "submit"
)

Button types

View Source
const (
	//ListUnordered is <ul>
	ListUnordered = "ul"
	//ListOrdered is <ol>
	ListOrdered = "ol"
	//DescriptionList is <dl>
	DescriptionList = "dl"
)

Lists types

View Source
const (
	InputButton        = "button"
	InputCheckbox      = "checkbox"
	InputColor         = "color"
	InputDate          = "date"
	InputDatetime      = "datetime"
	InputDatetimeLocal = "datetime-local"
	InputEmail         = "email"
	InputFile          = "file"
	InputHidden        = "hidden"
	InputImage         = "image"
	InputMonth         = "month"
	InputNumber        = "number"
	InputPassword      = "password"
	InputRadio         = "radio"
	InputRange         = "range"
	InputReset         = "reset"
	InputSearch        = "search"
	InputSubmit        = "submit"
	InputTel           = "tel"
	InputText          = "text"
	InputTime          = "time"
	InputUrl           = "url"
	InputWeek          = "week"
)

Input types

View Source
const (
	//BoldText <b>
	BoldText = "b"
	//StrongText <strong>
	StrongText = "strong"
	//ItalicText <i>
	ItalicText = "i"
	//EmphasizedText <em>
	EmphasizedText = "em"
	//MarkedText <mark>
	MarkedText = "mark"
	//SmallText <small>
	SmallText = "small"
	//DeletedText <del>
	DeletedText = "del"
	//InsertedText <ins>
	InsertedText = "ins"
	//SubscriptText <sub>
	SubscriptText = "sub"
	//SuperscriptText <sup>
	SuperscriptText = "sup"
	//TitleText <title>
	TitleText = "title"
	//Paragraph <p>
	Paragraph = "p"
	//Heading1 <h1>
	Heading1 = "h1"
	//Heading2 <h2>
	Heading2 = "h2"
	//Heading3 <h3>
	Heading3 = "h3"
	//Heading4 <h4>
	Heading4 = "h4"
	//Heading5 <h5>
	Heading5 = "h5"
	//Heading6 <h6>
	Heading6 = "h6"
)

Variables

View Source
var (
	//Order counts the number of elements rendered (for generating auto-ids)
	Order int
	//Output output render target (configurable for unit-tests)
	Output bytes.Buffer
)
View Source
var (
	Ids unique //Id for widgets

)
View Source
var (
	SseData = &Sse{}
)

Functions

func ElementRender

func ElementRender(e *Element, w io.Writer) error

func EventSend

func EventSend(clientid, js string, reply chan string) event

Makes an event that can be send to the browser

func JqFuncCont

func JqFuncCont(textinner string) string

func JqIdProp

func JqIdProp(id, property string) string

func JqIdPropCont

func JqIdPropCont(id, property, textinner string) string

func JsAlert

func JsAlert(alert string) string

func JsSendFunc

func JsSendFunc(send func())

NewJs send function

func JsSendJson

func JsSendJson(json string)

NewJs send data

func SendEvent

func SendEvent(clientid, js string, reply chan string)

Sends and Event to the browser

func SendEventDataToClient

func SendEventDataToClient(eventtype string, data interface{}, renderelement *Element, sender, change *Element)

func sendEventDataToClient(eventtype string, data interface{}, elementrender *wgui.Element, sender, change *wgui.Element) {

func SetResource

func SetResource(files map[string][]byte)

=============================================

Practical  //

=============================================

Types

type Body

type Body struct {
	*Element
}

func NewBody

func NewBody() *Body

Create new header element

type CheckBoxInput

type CheckBoxInput struct {
	*Element
	// contains filtered or unexported fields
}

Checkbox represents a checkbox with label

func NewCheckBoxInput

func NewCheckBoxInput(caption string, checked bool) *CheckBoxInput

NewCheckBox creates a bootstrap checkbox with label

func (*CheckBoxInput) Checked

func (cb *CheckBoxInput) Checked() bool

Checked is true if the checkbox is checked

type Css

type Css struct {
	*Element
	Type string `json:"type"`
	Href string `json:"href"`
	Rel  string `json:"rel"`
}

func NewCss

func NewCss(href string) *Css

NewTextInput creates a new "text" input

func (*Css) AddHref

func (c *Css) AddHref(href string)

AddSrc adds a src

func (*Css) AddRel

func (c *Css) AddRel(rel string)

AddSrc adds a text

type Element

type Element struct {
	//Parent the parent element
	Parent *Element

	//Kids child elements
	Kids []*Element
	//Attributes element attributes...
	Attributes []html.Attribute
	//Object arbitrary user object that can be associated with element.
	Object interface{}

	//Hidden if true the element will not be rendered
	Hidden bool
	// contains filtered or unexported fields
}

Element represents a DOM element and its state.

func NewButton

func NewButton(caption, buttontype string) *Element

NewButton creates <button> element

func NewElement

func NewElement(tag string) *Element

NewElement creates a new HTML element

func NewElementFromNode

func NewElementFromNode(node *html.Node, em ElementsMap) *Element

NewElementFromNode creates an element from existing node

func NewLink(caption, href string) *Element

NewLink creates <a> link element

func NewMeta

func NewMeta(meta map[string]string) *Element

=============================================

<meta>  Meta //

============================================= Create Meta element

func NewStyledText

func NewStyledText(text string, style string) *Element

NewStyledText creates new text element using a specific style

func NewTableCaption

func NewTableCaption(text string) *Element

NewTableCaption adds an caption

func NewText

func NewText(text string) *Element

NewText creates new text node (without HTML tag)

func NewTextInput

func NewTextInput(value string) *Element

NewTextInput creates a new "text" input

func ParseElement

func ParseElement(innerHTML string, em ElementsMap) (*Element, error)

ParseElement parses an html with only one root tag, returns the root element.

func ParseElements

func ParseElements(r io.Reader, em ElementsMap) ([]*Element, error)

ParseElements parse an html fragment and return a list of elements

func (*Element) AddElement

func (e *Element) AddElement(elem *Element) *Element

AddElement adds a child element

func (*Element) AddElements

func (e *Element) AddElements(elems ...*Element) []*Element

AddElements adds a multiple child elements

func (*Element) AddHTML

func (e *Element) AddHTML(innerHTML string, em ElementsMap) ([]*Element, error)

AddHTML parses the provided element and adds it to the current element. Returns a list of root elements from `html`. If em is not nil, for each HTML tag that has the `id` attribute set the corresponding element will be stored in the given ElementMap.

func (*Element) Disable

func (e *Element) Disable()

Disable sets the `disabled` attribute

func (*Element) Enable

func (e *Element) Enable()

Enable unsets the `disabled` attribute

func (*Element) Find

func (e *Element) Find(id string) *Element

Find returns the kid, or offspring with a specific `id` attribute value.

func (*Element) GetAttribute

func (e *Element) GetAttribute(key string) (string, bool)

GetAttribute returns value for attribute

func (*Element) GetID

func (e *Element) GetID() string

GetID returns the value of the `id` attribute

func (*Element) GetValue

func (e *Element) GetValue() string

GetValue returns the value of the `value` attribute

func (*Element) Hide

func (e *Element) Hide()

Hide if set, will not render the element.

func (*Element) OnEvent

func (e *Element) OnEvent(event string, handler EventHandler, change *Element)

OnEvent register an DOM element event.

func (*Element) ProcessEvent

func (e *Element) ProcessEvent(event *Event)

ProcessEvent fires the event provided

func (*Element) RemoveAttribute

func (e *Element) RemoveAttribute(key string)

RemoveAttribute removes the provided attribute by name

func (*Element) RemoveElement

func (e *Element) RemoveElement(elem *Element)

RemoveElement remove a specific kid

func (*Element) RemoveElements

func (e *Element) RemoveElements()

RemoveElements remove all kids.

func (*Element) Render

func (e *Element) Render() error

Render renders the element.

func (*Element) SetAttribute

func (e *Element) SetAttribute(key, val string)

SetAttribute adds or set the attribute

func (*Element) SetAttributes

func (e *Element) SetAttributes(event *EventElement)

SetAttributes sets attributes from an event element.

func (*Element) SetClass

func (e *Element) SetClass(class string)

SetClass adds the given class name to the class attribute.

func (*Element) SetID

func (e *Element) SetID(id string)

SetID sets the `id` attribute

func (*Element) SetText

func (e *Element) SetText(text string)

SetText Sets the element to hold ONLY the provided text

func (*Element) SetValue

func (e *Element) SetValue(value string)

SetValue set the `value` attribute

func (*Element) Show

func (e *Element) Show()

Show if set, will render the element.

func (*Element) UnsetClass

func (e *Element) UnsetClass(class string)

UnsetClass removes the given class name from the class attribute

type ElementsMap

type ElementsMap map[string]*Element

ElementsMap maps Elements by their `id` attributes

func NewElementMap

func NewElementMap() ElementsMap

NewElementMap creates a new ElementMap

type Event

type Event struct {
	//Сlid   string       `json:"clientid"`
	Name   string       `json:"name"`
	Sender EventElement `json:"sender"`
	//Change Element        `json:"change"`
	Inputs []EventElement `json:"inputs"`
	Data   string         `json:"data"`
}

Event represents a DOM event

type EventElement

type EventElement struct {
	Properties map[string]string `json:"properties"`
}

EventElement represents the DOM element sending an event

func (*EventElement) GetID

func (e *EventElement) GetID() string

GetID get the id of the event sender.

func (*EventElement) GetValue

func (e *EventElement) GetValue() string

GetValue gets the value of the event sender.

type EventHandler

type EventHandler func(sender *Element, event *EventElement, change *Element)

EventHandler handler for DOM event.

type EventHandlerStruct

type EventHandlerStruct struct {
	Func   EventHandler
	Sender *Element
	Change *Element
}

Element represents a DOM element and its state.

type Fieldset

type Fieldset struct {
	*Element
	// contains filtered or unexported fields
}

func NewFieldset

func NewFieldset(legend string, content ...*Element) *Fieldset

type FileInput

type FileInput struct {
	*Element
	// contains filtered or unexported fields
}

FileButton is an file-input linked to a button

func NewFileInput

func NewFileInput(buttontype string, caption string, foldersOnly bool) *FileInput

NewFileButton creates new 'file' input with a button

func (*FileInput) GetValue

func (fb *FileInput) GetValue() string

GetValue returns the selected file value

type Form

type Form struct {
	*Element
	Name          string
	Action        string
	Method        string
	Target        string
	Enctype       string
	Autocomplete  string
	AcceptCharset string
}

func NewForm

func NewForm(action, method string) *Form
type Head struct {
	*Element
	Charset string     `json:"charset"`
	Meta    []*Element `json:"meta"`
	Css     []*Css     `json:"css"`
	Script  []*Script  `json:"script"`
}

=============================================

<head>  Head //

=============================================

func NewHead

func NewHead(charset string, metas ...*Element) *Head

Create new header element

func (*Head) AddCss

func (h *Head) AddCss(css *Css)

AddCss add a Css to header

func (*Head) AddCsss

func (h *Head) AddCsss(csss ...*Css)

AddCss adds a Css array to header

func (*Head) AddMeta

func (h *Head) AddMeta(meta *Element)

AddMeta add Meta attr/value to header

func (*Head) AddMetas

func (h *Head) AddMetas(metas ...*Element)

AddMetas adds a Metas array to header

func (*Head) AddNewCss

func (h *Head) AddNewCss(href string)

AddNewCss add new Css to header

func (*Head) AddNewMeta

func (h *Head) AddNewMeta(meta map[string]string)

AddMeta add new Meta attr/value to header

func (*Head) AddNewScript

func (h *Head) AddNewScript(src string)

AddScript add new Script to header

func (*Head) AddScript

func (h *Head) AddScript(script *Script)

AddScript add a Script to header

func (*Head) AddScripts

func (h *Head) AddScripts(scripts ...*Script)

AddScripts adds a Script array to header

type Html

type Html struct {
	*Element
	Lang string `json:"lang"`
	Head *Head  `json:"head"`
	Body *Body  `json:"body"`
}

func NewHtml

func NewHtml(lang string, head *Head, body *Body) *Html

Create new html element

type Image

type Image struct {
	*Element
	Src string
	Alt string
}

func NewImage

func NewImage(src, alt string) *Image

type Input

type Input struct {
	*Element
	// contains filtered or unexported fields
}

Checkbox represents a checkbox with label

func NewInput

func NewInput(typeinput string) *Input

NewTextInput creates a new "text" input

type Label

type Label struct {
	*Element
	For *Element
}

func NewLabel

func NewLabel(elem *Element) *Label

type List

type List struct {
	*Element
	Items ListItems
}

List is a struct for <ul>, <ol>, <dl>

func NewList

func NewList(listType string) *List

NewList creates a new list

func (*List) AddItem

func (l *List) AddItem(elem *Element) *Element

AddItem creates new LI, adds the elem to the li and returns the li to the caller.

type ListItems

type ListItems []*Element

ListItems a list of elements

type Optgroup

type Optgroup struct {
	*Element
	Options  []*Option
	Label    string
	Disabled bool
}

func NewOptgroup

func NewOptgroup(label string) *Optgroup

func (*Optgroup) AddOption

func (g *Optgroup) AddOption(o *Option)

func (*Optgroup) AddOptions

func (g *Optgroup) AddOptions(options ...*Option)

func (*Optgroup) Disable

func (g *Optgroup) Disable()

func (*Optgroup) Enable

func (g *Optgroup) Enable()

func (*Optgroup) SetLabel

func (g *Optgroup) SetLabel(label string)

type Option

type Option struct {
	*Element
	Value    string
	Text     *Element
	Selected bool
	Label    string
	Disabled bool
}

func NewOption

func NewOption(value, text string, selected bool) *Option

func NewOptions

func NewOptions(values ...string) []*Option

func (*Option) Disable

func (o *Option) Disable()

func (*Option) Enable

func (o *Option) Enable()

func (*Option) Select

func (o *Option) Select()

func (*Option) SetLabel

func (o *Option) SetLabel(label string)

func (*Option) SetText

func (o *Option) SetText(text string)

func (*Option) SetValue

func (o *Option) SetValue(value string)

func (*Option) UnSelect

func (o *Option) UnSelect()

type Progress

type Progress struct {
	*Element
	Value int
	Max   int
}

func NewProgress

func NewProgress(value, max int) *Progress

type Script

type Script struct {
	*Element
	Type string
	Src  string
	Text string
}

func NewScript

func NewScript(src string) *Script

NewScript creates a scrypt

func (*Script) AddSrc

func (s *Script) AddSrc(src string)

AddSrc adds a src

func (*Script) AddText

func (s *Script) AddText(text string)

AddSrc adds a text

type Select

type Select struct {
	*Element
	Optgroups []*Optgroup
	Options   []*Option
	Size      int
	Multiple  bool
	Name      string
	Autofocus bool
	Required  bool
	Form      *Element
	Disabled  bool
}

func NewSelect

func NewSelect(size int, multiple bool, options ...*Option) (*Select, error)

Create new combobox, multiselection og list item.

func (*Select) AddOptgroup

func (s *Select) AddOptgroup(g *Optgroup) error

func (*Select) AddOptgroups

func (s *Select) AddOptgroups(optgroups ...*Optgroup)

func (*Select) AddOption

func (s *Select) AddOption(o *Option)

func (*Select) AddOptions

func (s *Select) AddOptions(options ...*Option)

func (*Select) Disable

func (s *Select) Disable()

func (*Select) Enable

func (s *Select) Enable()

func (*Select) GetSelected

func (s *Select) GetSelected() []string

func (*Select) RemoveMultiple

func (s *Select) RemoveMultiple()

func (*Select) SetMultiple

func (s *Select) SetMultiple()

func (*Select) SetSize

func (s *Select) SetSize(size int)

type Sse

type Sse struct {
	velox.State
	sync.Mutex
	Type     string      `json:"type"` // "innerhtml", "setvalue", "jseval", "jsalert", "json", "jqid"
	SenderId string      `json:"senderid"`
	ChangeId string      `json:"changeid"`
	Data     interface{} `json:"data"`
}

type Table

type Table struct {
	*Element
	Head     *TableHead
	Body     *TableBody
	Footer   *TableFooter
	Colgroup *TableColgroup
	Caption  *Element
	Rows     []*TableRow
}

Table represents <table>

func NewTable

func NewTable(rows ...*TableRow) *Table

NewTable creates a new table with type

func QuickTable

func QuickTable(data map[string]interface{}) *Table

QuickTable creates a table from a given map with key-value pairs

func (*Table) AddBody

func (t *Table) AddBody(b *TableBody)

AddBody adds a body

func (*Table) AddCaption

func (t *Table) AddCaption(c *Element)

AddCaption adds a caption

func (*Table) AddColgroup

func (t *Table) AddColgroup(c *TableColgroup)

AddColgroup adds a head

func (*Table) AddFooter

func (t *Table) AddFooter(f *TableFooter)

AddFooter adds a footer

func (*Table) AddHead

func (t *Table) AddHead(h *TableHead)

AddHead adds a head

func (*Table) AddRow

func (t *Table) AddRow(row *TableRow)

AddRow adds a row

func (*Table) AddRows

func (t *Table) AddRows(rows ...*TableRow)

AddRows adds a rows

type TableBody

type TableBody struct {
	*Element
	Rows []*TableRow
}

TableBody represents

func NewTableBody

func NewTableBody(rows ...*TableRow) *TableBody

NewTableBody adds body

func (*TableBody) AddBodyRow

func (b *TableBody) AddBodyRow(row *TableRow)

AddBodyRow adds a row

func (*TableBody) AddBodyRows

func (b *TableBody) AddBodyRows(rows ...*TableRow)

AddBodyRows adds a rows

type TableCell

type TableCell struct {
	*Element
	Header  bool
	Colspan int
	Rowspan int
	Content *Element
}

TableCell represents a <td>

func NewTableCell

func NewTableCell(header bool, colspan, rowspan int, content *Element) *TableCell

NewTableCell creates and adds new cell

type TableCol

type TableCol struct {
	*Element
	Span  int
	Style string
}

TableCol represents a <col>

func NewTableCol

func NewTableCol(span int, style string) *TableCol

NewTableCol creates a new table colgroup col

type TableColgroup

type TableColgroup struct {
	*Element
	Span int
	Cols []*TableCol
}

TableColgroup represents a <colgroup>

func NewTableColgroup

func NewTableColgroup(span int, cols ...*TableCol) *TableColgroup

NewTableColgroup adds an colgroup row

func (*TableColgroup) AddColgroupCol

func (c *TableColgroup) AddColgroupCol(col *TableCol)

AddColgroupCol adds a col

func (*TableColgroup) AddColgroupCols

func (c *TableColgroup) AddColgroupCols(cols ...*TableCol)

AddColgroupCols adds a cols

type TableFooter

type TableFooter struct {
	*Element
	Rows []*TableRow
}

TableFooter

func NewTableFooter

func NewTableFooter(rows ...*TableRow) *TableFooter

NewTableFooter adds footer

func (*TableFooter) AddFooterRow

func (f *TableFooter) AddFooterRow(row *TableRow)

AddFooterRow adds a row

func (*TableFooter) AddFooterRows

func (f *TableFooter) AddFooterRows(rows ...*TableRow)

AddFooterRows adds a rows

type TableHead

type TableHead struct {
	*Element
	Rows []*TableRow
}

TableHead

func NewTableHead

func NewTableHead(rows ...*TableRow) *TableHead

NewTableHead adds an header row

func (*TableHead) AddHeadRow

func (h *TableHead) AddHeadRow(row *TableRow)

AddHeadRow adds a row

func (*TableHead) AddHeadRows

func (h *TableHead) AddHeadRows(rows ...*TableRow)

AddHeadRows adds a rows

type TableRow

type TableRow struct {
	*Element
	Cells []*TableCell
}

TableRow represents a <tr>

func NewTableRow

func NewTableRow(cells ...*TableCell) *TableRow

NewTableRow creates a new table row

func (*TableRow) AddCell

func (tr *TableRow) AddCell(cell *TableCell)

AddCells adds cell to a table row

func (*TableRow) AddCells

func (tr *TableRow) AddCells(cells ...*TableCell)

AddCells adds cells to a table row

type Textarea

type Textarea struct {
	*Element
	Rows  int
	Cols  int
	Value string
}

func NewTextarea

func NewTextarea(rows, cols int, value string) *Textarea

Multiline text input

func (*Textarea) SetValue

func (t *Textarea) SetValue(s string)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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