trees

package
v0.0.0-...-a33cf17 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2016 License: MIT Imports: 6 Imported by: 5

Documentation

Overview

Trees contain the rendering structures that provide the markup generation for haiku

Index

Constants

This section is empty.

Variables

View Source
var ErrNotAttr = errors.New("Value type is not n Attribute type")

ErrNotAttr relating to the attribute types

View Source
var ErrNotElem = errors.New("Markup is not a *Element type")

ErrNotElem is returned when the markup type does not match the *Element type

View Source
var ErrNotFound = errors.New("Item not found")

ErrNotFound relating to the attribute types

View Source
var ErrNotMarkup = errors.New("Value does not match Markup interface types")

ErrNotMarkup is returned when the value/pointer type does not match the Markup interface type

View Source
var ErrNotStyle = errors.New("Value type is not a Style type")

Errors relating to the style types

View Source
var ErrNotText = errors.New("Markup is not a *Text type")

ErrNotText is returned when the markup type is not a text markup

View Source
var SimpleAttrWriter = &AttrWriter{}

SimpleAttrWriter provides a basic attribute writer

SimpleElementWriter provides a default writer using the basic attribute and style writers

View Source
var SimpleMarkupWriter = NewMarkupWriter(SimpleElementWriter)

SimpleMarkupWriter provides a basic markup writer for handling the different markup elements

View Source
var SimpleStyleWriter = &StyleWriter{}

SimpleStyleWriter provides a basic style writer

View Source
var SimpleTextWriter = &TextWriter{}

SimpleTextWriter provides a basic text writer

Functions

func AttrContains

func AttrContains(e Markup, f, val string) bool

AttrContains returns the attributes that have the specified text within the naming convention and if it also contains the set val if not an empty "", NOTE: string.Contains is used

func Augment

func Augment(root Markup, m ...Markup)

Augment adds new markup to an the root if its Element

func EqualAttributes

func EqualAttributes(e, em Markup) bool

EqualAttributes returns true/false if the elements and the giving markup have equal attribute

func RandString

func RandString(n int) string

RandString generates a set of random numbers of a set length

func ReconcileEvents

func ReconcileEvents(e, em Markup)

ReconcileEvents checks through two markup events against each other and if it finds any disparity marks event objects as Removed

func StyleContains

func StyleContains(e Markup, f, val string) bool

StyleContains returns the styles that contain the specified name and if the val is not empty then that contains the specified value also, note that strings NOTE: string.Contains is used

Types

type Appliable

type Appliable interface {
	Apply(*Element)
}

Appliable define the interface specification for applying changes to elements elements in tree

type AttrPrinter

type AttrPrinter interface {
	Print([]*Attribute) string
}

AttrPrinter defines a printer interface for writing out a Attribute objects into a string form

type AttrWriter

type AttrWriter struct{}

AttrWriter provides a concrete struct that meets the AttrPrinter interface

func (*AttrWriter) Print

func (m *AttrWriter) Print(a []*Attribute) string

Print returns a stringed repesentation of the attribute object

type Attribute

type Attribute struct {
	Name  string
	Value string
}

Attribute define the struct for attributes

func GetAttr

func GetAttr(e Markup, f string) (*Attribute, error)

GetAttr returns the attribute with the specified tag name

func GetAttrs

func GetAttrs(e Markup, f, val string) []*Attribute

GetAttrs returns the attributes that have the specified text within the naming convention and if it also contains the set val if not an empty "", NOTE: string.Contains is used

func NewAttr

func NewAttr(name, val string) *Attribute

NewAttr returns a new attribute instance

func (*Attribute) Apply

func (a *Attribute) Apply(e *Element)

Apply applies a set change to the giving element attributes list

func (*Attribute) Clone

func (a *Attribute) Clone() *Attribute

Clone replicates the attribute into a unique instance

func (*Attribute) Reconcile

func (a *Attribute) Reconcile(m *Attribute) bool

Reconcile checks if the attribute matches then upgrades its value.

type Attributes

type Attributes interface {
	Attributes() []*Attribute
}

Attributes interface defines a type that has Attributes

type ClassList

type ClassList struct {
	// contains filtered or unexported fields
}

ClassList defines the struct for a lists of classes.

func (*ClassList) Add

func (c *ClassList) Add(class string)

Add adds a class name into the lists.

func (*ClassList) Apply

func (c *ClassList) Apply(e *Element)

Apply checks for a class attribute

func (*ClassList) Clone

func (c *ClassList) Clone() *ClassList

Clone replicates the lists of classnames.

func (*ClassList) Reconcile

func (c *ClassList) Reconcile(m *ClassList) bool

Reconcile checks each item against the given lists and replaces/add any missing item.

func (*ClassList) Remove

func (c *ClassList) Remove(class string)

Remove removes a class from into the lists.

type Clonable

type Clonable interface {
	Clone() Markup
}

Clonable defines an interface for objects that can be cloned

type Element

type Element struct {
	Mutation
	// contains filtered or unexported fields
}

Element represent a concrete implementation of a element node

func NewElement

func NewElement(tag string, hasNoEndingTag bool) *Element

NewElement returns a new element instance giving the specificed name

func NewText

func NewText(txt string) *Element

NewText returns a new Text instance element TODO: should we allow styles here ?

func (*Element) AddChild

func (e *Element) AddChild(em Markup)

AddChild adds a new markup as the children of this element

func (*Element) Apply

func (e *Element) Apply(em *Element)

Apply adds the giving element into the current elements children tree

func (*Element) Attributes

func (e *Element) Attributes() []*Attribute

Attributes return the internal attribute list of the element

func (*Element) Augment

func (e *Element) Augment(m ...Markup)

Augment provides a generic method for markup addition

func (*Element) AutoClosed

func (e *Element) AutoClosed() bool

AutoClosed returns true/false if this element uses a </> or a <></> tag convention

func (*Element) Children

func (e *Element) Children() []Markup

Children returns the children list for the element

func (*Element) CleanRemoved

func (e *Element) CleanRemoved()

CleanRemoved removes all the chilren marked as removed

func (*Element) Clone

func (e *Element) Clone() Markup

Clone makes a new copy of the markup structure

func (*Element) Empty

func (e *Element) Empty()

Empty resets the elements children list as 0 length

func (*Element) EventID

func (e *Element) EventID() string

EventID returns the selector used for tagging events for a markup.

func (*Element) Events

func (e *Element) Events() []*Event

Events return the elements events

func (*Element) LoadEvents

func (e *Element) LoadEvents()

LoadEvents loads up the events registered by this and by its children into each respective available events managers

func (*Element) Name

func (e *Element) Name() string

Name returns the tag name of the element

func (*Element) Reconcile

func (e *Element) Reconcile(em Markup) bool

Reconcile takes a old markup and reconciles its uid and its children with the new formation,it returns a true/false telling the parent if the children swapped hashes

the reconcilation uses the order in which elements are added, if the order and element types are kept,

then the uid are swapped else it firsts checks the element type and if not the same adds the old one into the new list as removed then continues the check. The system takes position of elements in the old and new as very important and I cant stress this enough, "Element Positioning" in the markup are very important, if a Anchor was the first element in the old render and the next pass returns a Div in the new render, the Anchor will be marked as removed and will be removed from the dom and ignored by the writers. When two elements position are same and their types are the same then a checkup process is doing using the elements attributes, this is done to determine if the hash value of the new should be swapped with the old. We can use style properties here because they are the most volatile of the set and will periodically be either changed and returned to normal values eg display: none to display: block and vise-versa, so only attributes are used in the check process

func (*Element) Remove

func (e *Element) Remove()

Remove sets the markup as removable and adds a 'haikuRemoved' attribute to it

func (*Element) Styles

func (e *Element) Styles() []*Style

Styles return the internal style list of the element

func (*Element) TextContent

func (e *Element) TextContent() string

TextContent returns the elements text value if its a text type else an empty string

func (*Element) UseEventManager

func (e *Element) UseEventManager(man domevents.EventManagers) bool

UseEventManager adds a eventmanager into the markup and if not available before automatically registers the events with it,once an event manager is registered to it,it will and can not be changed

type ElementWriter

type ElementWriter struct {
	// contains filtered or unexported fields
}

ElementWriter writes out the element out as a string matching the html tag rules

func NewElementWriter

func NewElementWriter(aw AttrPrinter, sw StylePrinter, tw TextPrinter) *ElementWriter

NewElementWriter returns a new writer for Element objects

func (*ElementWriter) AllowRemoved

func (m *ElementWriter) AllowRemoved()

AllowRemoved is used to switch off the check to allow rendering of elements set as removed

func (*ElementWriter) DisallowRemoved

func (m *ElementWriter) DisallowRemoved()

DisallowRemoved is used to switch off the check to allow rendering of elements set as removed

func (*ElementWriter) Print

func (m *ElementWriter) Print(e *Element) string

Print returns the string representation of the element

type Event

type Event struct {
	Meta *domevents.EventMetable
	Fx   domevents.EventHandler
	// contains filtered or unexported fields
}

Event provide a meta registry for helps in registering events for dom markups which is translated to the nodes themselves

func NewEvent

func NewEvent(etype, eselector string, efx EventHandler) *Event

NewEvent returns a event object that allows registering events to eventlisteners

func (*Event) Apply

func (e *Event) Apply(em *Element)

Apply adds the event into the elements events lists

func (*Event) Clone

func (e *Event) Clone() *Event

Clone replicates the style into a unique instance

func (*Event) PreventDefault

func (e *Event) PreventDefault() *Event

PreventDefault will return itself and set PreventDefault to true

func (*Event) StopImmediatePropagation

func (e *Event) StopImmediatePropagation() *Event

StopImmediatePropagation will return itself and set StopPropagation to true

func (*Event) StopPropagation

func (e *Event) StopPropagation() *Event

StopPropagation will return itself and set StopPropagation to true

type EventHandler

type EventHandler func(domevents.Event, Markup)

EventHandler provides a custom event handler which allows access to the markup producing the event.

type Eventers

type Eventers interface {
	LoadEvents()
	UseEventManager(domevents.EventManagers) bool
}

Eventers provide an interface type for elements able to register and load event managers.

type Events

type Events interface {
	Events() []*Event
}

Events provide an interface for markup event addition system

type Markup

type Markup interface {
	Appliable
	Events
	Mutation
	Styles
	Attributes
	Clonable
	MarkupChildren
	Reconcilable
	Eventers

	AutoClosed() bool
	TextContent() string

	Name() string
	EventID() string
	Augment(...Markup)

	Empty()

	CleanRemoved()
}

Markup provide a basic specification type of how a element resolves its content

func DeepElementsUsingStyle

func DeepElementsUsingStyle(e Markup, f, val string, depth int) []Markup

DeepElementsUsingStyle returns the children within the element matching the style restrictions passed allowing control of search depth NOTE: is uses StyleContains WARNING: depth must start at 1

func DeepElementsWithAttr

func DeepElementsWithAttr(e Markup, f, val string, depth int) []Markup

DeepElementsWithAttr returns the children within the element matching the attributes restrictions passed allowing control of search depth NOTE: is uses Element.AttrContains WARNING: depth must start at 1

func DeepElementsWithTag

func DeepElementsWithTag(e Markup, f string, depth int) []Markup

DeepElementsWithTag returns elements matching the tag type in the parent markup and depending on the depth will walk down other children within the children. WARNING: depth must start at 1

func ElementsUsingStyle

func ElementsUsingStyle(e Markup, f, val string) []Markup

ElementsUsingStyle returns the children within the element matching the stlye restrictions passed. NOTE: is uses StyleContains

func ElementsWithAttr

func ElementsWithAttr(e Markup, f, val string) []Markup

ElementsWithAttr returns the children within the element matching the stlye restrictions passed. NOTE: is uses AttrContains

func ElementsWithTag

func ElementsWithTag(e Markup, f string) []Markup

ElementsWithTag returns elements matching the tag type in the parent markup children list only without going deeper into children's children lists

type MarkupChildren

type MarkupChildren interface {
	AddChild(Markup)
	Children() []Markup
}

MarkupChildren defines the interface of an element that has children

type MarkupWriter

type MarkupWriter interface {
	Write(Markup) (string, error)
}

MarkupWriter defines a printer interface for writing out a markup object into a string form

func NewMarkupWriter

func NewMarkupWriter(em *ElementWriter) MarkupWriter

NewMarkupWriter returns a new markup instance

type Mutable

type Mutable struct {
	// contains filtered or unexported fields
}

Mutable is a base implementation of the Mutation interface{}

func NewMutable

func NewMutable() *Mutable

NewMutable returns a new mutable instance

func (*Mutable) Hash

func (m *Mutable) Hash() string

Hash returns the current hash of the mutable

func (*Mutable) Remove

func (m *Mutable) Remove()

Remove marks this mutable as removed making this irreversible

func (*Mutable) Removed

func (m *Mutable) Removed() bool

Removed returns true/false if the mutable is marked removed

func (*Mutable) UID

func (m *Mutable) UID() string

UID returns the current uid of the mutable

func (*Mutable) UpdateHash

func (m *Mutable) UpdateHash()

UpdateHash updates the mutable hash value

type MutableBackdoor

type MutableBackdoor struct {
	M Mutation
}

MutableBackdoor grants access to a mutable swapUID and swapHash methods.

func (MutableBackdoor) SwapHash

func (m MutableBackdoor) SwapHash(hash string)

SwapHash swaps the hash of the internal mutable.

func (MutableBackdoor) SwapUID

func (m MutableBackdoor) SwapUID(uid string)

SwapUID swaps the uid of the internal mutable.

type Mutation

type Mutation interface {
	UID() string
	Hash() string

	Removed() bool
	Remove()
	UpdateHash()
	// contains filtered or unexported methods
}

Mutation defines the capability of an element to state its state if mutation occured

type Reconcilable

type Reconcilable interface {
	Reconcile(Markup) bool
}

Reconcilable defines the interface of markups that can reconcile their content against another

type Style

type Style struct {
	Name  string
	Value string
}

Style define the style specification for element styles

func GetStyle

func GetStyle(e Markup, f string) (*Style, error)

GetStyle returns the style with the specified tag name

func GetStyles

func GetStyles(e Markup, f, val string) []*Style

GetStyles returns the styles that contain the specified name and if not empty that contains the specified value also, note that strings NOTE: string.Contains is used when checking value parameter if present

func NewStyle

func NewStyle(name, val string) *Style

NewStyle returns a new style instance

func (*Style) Apply

func (s *Style) Apply(e *Element)

Apply applies a set change to the giving element style list

func (*Style) Clone

func (s *Style) Clone() *Style

Clone replicates the style into a unique instance

func (*Style) Reconcile

func (s *Style) Reconcile(m *Style) bool

Reconcile checks if the style matches then upgrades its value.

type StylePrinter

type StylePrinter interface {
	Print([]*Style) string
}

StylePrinter defines a printer interface for writing out a style objects into a string form

type StyleWriter

type StyleWriter struct{}

StyleWriter provides a concrete struct that meets the AttrPrinter interface

func (*StyleWriter) Print

func (m *StyleWriter) Print(s []*Style) string

Print returns a stringed repesentation of the style object

type Styles

type Styles interface {
	Styles() []*Style
}

Styles interface defines a type that has Styles

type TextPrinter

type TextPrinter interface {
	Print(Markup) string
}

TextPrinter defines a printer interface for writing out a text type markup into a string form

type TextWriter

type TextWriter struct{}

TextWriter writes out the text element/node for the vdom into a string

func (*TextWriter) Print

func (m *TextWriter) Print(t Markup) string

Print returns the string representation of the text object

Directories

Path Synopsis
Package events defines the event binding system for Haiku(https://github.com/influx6/Haiku)
Package events defines the event binding system for Haiku(https://github.com/influx6/Haiku)

Jump to

Keyboard shortcuts

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