package jen
import (
"fmt"
"io"
"sort"
"strconv"
)
func Tag (items map [string ]string ) *Statement {
return newStatement ().Tag (items )
}
func (g *Group ) Tag (items map [string ]string ) *Statement {
s := Tag (items )
g .items = append (g .items , s )
return s
}
func (s *Statement ) Tag (items map [string ]string ) *Statement {
c := tag {
items : items ,
}
*s = append (*s , c )
return s
}
type tag struct {
items map [string ]string
}
func (t tag ) isNull (f *File ) bool {
return len (t .items ) == 0
}
func (t tag ) render (f *File , w io .Writer , s *Statement ) error {
if t .isNull (f ) {
return nil
}
var str string
var sorted []string
for k := range t .items {
sorted = append (sorted , k )
}
sort .Strings (sorted )
for _ , k := range sorted {
v := t .items [k ]
if len (str ) > 0 {
str += " "
}
str += fmt .Sprintf (`%s:%q` , k , v )
}
if strconv .CanBackquote (str ) {
str = "`" + str + "`"
} else {
str = strconv .Quote (str )
}
if _ , err := w .Write ([]byte (str )); err != nil {
return err
}
return nil
}
The pages are generated with Golds v0.8.4 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .