html

package module
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2025 License: BSD-3-Clause Imports: 2 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Html

Go code generate html

GoDoc GitHub stars Go Report Card codecov

Versions

Stable Version GitHub Release GitHub Release

Instalation

go get -u github.com/gouef/html

Usages

package main

import "github.com/gouef/html"

func getHtml() string {
	el := html.El("div")
	el.AddAttribute("class", "container-fluid")
	child := html.El("p").AddString("some text")
	el.AddHtml(child)
	
	return el.Render()
}

Commit rules

Commit message should looks like

[TYPE] some message
Types
  • Add
  • Fix
  • Update
  • Remove
  • Refactor
  • Docs
  • Test
  • Improve

Contributors

JanGalek actions-user

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Attribute

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

func NewAttribute

func NewAttribute(name string, value interface{}) *Attribute

NewAttribute create new attribute for html element

func (*Attribute) GetValueString

func (a *Attribute) GetValueString() string

GetValueString convert value to string

func (*Attribute) ToHtml

func (a *Attribute) ToHtml() string

ToHtml create html string

type Html

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

func El

func El(name string) *Html

El create html element Example:

el := El("p")

func (*Html) AddAttribute

func (h *Html) AddAttribute(name string, value interface{}) *Html

AddAttribute add attribute to element Example:

el := El("div")
el.AddAttribute("class", "container")

func (*Html) AddAttributes

func (h *Html) AddAttributes(attributes []map[string]interface{}) *Html

AddAttributes add attributes to element Example:

el := El("div")

el.AddAttributes([]map[string]interface{}{
	{"class": "container"},
	{"id": "main"},
})

func (*Html) AddChild

func (h *Html) AddChild(child interface{}) *Html

AddChild add mixed child to element

func (*Html) AddChildren

func (h *Html) AddChildren(children []interface{}) *Html

AddChildren add mixed children to element

func (*Html) AddData added in v1.0.1

func (h *Html) AddData(data map[string]string) *Html

AddData add attributes with prefix data-* to element Example:

el := El("div")
el.AddData(map[string][string{"level": "35",})

func (*Html) AddHtml

func (h *Html) AddHtml(child *Html) *Html

AddHtml add html child to element Example:

el := El("div")
child := El("p").AddString("some text")
el.AddHtml(child)

func (*Html) AddHtmlChildren

func (h *Html) AddHtmlChildren(children []*Html) *Html

AddHtmlChildren add html children to element Example:

el := El("div")
p := El("p").AddString("some text")
div := El("div")
children := []*html.Html{div, p}
el.AddHtmlChildren(children)

func (*Html) AddId added in v1.0.4

func (h *Html) AddId(id string) *Html

AddId add id attribute to element Example:

el := El("div")
el.AddId("root")

func (*Html) AddString

func (h *Html) AddString(str string) *Html

AddString add html children to element Example:

p := El("p").AddString("some text")

func (*Html) AddStringChildren

func (h *Html) AddStringChildren(strings []string) *Html

AddStringChildren add string children to element Example:

el := El("div")
children := []string{"some text", "<p>another text</p>"}
el.AddHtmlChildren(children)

func (*Html) GetAttribute

func (h *Html) GetAttribute(name string) *Attribute

GetAttribute get single attribute of element

func (*Html) GetAttributes

func (h *Html) GetAttributes() []*Attribute

GetAttributes get attributes of element

func (*Html) GetChildren

func (h *Html) GetChildren() []interface{}

GetChildren get html children of element

func (*Html) GetName

func (h *Html) GetName() string

GetName get html element name

func (*Html) IsEmpty

func (h *Html) IsEmpty() bool

IsEmpty check if element is pair

func (*Html) RemoveAttribute

func (h *Html) RemoveAttribute(name string) *Html

RemoveAttribute remove attribute from element

func (*Html) RemoveAttributes

func (h *Html) RemoveAttributes(names []string) *Html

RemoveAttributes remove multiple attributes from element

func (*Html) RemoveChildren

func (h *Html) RemoveChildren() *Html

RemoveChildren clear children node of element

func (*Html) Render

func (h *Html) Render(level ...int) string

Render render html to string Example:

el := El("div")
children := []string{"some text", "<p>another text</p>"}
el.AddHtmlChildren(children)
html := el.Render()

func (*Html) UpdateEmpty

func (h *Html) UpdateEmpty() *Html

UpdateEmpty update element status pair

Jump to

Keyboard shortcuts

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