本文整理匯總了Golang中offend/me/uk/thiy/common.TagNode.Attributes方法的典型用法代碼示例。如果您正苦於以下問題:Golang TagNode.Attributes方法的具體用法?Golang TagNode.Attributes怎麽用?Golang TagNode.Attributes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類offend/me/uk/thiy/common.TagNode
的用法示例。
在下文中一共展示了TagNode.Attributes方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: makeFormControl
func makeFormControl(in common.TagNode) (out common.TagNode) {
if in.Tag != "input" && in.Tag != "select" {
panic("attempt to make a bootstrap from control out of a non-input")
}
out.Tag = "div"
out.Classes = []string{"form-group"}
in.Classes = append(in.Classes, "form-control")
var attrs []common.Attribute
for _, attr := range in.Attributes {
include := true
if attr.Name == "label" {
labelNode := common.TagNode{
Tag: "label",
Classes: []string{"control-label"},
Content: []common.Node{
common.TextNode{attr.Value},
},
}
if in.Id != "" {
labelNode.Attributes = []common.Attribute{
{"for", in.Id},
}
}
out.Content = append(out.Content, labelNode)
include = false
}
if include {
attrs = append(attrs, attr)
}
}
in.Attributes = attrs
if len(in.Content) == 1 {
if textNode, ok := in.Content[0].(common.TextNode); ok {
in.Attributes = append(in.Attributes, common.Attribute{"placeholder", textNode.Content})
in.Content = nil
}
}
out.Content = append(out.Content, in)
return
}
示例2: makeInclude
func makeInclude(in common.TagNode) common.TagNode {
if len(in.Content) != 1 {
return in
}
textNode, ok := in.Content[0].(common.TextNode)
if !ok {
return in
}
if strings.HasSuffix(textNode.Content, ".js") {
in.Tag = "script"
in.Attributes = append(in.Attributes, common.Attribute{"src", textNode.Content})
in.Content = nil
} else if strings.HasSuffix(textNode.Content, ".css") {
in.Tag = "link"
in.Attributes = append(in.Attributes, []common.Attribute{
{"rel", "stylesheet"},
{"href", textNode.Content},
}...)
in.Content = nil
} else if strings.HasSuffix(textNode.Content, ".ico") {
in.Tag = "link"
in.Attributes = append(in.Attributes, []common.Attribute{
{"rel", "shortcut icon"},
{"href", textNode.Content},
}...)
in.Content = nil
} else if strings.HasSuffix(textNode.Content, ".xml") {
in.Tag = "link"
in.Attributes = append(in.Attributes, []common.Attribute{
{"rel", "alternate"},
{"type", "application/rss+xml"},
{"href", textNode.Content},
}...)
in.Content = nil
} else if strings.HasSuffix(textNode.Content, ".atom") {
in.Tag = "link"
in.Attributes = append(in.Attributes, []common.Attribute{
{"rel", "alternate"},
{"type", "application/atom+xml"},
{"href", textNode.Content},
}...)
in.Content = nil
}
return in
}
示例3: makeMeta
func makeMeta(in common.TagNode) common.TagNode {
if len(in.Attributes) != 1 {
return in
}
if in.Attributes[0].Value != "" {
return in
}
if len(in.Content) != 1 {
return in
}
textNode, ok := in.Content[0].(common.TextNode)
if !ok {
return in
}
in.Attributes = []common.Attribute{
{"name", in.Attributes[0].Name},
{"content", textNode.Content},
}
in.Content = nil
return in
}
示例4: makeCol
func makeCol(in common.TagNode) common.TagNode {
if in.Tag != "col" {
panic("attempt to make a bootstrap col out of a non-col")
}
in.Tag = "div"
var attrs []common.Attribute
for _, attr := range in.Attributes {
include := true
for _, size := range bsSizes {
if attr.Name == size {
in.Classes = append(in.Classes, "col-"+attr.Name+"-"+attr.Value)
include = false
}
}
if include {
attrs = append(attrs, attr)
}
}
in.Attributes = attrs
return in
}