Documentation ¶
Index ¶
- Variables
- func Add(to HasChildren, add ...Element)
- func AddClass(w AttrsMapper, class ...string)
- func DeleteAttr(w AttrsMapper, key string, values ...string)
- func DeleteClass(w AttrsMapper, class ...string)
- func SetAccept(w AttrsMapper, accept string)
- func SetAction(w AttrsMapper, action string)
- func SetAsync(w AttrsMapper)
- func SetAttr(w AttrsMapper, key string, value ...string)
- func SetAttrNoValue(w AttrsMapper, key string)
- func SetAutoComplete(w AttrsMapper, on bool)
- func SetChecked(w AttrsMapper, checked bool)
- func SetClass(w AttrsMapper, class ...string)
- func SetDisabled(w AttrsMapper, disabled bool)
- func SetForm(w AttrsMapper, form string)
- func SetFormAction(w AttrsMapper, formAction string)
- func SetHeight(w AttrsMapper, height string)
- func SetID(w AttrsMapper, id string)
- func SetLang(w AttrsMapper, lang string)
- func SetList(w AttrsMapper, list string)
- func SetMax(w AttrsMapper, max string)
- func SetMaxLength(w AttrsMapper, maxLen int)
- func SetMethod(w AttrsMapper, method string)
- func SetMin(w AttrsMapper, min string)
- func SetMinLength(w AttrsMapper, minLen int)
- func SetName(w AttrsMapper, name string)
- func SetOnBlur(w AttrsMapper, script string)
- func SetOnChange(w AttrsMapper, script string)
- func SetOnClick(w AttrsMapper, script string)
- func SetOnFocus(w AttrsMapper, script string)
- func SetOnFormChange(w AttrsMapper, script string)
- func SetOnFormInput(w AttrsMapper, script string)
- func SetOnInput(w AttrsMapper, script string)
- func SetOnInvalid(w AttrsMapper, script string)
- func SetOnKeyDown(w AttrsMapper, script string)
- func SetOnKeyPress(w AttrsMapper, script string)
- func SetOnKeyUp(w AttrsMapper, script string)
- func SetOnReset(w AttrsMapper, script string)
- func SetOnSelect(w AttrsMapper, script string)
- func SetOnSubmit(w AttrsMapper, script string)
- func SetReadOnly(w AttrsMapper, readonly bool)
- func SetRequired(w AttrsMapper, required bool)
- func SetSelected(w AttrsMapper, checked bool)
- func SetSize(w AttrsMapper, size int)
- func SetSrc(w AttrsMapper, src string)
- func SetTarget(w AttrsMapper, target string)
- func SetTitle(w AttrsMapper, title string)
- func SetType(w AttrsMapper, tp string)
- func SetValue(w AttrsMapper, value string)
- func SetWidth(w AttrsMapper, width string)
- type A
- type Any
- func NewAny(tag string) *Any
- func NewArticle() *Any
- func NewBody() *Any
- func NewButton(value string) *Any
- func NewCode() *Any
- func NewDL() *Any
- func NewDT() *Any
- func NewDiv() *Any
- func NewFieldSet() *Any
- func NewFigCaption() *Any
- func NewFigure() *Any
- func NewForm(method string, action string) *Any
- func NewHTML() *Any
- func NewHead() *Any
- func NewInput(tp string, name string) *Any
- func NewLabel(e Element) *Any
- func NewLegend(e Element) *Any
- func NewNav() *Any
- func NewOl(values StringSlice) *Any
- func NewOption(value string, b Element) *Any
- func NewP() *Any
- func NewPre() *Any
- func NewScript() *Any
- func NewSelect(opts ...Element) *Any
- func NewStyle() *Any
- func NewSubmit(value string) *Any
- func NewTd(val ...Element) *Any
- func NewTh(val ...Element) *Any
- func NewTitle(c Element) *Any
- func NewUl(values StringSlice) *Any
- func WithAny(a *Any, fn func(*Any)) *Any
- type Attr
- type Attrs
- type AttrsMapper
- type Bytes
- type Comment
- type Element
- type Elements
- type HasChildren
- type IMG
- type Link
- type Meta
- type String
- type StringSlice
- type StyleAttr
- func (s *StyleAttr) BackgroundColor(color string) *StyleAttr
- func (s *StyleAttr) Border(val string) *StyleAttr
- func (s *StyleAttr) Color(color string) *StyleAttr
- func (s *StyleAttr) Font(val string) *StyleAttr
- func (s *StyleAttr) FontFamily(val string) *StyleAttr
- func (s *StyleAttr) FontSize(val string) *StyleAttr
- func (s *StyleAttr) FontWeight(val string) *StyleAttr
- func (s *StyleAttr) Get(key string) string
- func (s *StyleAttr) HTML() ([]byte, error)
- func (s *StyleAttr) Height(h string) *StyleAttr
- func (s *StyleAttr) Margin(val string) *StyleAttr
- func (s *StyleAttr) MaxHeight(h string) *StyleAttr
- func (s *StyleAttr) MaxWidth(w string) *StyleAttr
- func (s *StyleAttr) MinHeight(h string) *StyleAttr
- func (s *StyleAttr) MinWidth(w string) *StyleAttr
- func (s *StyleAttr) Padding(val string) *StyleAttr
- func (s *StyleAttr) SetTo(a AttrsMapper) error
- func (s *StyleAttr) TextAlign(align string) *StyleAttr
- func (s *StyleAttr) Width(w string) *StyleAttr
- type Table1
- type Text
- type WithAttrs
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // NL 换行: \n NL = Bytes("\n") // BR HTML 换行 br BR = Bytes("<br/>") // HR HTML 分割符 hr HR = Bytes("<hr/>") )
View Source
var ErrEmptyTagName = errors.New("empty tag name")
ErrEmptyTagName tag 值为空的错误
Functions ¶
func SetAttrNoValue ¶
func SetAttrNoValue(w AttrsMapper, key string)
SetAttrNoValue 设置只有 key,不需要 value 的属性
func SetAutoComplete ¶
func SetAutoComplete(w AttrsMapper, on bool)
SetAutoComplete 设置 autocomplete 属性
func SetFormAction ¶
func SetFormAction(w AttrsMapper, formAction string)
SetFormAction 设置 formaction 属性
func SetOnFormChange ¶
func SetOnFormChange(w AttrsMapper, script string)
SetOnFormChange 设置 onformchange 属性
func SetOnFormInput ¶
func SetOnFormInput(w AttrsMapper, script string)
SetOnFormInput 设置 onforminput 属性
func SetOnKeyPress ¶
func SetOnKeyPress(w AttrsMapper, script string)
SetOnKeyPress 设置 onkeypress 属性
Types ¶
type Any ¶
type Any struct { // Tag 标签名称,必填,如 div Tag string // WithAttrs 可选,属性信息 WithAttrs // Body 内容,可选 Body Elements // SelfClose 当前标签是否自关闭,默认为 false // 如 img 标签就是自关闭的:<img src="/a.jpg"/> SelfClose bool }
Any 一块 HTML 内容
func NewHTML ¶
func NewHTML() *Any
NewHTML html 标签
Example ¶
package main import ( "fmt" "github.com/fsgo/fsgo/fshtml" ) func main() { h := fshtml.NewHTML() fshtml.Add(h, fshtml.WithAny(fshtml.NewHead(), func(a *fshtml.Any) { fshtml.Add(a, fshtml.NewTitle(fshtml.Text("hello"))) }), fshtml.WithAny(fshtml.NewBody(), func(a *fshtml.Any) { fshtml.Add(a, fshtml.Text("Hello World")) }), ) got, _ := h.HTML() fmt.Println(string(got)) }
Output: <html><head><title>hello</title></head><body>Hello World</body></html>
func NewOl ¶
func NewOl(values StringSlice) *Any
NewOl 转换为 ol
Example ¶
package main import ( "fmt" "github.com/fsgo/fsgo/fshtml" ) func main() { values := []string{"1", "2", "3"} ul := fshtml.NewOl(values) style := &fshtml.StyleAttr{} _ = style.Width("180px").Height("20px").SetTo(ul) got, _ := ul.HTML() fmt.Println(string(got)) }
Output: <ol style="width:180px; height:20px"><li>1</li><li>2</li><li>3</li></ol>
func NewUl ¶
func NewUl(values StringSlice) *Any
NewUl 转换为 ul
Example ¶
package main import ( "fmt" "github.com/fsgo/fsgo/fshtml" ) func main() { values := []string{"1", "2", "3"} ul := fshtml.NewUl(values) got, _ := ul.HTML() fmt.Println(string(got)) }
Output: <ul><li>1</li><li>2</li><li>3</li></ul>
type Attr ¶
type Attr struct { // Key 属性的名字 Key string // Values 属性值,可以有多个 Values fstypes.StringSlice }
Attr 一个属性
type Attrs ¶
type Attrs struct { // Sep 多个属性间的连接符,当为空时,使用默认值 " " (一个空格) Sep string // KVSep key 和 value 之间的连接符,当为空时,使用默认值 = KVSep string // contains filtered or unexported fields }
Attrs 多个属性
type AttrsMapper ¶
AttrsMapper 具有 AttrsMapper 方法
type Elements ¶
type Elements []Element
Elements alias of []Element
func (*Elements) InsertFront ¶
InsertFront to the frontend
type HasChildren ¶
HasChildren 允许添加子元素
type StringSlice ¶
type StringSlice []string
StringSlice 将 []string 转换为 Element 类型
func (StringSlice) ToElements ¶
func (ss StringSlice) ToElements(tag string, fn func(b *Any)) Elements
ToElements 转换为 字段 tag 的 []Element
type StyleAttr ¶
type StyleAttr struct {
WithAttrs
}
StyleAttr style 属性
func (*StyleAttr) BackgroundColor ¶
BackgroundColor 设置背景演示
func (*StyleAttr) FontFamily ¶
FontFamily 设置字体系列(字体族)
func (*StyleAttr) FontWeight ¶
FontWeight 设置字体粗细
type Table1 ¶
type Table1 struct { WithAttrs // contains filtered or unexported fields }
Table1 一个简单的表格
Click to show internal directories.
Click to hide internal directories.