builder

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2021 License: MIT Imports: 3 Imported by: 4

Documentation

Overview

Package builder provides a programatic way of building the HTML tree structure in a way that can be more easily read without the documenet structure becoming a right leaning mess, such as:

&Doc{
	Head: &Head{},
	Body: &Body{
		Elements: []Element{
			&Div{
				Elements: []Element{
					&Table{
						Elements: []TableElement{
							&TR{
								Elements: []TRElement{
									&TD{},
									&TD{},
								},
							},
						},
					},
				},
			},
		},
	},
}

With our builder, this becomes

b := NewHTML(&Head{}, &Body{})

b.Into(&Div{}) // Adds the div and moves into the div
b.Into(&Table{}) // Adds the table and moves into the table
b.Into(&TR{}) // Adds the table row and moves into the table row
b.Add(&TD{}, &TD{})  // Adds two table role elements, but stays in the row.
b.Up() // We now move back to the table, if we called b.Up() again, we'd be at the div

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HTML

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

HTML provides a builder for constucting HTML objects that can be rendered. This attempts to allow tooling and other software constructs to be made that aren't right leaning pages of text.

func NewHTML

func NewHTML(head *html.Head, body *html.Body) *HTML

NewHTML creates a new HTML buider.

func (*HTML) Add

func (h *HTML) Add(elements ...html.Element)

Add adds an element into the focus object, the object focus is not changed. If there is no object in focus this element is added to the doc's body.

func (*HTML) AddHead

func (h *HTML) AddHead(elements ...html.Element)

AddHead adds elements to the doc's head.

func (*HTML) Doc

func (h *HTML) Doc() *html.Doc

Doc returns the *html.Doc.

func (*HTML) Into

func (h *HTML) Into(element html.Element) html.Element

Into inserts element into the current focus object and then changes the focus object to this element. It returns the focus element.

func (*HTML) Up

func (h *HTML) Up() *HTML

Up changes the current focus object to that object's parent. If there is no parent then the focus will become the doc's body. If the focus is already the doc's body, this will panic. Returns the HTML objects so you can call Up().Up() .

Jump to

Keyboard shortcuts

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