gohtml

package module
v1.2.4 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2022 License: GPL-2.0 Imports: 2 Imported by: 0

README

GoHTML!

A package to help you write WASM, or HTML inside of Golang!

Installation

Easily install with the following command:

go get github.com/Nigel2392/gohtml

Usage

Example of form submissions:
var body = g.Div()
var form = body.Form()
form.Method("POST").Action("")
form.Label("Name")
form.Input("text")                       // Type
form.Input("text", "name")               // Type, name and id
form.Input("submit", "submit", "Submit") // Type, name and display text
var _, rdy = form.WasmFormSubmit(func(data map[string]string) {
	println(fmt.Sprintf("Form submitted: %v", data))
})
// Generate the HTML inside of wasm, append it to and existing html element.
body.WasmGenerate(elems.ID_MAIN_CONTENT)
// Once the html is appended, we can enable the eventlistener.
rdy.Finalize()
Simple program for fetching repositories from github:
var WAITER = make(chan struct{})
var Application = js.Global().Get("document").Call("getElementById", "app")
var URLS = elems.URLs{
	{
		Name: "Home",
		URL:  "/",
		Icon: "fa fa-home",
		CallBack: func(body *elems.Element, args []js.Value, url *url.URL) {
			var loader = loader.NewLoader(elems.ID_MAIN_CONTENT)
			var url_to_fetch = "https://api.github.com/users/Nigel2392/repos"
			var reqEdit = func(rq *http.Request) { rq.Header.Set("Accept", "application/vnd.github.v3+json") }
			loader.RunHTTP(url_to_fetch, "GET", reqEdit, func(resp *http.Response) error {
				var repos = make([]struct {
					Name        string `json:"name"`
					Private     bool   `json:"private"`
					Description string `json:"description"`
					HTMLURL     string `json:"url"`
				}, 0)
				if err := json.NewDecoder(resp.Body).Decode(&repos); err != nil {
					return err
				}
				var table = body.Table().Class("table table-striped table-hover")
				var thead = table.Thead()
				var tbody = table.Tbody()
				var headRow = thead.Tr()
				headRow.Th("Name")
				headRow.Th("Description")
				var links elems.Elements = make(elems.Elements, 0)
				for _, repo := range repos {
					current_row := tbody.Tr()
					links = append(links, current_row.Td().A(repo.Name+" ", repo.HTMLURL).Href(repo.HTMLURL))
					current_row.Td().P(repo.Description)
				}
				body.WasmGenerate(elems.ID_MAIN_CONTENT)
				return nil
			})
		},
	},
	{
		Name: "About",
		URL:  "/about",
		Icon: "fa fa-info",
		CallBack: func(body *elems.Element, args []js.Value, url *url.URL) {
			form := body.Form()
			form.Method("POST").Action("")
			form.Label("Name").Class("form-label")
			form.Input("text", "name", "Name").Class("form-control mb-2")
			form.Input("submit", "submit", "Submit").Class("btn btn-primary mb-2")
			var _, rdy = form.WasmFormSubmit(func(data map[string]string) {
				println(fmt.Sprintf("Form submitted: %v", data))
			})
			body.WasmGenerate(elems.ID_MAIN_CONTENT)
			rdy.Finalize()
		},
	},
}

func main() {
    // Create a navbar
	var header, app, urlElems = elems.SideNavBar(URLS)
    // Listen for clicks on the navbar anchor tags
	var rdy = urlElems.ActiveToggleListener(paginator(app, URLS))
    // Generate the HTML inside of wasm, append it to and existing html element.
    header.WasmGenerate("app")
    // Once the html is appended, we can enable the eventlistener.
	rdy.Finalize()
    // Lock the main thread to prevent the program from exiting.
	<-WAITER
}

func paginator(app *elems.Element, urls elems.URLs) func(this js.Value, args []js.Value, url *url.URL) interface{} {
	return func(this js.Value, args []js.Value, url *url.URL) interface{} {
		app.WasmClearInnerHTML()
		var container = app.Div()
        // Get a URL to use it's callback function.
		if u, err := URLS.GetURL(url.Path); err != nil {
			container.Style("text-align:center").H1("404 Page Not Found")
		} else {
			u.CallBack(container, append([]js.Value{this}, args...), url)
		}
		return nil
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HTML

type HTML struct {
	Title        string
	Head         *elems.Element
	BodyElements *elems.Element
	Buffer       elems.Buffer
}

func NewHTML

func NewHTML(title string, buf ...elems.Buffer) *HTML

func (*HTML) A

func (h *HTML) A(t ...string) *elems.Element

func (*HTML) Abbr

func (h *HTML) Abbr(t ...string) *elems.Element

func (*HTML) Add

func (h *HTML) Add(e ...*elems.Element) *elems.Element

func (*HTML) AddHead

func (h *HTML) AddHead(e ...*elems.Element) *elems.Element

func (*HTML) Address

func (h *HTML) Address(t ...string) *elems.Element

func (*HTML) Area

func (h *HTML) Area(t ...string) *elems.Element

func (*HTML) Article

func (h *HTML) Article(t ...string) *elems.Element

func (*HTML) Aside

func (h *HTML) Aside(t ...string) *elems.Element

func (*HTML) Audio

func (h *HTML) Audio(t ...string) *elems.Element

func (*HTML) B

func (h *HTML) B(t ...string) *elems.Element

func (*HTML) Bdi

func (h *HTML) Bdi(t ...string) *elems.Element

func (*HTML) Bdo

func (h *HTML) Bdo(t ...string) *elems.Element

func (*HTML) Blockquote

func (h *HTML) Blockquote(t ...string) *elems.Element

func (*HTML) Body

func (h *HTML) Body(t ...string) *elems.Element

func (*HTML) Br

func (h *HTML) Br(t ...string) *elems.Element

func (*HTML) Button

func (h *HTML) Button(t ...string) *elems.Element

func (*HTML) Canvas

func (h *HTML) Canvas(t ...string) *elems.Element

func (*HTML) Caption

func (h *HTML) Caption(t ...string) *elems.Element

func (*HTML) Cite

func (h *HTML) Cite(t ...string) *elems.Element

func (*HTML) Code

func (h *HTML) Code(t ...string) *elems.Element

func (*HTML) Col

func (h *HTML) Col(t ...string) *elems.Element

func (*HTML) Colgroup

func (h *HTML) Colgroup(t ...string) *elems.Element

func (*HTML) Command

func (h *HTML) Command(t ...string) *elems.Element

func (*HTML) Datalist

func (h *HTML) Datalist(t ...string) *elems.Element

func (*HTML) Dd

func (h *HTML) Dd(t ...string) *elems.Element

func (*HTML) Del

func (h *HTML) Del(t ...string) *elems.Element

func (*HTML) Details

func (h *HTML) Details(t ...string) *elems.Element

func (*HTML) Dfn

func (h *HTML) Dfn(t ...string) *elems.Element

func (*HTML) Div

func (h *HTML) Div(t ...string) *elems.Element

func (*HTML) Dl

func (h *HTML) Dl(t ...string) *elems.Element

func (*HTML) Dt

func (h *HTML) Dt(t ...string) *elems.Element

func (*HTML) Em

func (h *HTML) Em(t ...string) *elems.Element

func (*HTML) Embed

func (h *HTML) Embed(t ...string) *elems.Element

func (*HTML) Fieldset

func (h *HTML) Fieldset(t ...string) *elems.Element

func (*HTML) Figcaption

func (h *HTML) Figcaption(t ...string) *elems.Element

func (*HTML) Figure

func (h *HTML) Figure(t ...string) *elems.Element

func (*HTML) Footer

func (h *HTML) Footer(t ...string) *elems.Element

func (*HTML) Form

func (h *HTML) Form(t ...string) *elems.Element

func (*HTML) H1

func (h *HTML) H1(t ...string) *elems.Element

func (*HTML) H2

func (h *HTML) H2(t ...string) *elems.Element

func (*HTML) H3

func (h *HTML) H3(t ...string) *elems.Element

func (*HTML) H4

func (h *HTML) H4(t ...string) *elems.Element

func (*HTML) H5

func (h *HTML) H5(t ...string) *elems.Element

func (*HTML) H6

func (h *HTML) H6(t ...string) *elems.Element

func (*HTML) HTML added in v1.0.1

func (h *HTML) HTML(templateData any, buffer ...elems.Buffer) string

Render to template.

func (*HTML) Header

func (h *HTML) Header(t ...string) *elems.Element

func (*HTML) Hr

func (h *HTML) Hr(t ...string) *elems.Element

func (*HTML) I

func (h *HTML) I(t ...string) *elems.Element

func (*HTML) Iframe

func (h *HTML) Iframe(t ...string) *elems.Element

func (*HTML) Img

func (h *HTML) Img(t ...string) *elems.Element

func (*HTML) Input

func (h *HTML) Input(t ...string) *elems.Element

func (*HTML) Ins

func (h *HTML) Ins(t ...string) *elems.Element

func (*HTML) Kbd

func (h *HTML) Kbd(t ...string) *elems.Element

func (*HTML) Keygen

func (h *HTML) Keygen(t ...string) *elems.Element

func (*HTML) Label

func (h *HTML) Label(t ...string) *elems.Element

func (*HTML) Legend

func (h *HTML) Legend(t ...string) *elems.Element

func (*HTML) Li

func (h *HTML) Li(t ...string) *elems.Element

func (*HTML) Main

func (h *HTML) Main(t ...string) *elems.Element

func (*HTML) Map

func (h *HTML) Map(t ...string) *elems.Element

func (*HTML) Mark

func (h *HTML) Mark(t ...string) *elems.Element

func (*HTML) Menu

func (h *HTML) Menu(t ...string) *elems.Element

func (*HTML) Meter

func (h *HTML) Meter(t ...string) *elems.Element

func (*HTML) Nav

func (h *HTML) Nav(t ...string) *elems.Element

func (*HTML) Object

func (h *HTML) Object(t ...string) *elems.Element

func (*HTML) Ol

func (h *HTML) Ol(t ...string) *elems.Element

func (*HTML) Optgroup

func (h *HTML) Optgroup(t ...string) *elems.Element

func (*HTML) Option

func (h *HTML) Option(t ...string) *elems.Element

func (*HTML) Output

func (h *HTML) Output(t ...string) *elems.Element

func (*HTML) P

func (h *HTML) P(t ...string) *elems.Element

func (*HTML) Param

func (h *HTML) Param(t ...string) *elems.Element

func (*HTML) Pre

func (h *HTML) Pre(t ...string) *elems.Element

func (*HTML) Progress

func (h *HTML) Progress(t ...string) *elems.Element

func (*HTML) Q

func (h *HTML) Q(t ...string) *elems.Element

func (*HTML) Release

func (h *HTML) Release()

func (*HTML) RenderBuffer

func (h *HTML) RenderBuffer(buffer elems.Buffer, templateData any) elems.Buffer

func (*HTML) Rp

func (h *HTML) Rp(t ...string) *elems.Element

func (*HTML) Rt

func (h *HTML) Rt(t ...string) *elems.Element

func (*HTML) Ruby

func (h *HTML) Ruby(t ...string) *elems.Element

func (*HTML) S

func (h *HTML) S(t ...string) *elems.Element

func (*HTML) Samp

func (h *HTML) Samp(t ...string) *elems.Element

func (*HTML) Script

func (h *HTML) Script(src string, typ ...string) *elems.Element

func (*HTML) ScriptInline

func (h *HTML) ScriptInline(sourceCode string, typ ...string) *elems.Element

func (*HTML) ScriptOnLoad added in v1.1.6

func (h *HTML) ScriptOnLoad(sourceCode string, typ ...string) *elems.Element

func (*HTML) Section

func (h *HTML) Section(t ...string) *elems.Element

func (*HTML) Select

func (h *HTML) Select(t ...string) *elems.Element

func (*HTML) SetTitle

func (h *HTML) SetTitle(str string)

func (*HTML) Small

func (h *HTML) Small(t ...string) *elems.Element

func (*HTML) Source

func (h *HTML) Source(t ...string) *elems.Element

func (*HTML) Span

func (h *HTML) Span(t ...string) *elems.Element

func (*HTML) String

func (h *HTML) String() string

func (*HTML) Strong

func (h *HTML) Strong(t ...string) *elems.Element

func (*HTML) Style

func (h *HTML) Style(sourceCode string) *elems.Element

func (*HTML) StyleSheet

func (h *HTML) StyleSheet(href string, rel string) *elems.Element

func (*HTML) Sub

func (h *HTML) Sub(t ...string) *elems.Element

func (*HTML) Summary

func (h *HTML) Summary(t ...string) *elems.Element

func (*HTML) Sup

func (h *HTML) Sup(t ...string) *elems.Element

func (*HTML) Table

func (h *HTML) Table(t ...string) *elems.Element

func (*HTML) Tbody

func (h *HTML) Tbody(t ...string) *elems.Element

func (*HTML) Td

func (h *HTML) Td(t ...string) *elems.Element

func (*HTML) Text

func (h *HTML) Text(t ...string) *elems.Element

func (*HTML) Textarea

func (h *HTML) Textarea(t ...string) *elems.Element

func (*HTML) Tfoot

func (h *HTML) Tfoot(t ...string) *elems.Element

func (*HTML) Th

func (h *HTML) Th(t ...string) *elems.Element

func (*HTML) Thead

func (h *HTML) Thead(t ...string) *elems.Element

func (*HTML) Time

func (h *HTML) Time(t ...string) *elems.Element

func (*HTML) Tr

func (h *HTML) Tr(t ...string) *elems.Element

func (*HTML) Track

func (h *HTML) Track(t ...string) *elems.Element

func (*HTML) U

func (h *HTML) U(t ...string) *elems.Element

func (*HTML) Ul

func (h *HTML) Ul(t ...string) *elems.Element

func (*HTML) Var

func (h *HTML) Var(t ...string) *elems.Element

func (*HTML) Video

func (h *HTML) Video(t ...string) *elems.Element

func (*HTML) Wbr

func (h *HTML) Wbr(t ...string) *elems.Element

Directories

Path Synopsis
Urls for normal build
Urls for normal build

Jump to

Keyboard shortcuts

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