hb

package module
v1.72.1 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2024 License: MIT Imports: 7 Imported by: 9

README

HTML Builder Open in Gitpod

tests Go Report Card PkgGoDev

Unpretentious short and sweet declarative HTML Builder.

Demos can be found on: https://golangui.com

Benefits

  • Valid (X)HTML
  • Programmatically generate (X)HTML
  • Pure GO code
  • No need to transfer HTML files
  • No need to embed HTML files
  • No need for using template files
  • Full reuse of the code
  • Fully eliminates the quirks of the standard template package
  • Great for email templates too
  • Nice looking fluent interface
  • Easy to extend and build your own flavor on top
  • Dynamic UI with conditions
  • Conditional attributes
  • Lots of demos and examples
  • Works with any CSS library
  • Works with any JS library
  • Out of the box support for Alpine.js
  • Out of the box support for HTMX

Example

  • Section containing div container (Bootstrap) with a message "Hello world"
import "github.com/gouniverse/hb"
	
// 1. Create a div container with "Hello world" message
div := hb.NewDiv().Class("container").Text("Hello world")

// 2. Create a section with padding of 40px containing the container
section := hb.NewSection().Style("padding:40px;").Child(div)

// 3. Render to HTML to display
html := section.ToHTML()

!!! For more examples look below in the README

Installation

go get -u github.com/gouniverse/hb

Implemented Tag Shortcuts

  • NewBR() - shortcut for <br> tag
  • NewButton() - shortcut for <button> tag
  • NewCaption() - shortcut for <caption> tag
  • NewCode() - shortcut for <code> tag
  • NewDiv() - shortcut for <div> tag
  • NewForm() - shortcut for <form> tag
  • NewI() - shortcut for <i> tag
  • NewHeader() - shortcut for <header> tag
  • NewHeading1() - shortcut for <h1> tag
  • NewHeading2() - shortcut for <h2> tag
  • NewHeading3() - shortcut for <h3> tag
  • NewHeading4() - shortcut for <h4> tag
  • NewHeading5() - shortcut for <h5> tag
  • NewHeading6() - shortcut for <h6> tag
  • NewHyperlink() - shortcut for <a> tag
  • NewHR() - shortcut for <hr> tag
  • NewHTML(html string) - creates empty tag with the HTML content
  • NewImage() - shortcut for <img> tag
  • NewInput() - shortcut for <input> tag
  • NewLI() - shortcut for <li> tag
  • NewLabel() - shortcut for <label> tag
  • NewNav() - shortcut for <nav> tag
  • NewNavbar() - shortcut for <navbar> tag
  • NewOL() - shortcut for <ol> tag
  • NewOption() - shortcut for <option> tag
  • NewParagraph() - shortcut for <p> tag
  • NewPRE() - shortcut for <pre> tag
  • NewScript() - shortcut for <script> tag
  • NewScriptURL() - shortcut for <script src="{SRC}"> tag
  • NewSelect() - shortcut for <select> tag
  • NewSpan() - shortcut for <span> tag
  • NewStyle() - shortcut for <style> tag
  • NewStyleURL() - shortcut for <link> tag
  • NewSection() - shortcut for <section> tag
  • NewSub() - shortcut for <sub> tag
  • NewSup() - shortcut for <sup> tag
  • NewTag(tagName string) - for custom tags
  • NewTable() - shortcut for <table> tag
  • NewTBody() - shortcut for <tbody> tag
  • NewTD() - shortcut for <td> tag
  • NewTemplate() - shortcut for <template> tag
  • NewText(text string) - creates empty tag with the escaped text content
  • NewTextArea() - shortcut for <textarea> tag
  • NewTH() - shortcut for <th> tag
  • NewThead() - shortcut for <thead> tag
  • NewTR() - shortcut for <tr> tag
  • NewUL() - shortcut for <ul> tag
  • NewWebpage() - full HTML page withe head, body, meta, styles and scripts
  • NewWrap() - convenience method to taglessly (without a root wrapping element) group elements together

Examples can be found on: https://golangui.com

Tag Methods

  • Action(action string) - shortcut to add an "action" attribute
  • Attr(key, value string) - shortcut for SetAttribute
  • AttrIf(condition bool, key, value string) - conditional setting of attribute
  • AttrIfF(condition bool, key string, valueFunc func() string) - conditional setting of attribute using function
  • AttrIfElse(condition bool, key, valueIf string, valueElse string) - conditional setting of attribute
  • Attrs(map[string]string) - shortcut for setting multiple attributes
  • AttrsIf(condition bool, attrs map[string]string) - conditional setting of attributes
  • AttrsIfF(condition bool, attrsFunc func() map[string]string) - conditional setting of attributes using function
  • AttrsIfElse(condition, attrsIf map[string]string, attrsElse map[string]string) - conditional setting of attributes
  • AddChild(tag Tag) - adds a child element
  • AddChildren(tag []Tag) - adds an array of child elements
  • AddClass(className string) - adds a class name to the "class" attribute
  • AddHTML(html string) - adds HTML content to the element
  • AddStyle(style string) - adds a style to the "style" attribute
  • AddText(text string) - adds escaped text content to the element
  • Child(tag Tag) - shortcut for AddChild
  • ChildIf(condition bool, tag Tag) - conditional adding of a child
  • ChildIfF(condition bool, childFunc func() *Tag) - conditional adding of a child using function
  • ChildIfElse(condition bool, childIf Tag, childElse Tag) - conditional adding of a child
  • Children(children []Tag) - shortcut for AddChildren
  • ChildrenIf(condition bool, children []Tag) - conditional adding of children
  • ChildrenIfF(condition bool, childrenFunc func() []*Tag) - conditional adding of children using function
  • ChildrenIfElse(condition bool, childrenIf []Tag, childrenElse []Tag) - conditional adding of a children
  • ChildrenMap(items []any, callback func(item any, index int) *Tag) []*Tag - map a slice to a slice of tags and adds as children
  • Class(className string) - shortcut for AddClass
  • ClassIf(condition bool, className string) - conditional adding of a class
  • ClassIfElse(condition bool, classNameIf string, classNameElse string) - conditional adding of a class
  • Data(name string, value string) - shortcut to add a "data-" attribute
  • DataIf(condition bool, key, value string) - conditional setting of attribute
  • DataIfElse(condition bool, key, valueIf string, valueElse string) - conditional setting of attribute
  • Enctype(enctype string) - shortcut to add an "enctype" attribute
  • HasClass(className string) - checks if the class is available
  • Href(href string) - shortcut to add an "href" attribute
  • HTML(html string) - shortcut for AddHTML
  • ID(className string) - shortcut to add an "id" attribute
  • GetAttribute(key string) string
  • Method(method string) - shortcut to add a "method" attribute
  • Name(name string) - shortcut to add a "name" attribute
  • Placeholder(placeholder string) - shortcut to add a "placeholder" attribute
  • OnBlur(js string) - shortcut to add an "onblur" attribute
  • OnChange(js string) - shortcut to add an "onchange" attribute
  • OnClick(js string) - shortcut to add an "onclick" attribute
  • OnDblClick(js string) - shortcut to add an "ondblclick" attribute
  • OnFocus(js string) - shortcut to add an "onfocus" attribute
  • OnKeyDown(js string) - shortcut to add an "onkeydown" attribute
  • OnKeyPress(js string) - shortcut to add an "onkeypress" attribute
  • OnKeyUp(js string) - shortcut to add an "onkeyup" attribute
  • OnMouseDown(js string) - shortcut to add an "onmousedown" attribute
  • OnMouseOut(js string) - shortcut to add an "onmouseout" attribute
  • OnMouseUp(js string) - shortcut to add an "onmouseup" attribute
  • OnSubmit(js string) - shortcut to add an "onsubmit" attribute
  • Role(role string) - shortcut to add a "role" attribute
  • SetAttribute(key, value string) - sets an attribute (i.e. id, class, etc)
  • Src(src string) - shortcut to add a "src" attribute
  • Style(style string) - shortcut to add a "style" attribute
  • StyleIf(condition bool, style string) - conditional adding of a style
  • StyleIfElse(condition bool, styleIf string, styleElse string) - conditional adding of a style
  • Target(target string) - shortcut to add a "target" attribute
  • TargetIf(condition bool, target string) - conditional adding of a "target" attribute
  • Text(html string) - shortcut for AddText
  • TextIf(condition bool, text string) - adds escaped text if a condition is met
  • TextIfElse(condition bool, textIf string, textElse string) - adds escaped text if a condition is met
  • Title(title string) - shortcut for setting the "title" attribute
  • TitleIf(condition bool, title string) - sets the title if a condition is met
  • ToHTML() string - outputs HTML code
  • Type(target string) - shortcut to add a "type" attribute
  • TypeIf(condition bool, target string) - conditional setting of "type" attribute
  • Value(value string) - shortcut to add a "value" attribute
  • ValueIf(condition bool, value string) - conditional setting of "value" attribute

Examples can be found on: https://golangui.com

Utility

  • Map[T any](items []T, callback func(item T, index int) *Tag) []*Tag - map a slice of anything to a slice of tags
  • If(condition bool, trueTag *Tag) *Tag
  • IfF(condition bool, trueFunc func() *Tag) *Tag
  • IfElse(condition bool, trueTag *Tag, falseTag *Tag) *Tag
  • IfFElseF(condition bool, trueFunc func() *Tag, falseFunc func() *Tag) *Tag
  • Ternary(condition bool, trueTag *Tag, falseTag *Tag) *Tag
  • TernaryF(condition bool, trueFunc func() *Tag, falseFunc func() *Tag) *Tag

Tag HTMX Attributes

HTMX (https://htmx.org/reference/) is a great match for Golang, therefore here is a shortcut for working with HTMX.

  • Hx(name string, value string) - shortcut for setting an HTMX attribute
  • HxConfirm(value string)
  • HxDelete(value string)
  • HxGet(value string)
  • HxInclude(value string)
  • HxOn(name string, value string)
  • HxPatch(value string)
  • HxPost(value string)
  • HxPut(value string)
  • HxSelect(value string)
  • HxSelectOob(value string)
  • HxSync(value string)
  • HxSwap(value string)
  • HxSwapOob(value string)
  • HxTarget(value string)
  • HxTrigger(value string)
  • HxVals(value string)
  • HxVars(value string)

Examples can be found on: https://golangui.com

Tag Alpine.js Attributes

Alpine.js (https://alpinejs.dev/) is a great match for Golang, therefore here is a shortcut for working with HTMX.

  • X(name string, value string) - shortcut for setting an AlpineJS attribute
  • XBind(name string, value string)
  • XOn(name string, value string)

Examples can be found on: https://golangui.com

Webpage Methods

  • AddChild(child *Tag)
  • SetFavicon(favicon string)
  • SetTitle(title string)
  • AddScripts(scripts []string)
  • AddScript(script string)
  • AddScriptURLs(scriptURLs []string)
  • AddScriptURL(scriptURL string)
  • AddStyle(style string)
  • AddStyles(styles []string)
  • AddStyleURL(styleURL string)
  • AddStyleURLs(styleURLs []string)

Border Layout Methods

  • NewBorderLayout() - shortcut to quickly create a border layout with top, bottom, left, right and center slots (see example below how to use it)
  • AddTop(tag *Tag, alignHorizontal string, alignVertical string)
  • AddBottom(tag *Tag, alignHorizontal string, alignVertical string)
  • AddLeft(tag *Tag, alignHorizontal string, alignVertical string)
  • AddRight(tag *Tag, alignHorizontal string, alignVertical string)
  • AddCenter(tag *Tag, alignHorizontal string, alignVertical string)

Usage example:

bl := NewBorderLayout()
	bl.AddTop(NewSpan().Text("TOP"), BORDER_LAYOUT_ALIGN_CENTER, BORDER_LAYOUT_ALIGN_MIDDLE)
	bl.AddCenter(NewSpan().Text("CENTER"), BORDER_LAYOUT_ALIGN_CENTER, BORDER_LAYOUT_ALIGN_MIDDLE)
	bl.AddBottom(NewSpan().Text("BOTTOM"), BORDER_LAYOUT_ALIGN_CENTER, BORDER_LAYOUT_ALIGN_MIDDLE)
	bl.AddLeft(NewSpan().Text("LEFT"), BORDER_LAYOUT_ALIGN_CENTER, BORDER_LAYOUT_ALIGN_MIDDLE)
	bl.AddRight(NewSpan().Text("RIGHT"), BORDER_LAYOUT_ALIGN_CENTER, BORDER_LAYOUT_ALIGN_MIDDLE)
blHtml := bl.ToHTML()

Swal

Usage example in a form:

form.
	ChildIf(data.formErrorMessage != "", hb.NewSwal(swal.SwalOptions{
		Icon:              "error",
		Title:             "Oops...",
		Text:              data.formErrorMessage,
		ShowCancelButton:  false,
		ConfirmButtonText: "OK",
		ConfirmCallback:   "window.location.href = window.location.href",
	})).
	ChildIf(data.formSuccessMessage != "", hb.NewSwal(swal.SwalOptions{
		Icon:              "success",
		Title:             "Saved",
		Text:              data.formSuccessMessage,
		ShowCancelButton:  false,
		ConfirmButtonText: "OK",
		ConfirmCallback:   "window.location.href = window.location.href",
	}))

Working with Raw Tags

tag := &Tag{
	TagName: "custom-element",
}
tag.toHTML()

Safe Escaping HTML

For safeguarding HTML, always use the .Text(text) method of the tags, it will automatically escape any HTML tags in the output.

Using the .HTML(html) method of the tags, will output the raw HTML, and leaves you vulnerable to XSS attacks.

You can escape the HTML yourself by using the EscapeString method from the standard HTML library Link with example: https://golang.org/pkg/html/#EscapeString

Examples

  • Bootstrap login form
// Elements for the form
header := hb.NewHeading3().text("Please sign in").Style("margin:0px;")
emailLabel := hb.NewLabel().Text("E-mail Address")
emailInput := hb.NewInput().Class("form-control").Name("email").Attr("placeholder", "Enter e-mail address")
emailFormGroup := hb.NewDiv().Class("form-group").Child(emailLabel).Child(emailInput)
passwordLabel := hb.NewLabel().Child(hb.NewText("Password"))
passwordInput := hb.NewInput().Class("form-control").Name("password").Attr("type", "password").Attr("placeholder", "Enter password")
passwordFormGroup := hb.NewDiv().Class("form-group").Child(passwordLabel).Child(passwordInput)
buttonLogin := hb.NewButton().Class("btn btn-lg btn-success btn-block").Text("Login")
buttonRegister := hb.NewHyperlink().Class("btn btn-lg btn-info float-left").Text("Register").Href("auth/register")
buttonForgotPassword := hb.NewHyperlink().Class("btn btn-lg btn-warning float-right").Text("Forgot password?").Href("auth/password-restore")

// Add elements in a card
cardHeader := hb.NewDiv().
	Class("card-header").
	Child(header)

cardBody := hb.NewDiv().
	Class("card-body").
	Children([]*hb.Tag{
		emailFormGroup,
		passwordFormGroup,
		buttonLogin,
	})

cardFooter := hb.NewDiv().
	Class("card-footer").
	Children([]*hb.Tag{
		buttonRegister,
		buttonForgotPassword,
	})

card := hb.NewDiv().
	Class("card card-default").
	Style("margin:0 auto;max-width: 360px;").
	Children([]*hb.Tag{
		cardHeader,
		cardBody,
		cardFooter
	})

// Convert to HTML to display
html := card.ToHTML()

Result:

  • Webpage with title, favicon, Font Awesome icons 4.7.0, jQuery 3.2.1, and Bootstrap 4.5
// 1. Webpage Title
title := "Title"

// 2. Webpage Favicon
favicon := "data:image/x-icon;base64,AAABAAEAEBAQAAEABAAoAQAAFgAAACgAAAAQAAAAIAAAAAEABAAAAAAAgAAAAAAAAAAAAAAAEAAAAAAAAABNTU0AVKH/AOPj4wDExMQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACIiAREQEREAIiIBERAREQAiIgIiICIiACIiAiIgIiIAMzMDMzAzMwAzMwMzMDMzACIiAiIgIiIAIiICIiAiIgAzMwMzMDMzADMzAzMwMzMAIiICIiAiIgAiIgIiICIiAAAAAAAAAAAAIiICIiAiIgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"

// 3. Webpage
webpage := NewWebpage().
	SetTitle(title).
	SetFavicon(favicon).
	AddStyleURLs([]string{
		"https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css",
		"https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css",
	}).
	AddScriptURLs([]string{
		"https://code.jquery.com/jquery-3.2.1.min.js",
		"https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.bundle.min.js",
	}).
	AddStyle(`html,body{height:100%;font-family: Ubuntu, sans-serif;}`).AddChild(NewDiv().Text("Hello"))
  • Wrap webpage in a function to be reused as a master template
// Webpage returns the webpage template for the website
func Webpage(title, content string) *hb.Webpage {
	faviconImgCms := `data:image/x-icon;base64,AAABAAEAEBAQAAEABAAoAQAAFgAAACgAAAAQAAAAIAAAAAEABAAAAAAAgAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAmzKzAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABEQEAAQERAAEAAQABAAEAAQABAQEBEQABAAEREQEAAAERARARAREAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAAi6MAALu7AAC6owAAuC8AAIkjAAD//wAA//8AAP//AAD//wAA`
	webpage := hb.NewWebpage()
	webpage.SetTitle(title)
	webpage.SetFavicon(faviconImgCms)

	webpage.AddStyleURLs([]string{
		"https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css",
	})
	webpage.AddScriptURLs([]string{
		"https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/js/bootstrap.bundle.min.js",
		"http://code.jquery.com/jquery-3.5.1.min.js",
		"https://unpkg.com/vue@next",
		"https://cdn.jsdelivr.net/npm/sweetalert2@9",
	})
	webpage.AddScripts([]string{})
	webpage.AddStyle(`html,body{height:100%;font-family: Ubuntu, sans-serif;}`)
	webpage.AddStyle(`body {
		font-family: "Nunito", sans-serif;
		font-size: 0.9rem;
		font-weight: 400;
		line-height: 1.6;
		color: #212529;
		text-align: left;
		background-color: #f8fafc;
	}`)
	webpage.AddChild(hb.NewHTML(content))
	return webpage
}

// Generate HTML
html := webpage("Home", "Hello world").ToHTML()

HTMX Example

Here is an HTMX example which submits the content of all the inputs in a div to the server (no need to be in a form) and then replaces the content of the webpage with the result.

input := NewButton().
		Text("Submit")
		Hx("post", "http://test.com").
		Hx("include", "#DivID").
		Hx("target", "#PageID").
		Hx("swap", "outerHTML")

How to Add a Redirection?

webpage.Meta(hb.NewMeta().Attr("http-equiv", "refresh").Attr("content", "2; url = https://www.yahoo.com"))

Stargazers over time

Stargazers over time

Similar

Changelog

2023.12.17 - Added Map, Ternary, Text

2023.12.10 - Added Swal method for quickly adding Sweetalert

2023.09.16 - Added special case for empty "value" attribute

2023.07.26 - Added NewCaption function and Alpine.js, HTMX functions

2023.07.02 - Added NewHeader function

2023.06.09 - Added functional conditions AttrIfF, AttrsIfF, ChildIfF, ChildrenIfF

2023.05.08 - Added Alt attribute shortcut

2023.05.01 - Added NewWrap function

2023.04.27 - Added OnDblClick, OnInput, OnKeyPress, OnMouseDown, OnMouseUp, and conditionals for data

2023.04.25 - Added Placeholder, and conditionals for attributes

2023.04.15 - Added AddStyle, Src, and conditionals for style

2023.04.14 - Added Type attribute shortcut, conditionals for children and class names

2023.03.26 - Added Hx attribute shortcut for working with HTMX

2023.03.26 - Added OnBlur, OnChange, OnFocus, OnKeyDown, OnKeyUp, attribute shortcuts

2023.03.26 - Added Enctype, Href, Method, Name, target, Value attribute shortcuts

2023.01.22 - Added shortcut for <footer> tag

2023.01.14 - Flow pattern applied to BorderLayout methods

2022.09.07 - Added Child and Children shortcuts

2022.08.29 - Added default favicon to Webpage to fix 404 if missing

2022.01.07 - Added Attrs shortcut for setting multiple attributes

2021.07.30 - Added shortcut for <hr> tag

2021.03.20 - Renamed package name to hb to not conflict/confuse with the standard html package

2021.03.18 - Added shortcuts for <template> tag

2021.02.26 - Added shortcuts for <sub>, <sup> tags

2021.01.03 - Added example for webpage layout, and screenshot

2020.12.28 - Added shortcuts for <code>, <pre> tags, shortcuts sorted alphabetically

2020.12.27 - Added shortcuts for <table>, <thead>, <tbody>, <tr>, <th>, <td> tags

2020.12.26 - Fix for attribute escapes, added tests

2020.09.16 - Added shortcuts for <nav>, <navbar>, <ol>, <ul>, <li> tags

2020.06.16 - Initial commit

Aternatives

Documentation

Index

Constants

View Source
const BORDER_LAYOUT_ALIGN_BOTTOM = "bottom"
View Source
const BORDER_LAYOUT_ALIGN_CENTER = "center"
View Source
const BORDER_LAYOUT_ALIGN_LEFT = "left"
View Source
const BORDER_LAYOUT_ALIGN_MIDDLE = "middle"
View Source
const BORDER_LAYOUT_ALIGN_RIGHT = "right"
View Source
const BORDER_LAYOUT_ALIGN_TOP = "top"
View Source
const ENCTYPE_FORM_MULTIPART = "multipart/form-data"

ENCTYPE_MULTIPART_FORM_DATA ("multipart/form-data") Necessary if the user will upload a file through the form

View Source
const ENCTYPE_FORM_TEXT = "text/plain"

ENCTYPE_FORM_TEXT ("text/plain") plain text An ambiguous format, human-readable content not reliably interpretable by computer

View Source
const ENCTYPE_FORM_URLENCODED = "application/x-www-form-urlencoded"

ENCTYPE_FORM_URLENCODED ("application/x-www-form-urlencoded") default encoding of forms. All characters are converted. Spaces are converted to "+" symbols, and special characters are converted to ASCII HEX values)

View Source
const TYPE_BUTTON = "button"
View Source
const TYPE_CHECKBOX = "checkbox"
View Source
const TYPE_COLOR = "color"
View Source
const TYPE_DATE = "date"
View Source
const TYPE_DATETIME = "datetime-local"
View Source
const TYPE_EMAIL = "email"
View Source
const TYPE_FILE = "file"
View Source
const TYPE_HIDDEN = "hidden"
View Source
const TYPE_IMAGE = "image"
View Source
const TYPE_MONTH = "month"
View Source
const TYPE_NUMBER = "number"
View Source
const TYPE_PASSWORD = "password"
View Source
const TYPE_RADIO = "radio"
View Source
const TYPE_RANGE = "range"
View Source
const TYPE_RESET = "reset"
View Source
const TYPE_SEARCH = "search"
View Source
const TYPE_SUBMIT = "submit"
View Source
const TYPE_TEL = "tel"
View Source
const TYPE_TEXT = "text"
View Source
const TYPE_TIME = "time"
View Source
const TYPE_URL = "url"
View Source
const TYPE_WEEK = "week"

Variables

This section is empty.

Functions

This section is empty.

Types

type BorderLayout added in v1.37.0

type BorderLayout struct {
	Tag
	// contains filtered or unexported fields
}

* * The BorderLayout type is an advanced layout. * * It arranges its children in five regions: top, bottom, left, right, and center. * Each region may contain no more than one widget. * <code> * // Creating a new instance of BorderLayout * borderlayout = NewBorderLayout() * AddChild("HEADER", BORDER_LAYOUT_ALIGN_CENTER, BORDER_LAYOUT_ALIGN_MIDDLE); * AddChild("CONTENT", BORDER_LAYOUT_ALIGN_CENTER, BORDER_LAYOUT_ALIGN_MIDDLE); * AddChild("FOOTER", BORDER_LAYOUT_ALIGN_CENTER, BORDER_LAYOUT_ALIGN_MIDDLE); * AddChild("MENU", BORDER_LAYOUT_ALIGN_CENTER, BORDER_LAYOUT_ALIGN_MIDDLE); * AddChild("ADDS", BORDER_LAYOUT_ALIGN_CENTER, BORDER_LAYOUT_ALIGN_MIDDLE); * </code>

func NewBorderLayout added in v1.37.0

func NewBorderLayout() *BorderLayout

func (*BorderLayout) AddBottom added in v1.37.0

func (bl *BorderLayout) AddBottom(tag *Tag, alignHorizontal string, alignVertical string) *BorderLayout

func (*BorderLayout) AddCenter added in v1.37.0

func (bl *BorderLayout) AddCenter(tag *Tag, alignHorizontal string, alignVertical string) *BorderLayout

func (*BorderLayout) AddLeft added in v1.37.0

func (bl *BorderLayout) AddLeft(tag *Tag, alignHorizontal string, alignVertical string) *BorderLayout

func (*BorderLayout) AddRight added in v1.37.0

func (bl *BorderLayout) AddRight(tag *Tag, alignHorizontal string, alignVertical string) *BorderLayout

func (*BorderLayout) AddTop added in v1.37.0

func (bl *BorderLayout) AddTop(tag *Tag, alignHorizontal string, alignVertical string) *BorderLayout

func (*BorderLayout) SetHeightPercents added in v1.37.0

func (bl *BorderLayout) SetHeightPercents(height int) *BorderLayout

func (*BorderLayout) SetHeightPixels added in v1.37.0

func (bl *BorderLayout) SetHeightPixels(height int) *BorderLayout

func (*BorderLayout) SetWidthPercents added in v1.37.0

func (bl *BorderLayout) SetWidthPercents(width int) *BorderLayout

func (*BorderLayout) SetWidthPixels added in v1.37.0

func (bl *BorderLayout) SetWidthPixels(width int) *BorderLayout

func (*BorderLayout) ToHTML added in v1.37.0

func (bl *BorderLayout) ToHTML() string

BorderLayout returns HTML representation of the layout

type SwalOptions added in v1.68.0

type SwalOptions struct {
	Icon               string `json:"icon,omitempty"`
	Text               string `json:"text,omitempty"`
	Title              string `json:"title,omitempty"`
	ShowCancelButton   bool   `json:"showCancelButton,omitempty"`
	CancelButtonColor  string `json:"cancelButtonColor,omitempty"`
	CancelButtonText   string `json:"cancelButtonText,omitempty"`
	ConfirmButtonText  string `json:"confirmButtonText,omitempty"`
	ConfirmButtonColor string `json:"confirmButtonColor,omitempty"`
	ConfirmCallback    string `json:"-"`
}

type Tag

type Tag struct {
	TagInterface
	TagName       string
	TagContent    string
	TagAttributes map[string]string
	TagChildren   []*Tag
}

Tag represents an HTML tag

func If added in v1.50.0

func If(condition bool, trueTag *Tag) *Tag

func IfElse added in v1.50.0

func IfElse(condition bool, trueTag *Tag, falseTag *Tag) *Tag

func IfF added in v1.62.1

func IfF(condition bool, trueFunc func() *Tag) *Tag

func IfFElseF added in v1.62.1

func IfFElseF(condition bool, trueFunc func() *Tag, falseFunc func() *Tag) *Tag

func Map added in v1.70.0

func Map[T any](items []T, callback func(item T, index int) *Tag) []*Tag

Map a slice of anything to a slice of tags.

func NewBR added in v1.43.0

func NewBR() *Tag

NewBR represents a BR tag

func NewButton

func NewButton() *Tag

NewButton represents a BUTTON tag

func NewCaption added in v1.64.0

func NewCaption() *Tag

NewCaption is a shortcut to create a new CAPTION tag

func NewCode

func NewCode() *Tag

NewCode represents a CODE tag

func NewDiv

func NewDiv() *Tag

NewDiv represents a DIV tag

func NewFooter added in v1.46.0

func NewFooter() *Tag

NewFooter is a shortcut to create a new FOOTER tag

func NewForm

func NewForm() *Tag

NewForm represents a FORM tag

func NewHR added in v1.31.0

func NewHR() *Tag

NewHR creates represents a HR tags

func NewHTML

func NewHTML(html string) *Tag

NewHTML creates pure HTML without surrounding tags

func NewHeader added in v1.58.0

func NewHeader() *Tag

NewHeader is a shortcut to create a new HEADER tag

func NewHeading1

func NewHeading1() *Tag

NewHeading1 represents a H1 tag

func NewHeading2

func NewHeading2() *Tag

NewHeading2 represents a H1 tag

func NewHeading3

func NewHeading3() *Tag

NewHeading3 represents a H1 tag

func NewHeading4

func NewHeading4() *Tag

NewHeading4 represents a H1 tag

func NewHeading5

func NewHeading5() *Tag

NewHeading5 represents a H1 tag

func NewHeading6

func NewHeading6() *Tag

NewHeading6 represents a H1 tag

func NewHyperlink() *Tag

NewHyperlink represents a H1 tag

func NewI added in v1.37.0

func NewI() *Tag

NewI represents an I tag

func NewImage

func NewImage() *Tag

NewImage represents a IMG tag

func NewInput

func NewInput() *Tag

NewInput represents a IMG tag

func NewLI

func NewLI() *Tag

NewLI represents a LI tag

func NewLabel

func NewLabel() *Tag

NewLabel represents a LABEL tag

func NewLink() *Tag

NewLink represents a LINK tag

func NewMeta

func NewMeta() *Tag

NewMeta represents a META tag

func NewNav

func NewNav() *Tag

NewNav represents a NAV tag

func NewNavbar

func NewNavbar() *Tag

NewNavbar represents a NAVBAR tag

func NewOL

func NewOL() *Tag

NewOL represents a UL tag

func NewOption

func NewOption() *Tag

NewOption represents an OPTION tag

func NewPRE

func NewPRE() *Tag

NewPRE represents a PRE tag

func NewParagraph

func NewParagraph() *Tag

NewParagraph represents a IMG tag

func NewPod added in v1.53.2

func NewPod() *Tag

NewPod represents a wrapper tag It serves as a container for other tags, and is used to wrap other tags together.

func NewScript

func NewScript(javascript string) *Tag

NewScript represents a SCRIPT tag

func NewScriptURL

func NewScriptURL(javascriptURL string) *Tag

NewScriptURL represents a SCRIPT tag with URL

func NewSection

func NewSection() *Tag

NewSection represents a SECTION tag

func NewSelect

func NewSelect() *Tag

NewSelect represents a SELECT tag

func NewSpan

func NewSpan() *Tag

NewSpan represents a SPAN tag

func NewStyle

func NewStyle(css string) *Tag

NewStyle represents a STYLE tag

func NewStyleURL

func NewStyleURL(styleURL string) *Tag

NewStyleURL represents a LINK tag with URL

func NewSub

func NewSub() *Tag

NewSub represents a SUB tag

func NewSup

func NewSup() *Tag

NewSup represents a SUP tag

func NewSwal added in v1.68.0

func NewSwal(options SwalOptions) *Tag

NewSwal generates a script with a Sweetalert2 dialog Note! you must include the library yourself (i.e. CDN)

func NewTD

func NewTD() *Tag

NewTD represents a TD tag

func NewTH

func NewTH() *Tag

NewTH represents a TH tag

func NewTR

func NewTR() *Tag

NewTR represents a TR tag

func NewTable

func NewTable() *Tag

NewTable represents a TABLE tag

func NewTag

func NewTag(tagName string) *Tag

NewTag creates a tag, with the specified name useful for custom tags or ones that are not yet added to the hb library

func NewTbody

func NewTbody() *Tag

NewTbody represents a TBODY tag

func NewTemplate

func NewTemplate() *Tag

NewTemplate represents a TEMPLATE tag

func NewText added in v1.69.0

func NewText(text string) *Tag

NewText creates pure escaped text without surrounding tags

func NewTextArea

func NewTextArea() *Tag

NewTextArea represents a FORM tag

func NewThead

func NewThead() *Tag

NewThead represents a THEAD tag

func NewUL

func NewUL() *Tag

NewUL represents a UL tag

func NewWrap added in v1.56.0

func NewWrap() *Tag

NewWrap is a convenience tagless container to wrap multiple elements together. Any attributes added to the wrap tag will be lost. If you need to keep these better use a DIV tag

func Ternary added in v1.70.0

func Ternary(condition bool, trueTag *Tag, falseTag *Tag) *Tag

Ternary is a 1 line if/else statement.

func TernaryF added in v1.70.0

func TernaryF(condition bool, trueFunc func() *Tag, falseFunc func() *Tag) *Tag

TernaryF is a 1 line if/else statement whose options are functions

func (*Tag) Action added in v1.48.0

func (t *Tag) Action(action string) *Tag

Action shortcut for setting the "action" attribute

func (*Tag) AddChild

func (t *Tag) AddChild(child *Tag) *Tag

AddChild adds a new child tag to this tag

func (*Tag) AddChildren

func (t *Tag) AddChildren(children []*Tag) *Tag

AddChildren adds an array of child tags to this tag

func (*Tag) AddClass added in v1.36.0

func (t *Tag) AddClass(className string) *Tag

AddClass adds a new class name to the tag attribute list.

func (*Tag) AddHTML

func (t *Tag) AddHTML(html string) *Tag

AddHTML adds an HTML string as a child tag to this tag

func (*Tag) AddStyle added in v1.52.0

func (t *Tag) AddStyle(style string) *Tag

AddStyle adds a new class name to the tag attribute list.

func (*Tag) AddText added in v1.69.0

func (t *Tag) AddText(text string) *Tag

AddText adds an escaped text string as a child tag to this tag

func (*Tag) Alt added in v1.57.0

func (t *Tag) Alt(text string) *Tag

Alt shortcut for setting the "alt" attribute

func (*Tag) Attr

func (t *Tag) Attr(key, value string) *Tag

Attr shortcut for SetAttribute

func (*Tag) AttrIf added in v1.54.0

func (t *Tag) AttrIf(condition bool, key, value string) *Tag

AttrIf shortcut for setting an attribute if a condition is met

func (*Tag) AttrIfElse added in v1.54.0

func (t *Tag) AttrIfElse(condition bool, key, valueIf string, valueElse string) *Tag

AttrIfElse shortcut for setting an attribute if a condition is met, otherwise adds another attribute

func (*Tag) AttrIfF added in v1.57.0

func (t *Tag) AttrIfF(condition bool, key string, valueFunc func() string) *Tag

func (*Tag) Attrs added in v1.32.0

func (t *Tag) Attrs(attrs map[string]string) *Tag

Attrs shortcut for setting multiple attributes

func (*Tag) AttrsIf added in v1.54.0

func (t *Tag) AttrsIf(condition bool, attrs map[string]string) *Tag

AttrsIf shortcut for setting multiple attributes if a condition is met

func (*Tag) AttrsIfElse added in v1.54.0

func (t *Tag) AttrsIfElse(condition bool, attrsIf map[string]string, attrsElse map[string]string) *Tag

AttrsIfElse shortcut for setting multiple attributes if a condition is met, otherwise adds another attribute

func (*Tag) AttrsIfF added in v1.57.0

func (t *Tag) AttrsIfF(condition bool, attrsFunc func() map[string]string) *Tag

AttrsIf shortcut for setting multiple attributes via function if a condition is met

func (*Tag) Child added in v1.41.0

func (t *Tag) Child(child *Tag) *Tag

Child shortcut for AddChild

func (*Tag) ChildIf added in v1.50.0

func (t *Tag) ChildIf(condition bool, child *Tag) *Tag

ChildIf adds a child if a condition is met

func (*Tag) ChildIfElse added in v1.51.0

func (t *Tag) ChildIfElse(condition bool, childIf *Tag, childElse *Tag) *Tag

ChildIfElse adds a child if a condition is met, otherwise adds another child

func (*Tag) ChildIfF added in v1.57.0

func (t *Tag) ChildIfF(condition bool, childFunc func() *Tag) *Tag

ChildIf adds a child using function if a condition is met

func (*Tag) Children added in v1.41.0

func (t *Tag) Children(children []*Tag) *Tag

Children shortcut for AddChildren

func (*Tag) ChildrenIf added in v1.50.0

func (t *Tag) ChildrenIf(condition bool, children []*Tag) *Tag

ChildrenIf adds children if a condition is met

func (*Tag) ChildrenIfElse added in v1.51.0

func (t *Tag) ChildrenIfElse(condition bool, childrenIf []*Tag, childrenElse []*Tag) *Tag

ChildrenIfElse adds children if a condition is met

func (*Tag) ChildrenIfF added in v1.57.0

func (t *Tag) ChildrenIfF(condition bool, childrenFunc func() []*Tag) *Tag

ChildrenIf adds children using function if a condition is met

func (*Tag) ChildrenMap added in v1.71.0

func (t *Tag) ChildrenMap(items []any, callback func(item any, index int) *Tag) *Tag

ChildrenMap map a slice to a slice of tags and adds as children

func (*Tag) Class added in v1.36.0

func (t *Tag) Class(className string) *Tag

Class shortcut for setting the "class" attribute

func (*Tag) ClassIf added in v1.50.0

func (t *Tag) ClassIf(condition bool, className string) *Tag

ClassIf adds class name if a condition is met

func (*Tag) ClassIfElse added in v1.51.0

func (t *Tag) ClassIfElse(condition bool, classNameIf string, classNameElse string) *Tag

ClassIfElse adds class name if a condition is met

func (*Tag) Data added in v1.49.0

func (t *Tag) Data(name string, value string) *Tag

Data shortcut for setting a "data-" attribute

func (*Tag) DataIf added in v1.55.0

func (t *Tag) DataIf(condition bool, name string, value string) *Tag

DataIf shortcut for setting a "data-" attribute if a condition is met

func (*Tag) DataIfElse added in v1.55.0

func (t *Tag) DataIfElse(condition bool, name string, valueIf string, valueElse string) *Tag

DataIfElse shortcut for setting a "data-" attribute if a condition is met

func (*Tag) Enctype added in v1.48.0

func (t *Tag) Enctype(enctype string) *Tag

Enctype shortcut for setting the "enctype" attribute

func (*Tag) GetAttribute

func (t *Tag) GetAttribute(key string) string

GetAttribute returns the value of an attribute

func (*Tag) HTML

func (t *Tag) HTML(html string) *Tag

HTML shortcut for AddHTML

func (*Tag) HTMLIf added in v1.51.0

func (t *Tag) HTMLIf(condition bool, html string) *Tag

HTMLIf adds html if a condition is met

func (*Tag) HTMLIfElse added in v1.51.0

func (t *Tag) HTMLIfElse(condition bool, htmlIf string, htmlElse string) *Tag

HTMLIfElse adds html if a condition is met

func (*Tag) HasClass added in v1.36.0

func (t *Tag) HasClass(className string) bool

HasClass returns true if the tag has a class with the specified name.

func (*Tag) Href added in v1.48.0

func (t *Tag) Href(href string) *Tag

Href shortcut for setting the "href" attribute

func (*Tag) Hx added in v1.48.0

func (t *Tag) Hx(name string, value string) *Tag

Hx shortcut for setting an HTMX attribute Htmx attributes have the format of hx-{NAME}="{VALUE}"

func (*Tag) HxConfirm added in v1.62.0

func (t *Tag) HxConfirm(value string) *Tag

func (*Tag) HxDelete added in v1.63.0

func (t *Tag) HxDelete(value string) *Tag

func (*Tag) HxGet added in v1.62.0

func (t *Tag) HxGet(value string) *Tag

func (*Tag) HxInclude added in v1.62.0

func (t *Tag) HxInclude(value string) *Tag

func (*Tag) HxOn added in v1.62.0

func (t *Tag) HxOn(name string, value string) *Tag

func (*Tag) HxPatch added in v1.63.0

func (t *Tag) HxPatch(value string) *Tag

func (*Tag) HxPost added in v1.62.0

func (t *Tag) HxPost(value string) *Tag

func (*Tag) HxPut added in v1.63.0

func (t *Tag) HxPut(value string) *Tag

func (*Tag) HxSelect added in v1.62.0

func (t *Tag) HxSelect(value string) *Tag

func (*Tag) HxSelectOob added in v1.62.0

func (t *Tag) HxSelectOob(value string) *Tag

func (*Tag) HxSwap added in v1.62.0

func (t *Tag) HxSwap(value string) *Tag

func (*Tag) HxSwapOob added in v1.62.0

func (t *Tag) HxSwapOob(value string) *Tag

func (*Tag) HxSync added in v1.62.0

func (t *Tag) HxSync(value string) *Tag

func (*Tag) HxTarget added in v1.62.0

func (t *Tag) HxTarget(value string) *Tag

func (*Tag) HxTrigger added in v1.62.0

func (t *Tag) HxTrigger(value string) *Tag

func (*Tag) HxVals added in v1.62.0

func (t *Tag) HxVals(value string) *Tag

func (*Tag) HxVars added in v1.62.0

func (t *Tag) HxVars(value string) *Tag

func (*Tag) ID added in v1.36.0

func (t *Tag) ID(id string) *Tag

ID shortcut for setting the "id" attribute

func (*Tag) Method added in v1.48.0

func (t *Tag) Method(method string) *Tag

Method shortcut for setting the "method" attribute

func (*Tag) Name added in v1.48.0

func (t *Tag) Name(name string) *Tag

Name shortcut for setting the "name" attribute

func (*Tag) OnBlur added in v1.48.0

func (t *Tag) OnBlur(js string) *Tag

OnBlur shortcut for setting the "onblur" attribute

func (*Tag) OnChange added in v1.48.0

func (t *Tag) OnChange(js string) *Tag

OnChange shortcut for setting the "onchange" attribute

func (*Tag) OnClick added in v1.37.0

func (t *Tag) OnClick(js string) *Tag

OnClick shortcut for setting the "onclick" attribute

func (*Tag) OnDblClick added in v1.55.0

func (t *Tag) OnDblClick(js string) *Tag

OnDblClick shortcut for setting the "ondblclick" attribute

func (*Tag) OnFocus added in v1.48.0

func (t *Tag) OnFocus(js string) *Tag

OnFocus shortcut for setting the "onfocus" attribute

func (*Tag) OnInput added in v1.55.0

func (t *Tag) OnInput(js string) *Tag

OnInput shortcut for setting the "oninput" attribute

func (*Tag) OnKeyDown added in v1.48.0

func (t *Tag) OnKeyDown(js string) *Tag

OnKeyDown shortcut for setting the "onkeydown" attribute

func (*Tag) OnKeyPress added in v1.55.0

func (t *Tag) OnKeyPress(js string) *Tag

OnKeyPress shortcut for setting the "onkeydown" attribute

func (*Tag) OnKeyUp added in v1.48.0

func (t *Tag) OnKeyUp(js string) *Tag

OnKeyUp shortcut for setting the "onkeyup" attribute

func (*Tag) OnLoad added in v1.55.0

func (t *Tag) OnLoad(js string) *Tag

OnLoad shortcut for setting the "onload" attribute

func (*Tag) OnMouseDown added in v1.55.0

func (t *Tag) OnMouseDown(js string) *Tag

OnMouseDown shortcut for setting the "onmousedown" attribute

func (*Tag) OnMouseEnter added in v1.55.0

func (t *Tag) OnMouseEnter(js string) *Tag

OnMouseEnter shortcut for setting the "onmouseenter" attribute

func (*Tag) OnMouseLeave added in v1.55.0

func (t *Tag) OnMouseLeave(js string) *Tag

OnMouseLeave shortcut for setting the "onmouseleave" attribute

func (*Tag) OnMouseMove added in v1.55.0

func (t *Tag) OnMouseMove(js string) *Tag

OnMouseMove shortcut for setting the "onmousemove" attribute

func (*Tag) OnMouseOut added in v1.55.0

func (t *Tag) OnMouseOut(js string) *Tag

OnMouseOut shortcut for setting the "onmouseout" attribute

func (*Tag) OnMouseOver added in v1.55.0

func (t *Tag) OnMouseOver(js string) *Tag

OnMouseOver shortcut for setting the "onmouseover" attribute

func (*Tag) OnMouseUp added in v1.55.0

func (t *Tag) OnMouseUp(js string) *Tag

OnMouseUp shortcut for setting the "onmouseup" attribute

func (*Tag) OnSubmit added in v1.55.0

func (t *Tag) OnSubmit(js string) *Tag

OnSubmit shortcut for setting the "onsubmit" attribute

func (*Tag) Placeholder added in v1.54.0

func (t *Tag) Placeholder(placeholder string) *Tag

Placeholder shortcut for setting the "placeholder" attribute

func (*Tag) Role added in v1.65.0

func (t *Tag) Role(role string) *Tag

Src shortcut for setting the "src" attribute

func (*Tag) SetAttribute

func (t *Tag) SetAttribute(key, value string) *Tag

SetAttribute sets the value of an attribute

func (*Tag) Src added in v1.53.0

func (t *Tag) Src(src string) *Tag

Src shortcut for setting the "src" attribute

func (*Tag) SrcIf added in v1.63.0

func (t *Tag) SrcIf(condition bool, src string) *Tag

SrcIf sets the "src" attribute if a condition is met

func (*Tag) Style added in v1.38.0

func (t *Tag) Style(style string) *Tag

Style shortcut for setting the "style" attribute

func (*Tag) StyleIf added in v1.52.0

func (t *Tag) StyleIf(condition bool, style string) *Tag

StyleIf adds style if a condition is met

func (*Tag) StyleIfElse added in v1.52.0

func (t *Tag) StyleIfElse(condition bool, styleIf string, styleElse string) *Tag

StyleIfElse adds style if a condition is met

func (*Tag) Target added in v1.48.0

func (t *Tag) Target(target string) *Tag

Target shortcut for setting the "target" attribute

func (*Tag) TargetIf added in v1.63.0

func (t *Tag) TargetIf(condition bool, target string) *Tag

TargetIf sets the target if a condition is met

func (*Tag) Text added in v1.69.0

func (t *Tag) Text(text string) *Tag

Text shortcut for AddText

func (*Tag) TextIf added in v1.69.0

func (t *Tag) TextIf(condition bool, text string) *Tag

TextIf adds escaped text if a condition is met

func (*Tag) TextIfElse added in v1.69.0

func (t *Tag) TextIfElse(condition bool, textIf string, textElse string) *Tag

TextIfElse adds escaped text if a condition is met

func (*Tag) Title added in v1.72.0

func (t *Tag) Title(title string) *Tag

Title shortcut for setting the "title" attribute

func (*Tag) TitleIf added in v1.72.0

func (t *Tag) TitleIf(condition bool, title string) *Tag

TitleIf sets the title if a condition is met

func (*Tag) ToHTML

func (t *Tag) ToHTML() string

ToHTML returns HTML from Node

func (*Tag) Type added in v1.51.0

func (t *Tag) Type(inputType string) *Tag

Type shortcut for setting the "type" attribute

func (*Tag) TypeIf added in v1.63.0

func (t *Tag) TypeIf(condition bool, inputType string) *Tag

TypeIf sets the type if a condition is met

func (*Tag) Value added in v1.48.0

func (t *Tag) Value(value string) *Tag

Value shortcut for setting the "value" attribute

func (*Tag) ValueIf added in v1.63.0

func (t *Tag) ValueIf(condition bool, value string) *Tag

ValueIf sets the value if a condition is met

func (*Tag) X added in v1.64.0

func (t *Tag) X(name string, value string) *Tag

X shortcut for setting an Alpine attribute AlpineJS attributes have the format of x-{NAME}="{VALUE}"

func (*Tag) XBind added in v1.64.0

func (t *Tag) XBind(name string, value string) *Tag

func (*Tag) XOn added in v1.64.0

func (t *Tag) XOn(name string, value string) *Tag

type TagInterface

type TagInterface interface {
	ToHTML() string
}

TagInterface represents an HTML tag interface

type Webpage

type Webpage struct {
	Tag
	// contains filtered or unexported fields
}

Webpage represents a web page

func NewWebpage

func NewWebpage() *Webpage

NewWebpage returns a webpage instance

func (*Webpage) AddChild

func (w *Webpage) AddChild(child *Tag) *Webpage

AddChild adds a tag to the webpage

func (*Webpage) AddChildren added in v1.42.0

func (w *Webpage) AddChildren(children []*Tag) *Webpage

AddChildren adds tags to the webpage

func (*Webpage) AddHTML added in v1.61.0

func (w *Webpage) AddHTML(html string) *Webpage

AddHTML adds an HTML to the body of the webpage

func (*Webpage) AddMeta added in v1.60.0

func (w *Webpage) AddMeta(meta *Tag) *Webpage

func (*Webpage) AddScript

func (w *Webpage) AddScript(script string) *Webpage

AddScript adds a script to the webpage

func (*Webpage) AddScriptURL

func (w *Webpage) AddScriptURL(scriptURL string) *Webpage

AddScriptURL adds a style URL to the webpage

func (*Webpage) AddScriptURLs

func (w *Webpage) AddScriptURLs(scriptURLs []string) *Webpage

AddScriptURLs adds style URLs to the webpage

func (*Webpage) AddScripts

func (w *Webpage) AddScripts(scripts []string) *Webpage

AddScripts adds scripts to the webpage

func (*Webpage) AddStyle

func (w *Webpage) AddStyle(style string) *Webpage

AddStyle adds a style to the webpage

func (*Webpage) AddStyleURL

func (w *Webpage) AddStyleURL(styleURL string) *Webpage

AddStyleURL adds a style URL to the webpage

func (*Webpage) AddStyleURLs

func (w *Webpage) AddStyleURLs(styleURLs []string) *Webpage

AddStyleURLs adds style URLs to the webpage

func (*Webpage) AddStyles

func (w *Webpage) AddStyles(styles []string) *Webpage

AddStyles adds styles to the webpage

func (*Webpage) Attr added in v1.44.0

func (w *Webpage) Attr(key, value string) *Webpage

Attr shortcut for SetAttribute

func (*Webpage) Attrs added in v1.44.0

func (w *Webpage) Attrs(attrs map[string]string) *Webpage

Attrs shortcut for setting multiple attributes

func (*Webpage) Body

func (w *Webpage) Body() *Tag

Body returns a pointer to the body tag

func (*Webpage) Child added in v1.42.0

func (w *Webpage) Child(child *Tag) *Webpage

AddChild shortcut for AddChild

func (*Webpage) Children added in v1.42.0

func (w *Webpage) Children(children []*Tag) *Webpage

Children shortcut for AddChildren

func (*Webpage) HTML added in v1.61.0

func (w *Webpage) HTML(html string) *Webpage

HTML shortcut for adding HTML to the body

func (*Webpage) Head

func (w *Webpage) Head() *Tag

Head returns a pointer to the head tag

func (*Webpage) Meta added in v1.60.0

func (w *Webpage) Meta(meta *Tag) *Webpage

Meta shortcut for adding a meta

func (*Webpage) Script added in v1.60.0

func (w *Webpage) Script(script string) *Webpage

Script shortcut for adding a script

func (*Webpage) ScriptURL added in v1.60.0

func (w *Webpage) ScriptURL(scriptURL string) *Webpage

ScriptURL shortcut for adding a script URL

func (*Webpage) ScriptURLs

func (w *Webpage) ScriptURLs(scriptURLs []string) *Webpage

ScriptURLs shortcut for adding script URLs

func (*Webpage) SetAttribute added in v1.44.0

func (w *Webpage) SetAttribute(key string, value string) *Webpage

SetAttribute adds a style to the webpage

func (*Webpage) SetCharset added in v1.72.1

func (w *Webpage) SetCharset(charset string) *Webpage

SetCharset sets the charset of the webpage

func (*Webpage) SetFavicon

func (w *Webpage) SetFavicon(favicon string) *Webpage

SetFavicon sets the favicon of the webpage

func (*Webpage) SetLanguage added in v1.72.1

func (w *Webpage) SetLanguage(language string) *Webpage

SetLanguage sets the language of the webpage

func (*Webpage) SetTitle

func (w *Webpage) SetTitle(title string) *Webpage

SetTitle sets the title of the webpage

func (*Webpage) Style added in v1.59.0

func (w *Webpage) Style(style string) *Webpage

Style shortcut for adding a style

func (*Webpage) StyleURL added in v1.59.0

func (w *Webpage) StyleURL(styleURL string) *Webpage

StyleURL shortcut for adding a style URL to the webpage

func (*Webpage) StyleURLs

func (w *Webpage) StyleURLs(styleURLs []string) *Webpage

StyleURLs shortcut for adding style URLs to the webpage

func (*Webpage) ToHTML

func (w *Webpage) ToHTML() string

ToHTML returns HTML representation of the webpage

Jump to

Keyboard shortcuts

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