本文整理汇总了Golang中github.com/kpmy/ot/otm.Object.Children方法的典型用法代码示例。如果您正苦于以下问题:Golang Object.Children方法的具体用法?Golang Object.Children怎么用?Golang Object.Children使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/kpmy/ot/otm.Object
的用法示例。
在下文中一共展示了Object.Children方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: prettyPrintObject
func prettyPrintObject(o otm.Object, log *testing.T) {
parent := ""
for x := o.Parent(); !fn.IsNil(x); x = x.Parent() {
parent = fmt.Sprint(x.Qualident(), "<-", parent)
}
log.Log(parent, o.Qualident())
if o.ChildrenCount() > 0 {
log.Log(":")
for _x := range o.Children() {
switch x := _x.(type) {
case otm.Object:
prettyPrintObject(x, log)
case otm.Link:
log.Log("@", x.Object().Qualident())
case string, float64, int64, rune, tri.Trit:
log.Log(_x)
case []uint8:
s := zbase32.EncodeToString(x)
log.Log("zbase32(", s, ")", x)
default:
halt.As(100, reflect.TypeOf(x))
}
}
log.Log(";")
}
}
示例2: object
func (f *fm) object(o otm.Object) {
q := o.Qualident()
if q.Template != "" {
f.Ident(q.Template)
f.Char('~')
}
f.Ident(q.Class)
if q.Identifier != "" {
f.Char('(')
f.Ident(q.Identifier)
f.Char(')')
}
if o.ChildrenCount() > 0 {
f.Char(':')
for _x := range o.Children() {
f.Char(' ')
switch x := _x.(type) {
case otm.Object:
f.object(x)
case string:
f.stringValue(x)
case int64:
i := strconv.Itoa(int(x))
f.RawString(i)
case float64:
if math.IsInf(x, 1) {
f.RawString("inf")
} else if math.IsInf(x, -1) {
f.RawString("-inf")
} else {
f_ := strconv.FormatFloat(x, 'f', 8, 64)
f.RawString(f_)
}
case rune:
r := strconv.FormatUint(uint64(x), 16)
f.RawString("0" + r + "U")
case tri.Trit:
f.Trinary(x)
case []uint8:
f.RawString(zbase32.EncodeToString(x))
default:
halt.As(100, reflect.TypeOf(x))
}
}
f.Char(';')
} else {
f.Char(' ')
}
}
示例3: renderHtml
func renderHtml(o otm.Object, log *testing.T) {
buf := bytes.NewBufferString("<!DOCTYPE HTML>")
e := xml.NewEncoder(buf)
var obj func(otm.Object)
obj = func(o otm.Object) {
clazz := o.InstanceOf().Qualident()
if clazz.Template == "html" {
start := xml.StartElement{}
start.Name.Local = clazz.Class
if id := o.Qualident().Identifier; id != "" {
attr := xml.Attr{}
attr.Name.Local = "id"
attr.Value = id
start.Attr = append(start.Attr, attr)
}
e.EncodeToken(start)
for _x := range o.Children() {
switch x := _x.(type) {
case otm.Object:
obj(x)
case string:
e.EncodeToken(xml.CharData([]byte(x)))
default:
halt.As(100, reflect.TypeOf(x))
}
}
e.EncodeToken(start.End())
}
}
for x := range o.ChildrenObjects() {
if x.InstanceOf().Qualident().Template == "html" && x.InstanceOf().Qualident().Class == "html" {
obj(x)
}
}
e.Flush()
log.Log(buf.String())
}