本文整理汇总了Golang中github.com/ungerik/go-start/utils.XMLWriter.Content方法的典型用法代码示例。如果您正苦于以下问题:Golang XMLWriter.Content方法的具体用法?Golang XMLWriter.Content怎么用?Golang XMLWriter.Content使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/ungerik/go-start/utils.XMLWriter
的用法示例。
在下文中一共展示了XMLWriter.Content方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Render
func (self *TextPreview) Render(context *Context, writer *utils.XMLWriter) (err error) {
if len(self.PlainText) < self.MaxLength {
writer.Content(self.PlainText)
} else {
shortLength := self.ShortLength
if shortLength == 0 {
shortLength = self.MaxLength
}
// If in the middle of a word, go back to space before it
for shortLength > 0 && !unicode.IsSpace(rune(self.PlainText[shortLength-1])) {
shortLength--
}
// If in the middle of space, go back to word before it
for shortLength > 0 && unicode.IsSpace(rune(self.PlainText[shortLength-1])) {
shortLength--
}
writer.Content(self.PlainText[:shortLength])
writer.Content("... ")
if self.MoreLink != nil {
writer.OpenTag("a")
writer.Attrib("href", self.MoreLink.URL(context.PathArgs...))
writer.AttribIfNotDefault("title", self.MoreLink.LinkTitle(context))
content := self.MoreLink.LinkContent(context)
if content != nil {
err = content.Render(context, writer)
}
writer.ForceCloseTag() // a
}
}
return err
}
示例2: Render
func (self HTML) Render(context *Context, writer *utils.XMLWriter) (err error) {
writer.Content(string(self))
return nil
}
示例3: RenderItem
func (self *StringsSelectModel) RenderItem(index int, context *Context, writer *utils.XMLWriter) (err error) {
writer.Content(self.Options[index])
return nil
}
示例4: Render
func (self *Menu) Render(context *Context, writer *utils.XMLWriter) (err error) {
writer.OpenTag("ul").Attrib("id", self.id).AttribIfNotDefault("class", self.Class)
requestURL := context.RequestURL()
// Find active item
activeIndex := -1
if self.ActiveItemClass != "" {
// First try exact URL match
for i := range self.Items {
url := self.Items[i].URL(context.PathArgs...)
if url == requestURL {
activeIndex = i
break
}
}
// If no exact URL match is found, search for sub pages
if activeIndex == -1 {
for i := range self.Items {
url := self.Items[i].URL(context.PathArgs...)
if strings.HasPrefix(requestURL, url) {
activeIndex = i
// todo
// not perfect, what if homepage matches first, but other matches better?
}
}
}
}
for i := range self.Items {
index := i
if self.Reverse {
index = len(self.Items) - 1 - i
}
itemClass := self.ItemClass
linkModel := self.Items[index]
url := linkModel.URL(context.PathArgs...)
// use i instead of index
if i == activeIndex {
itemClass += " " + self.ActiveItemClass
}
writer.OpenTag("li").Attrib("id", self.id, "_", index).AttribIfNotDefault("class", itemClass)
if i > 0 && self.BetweenItems != "" {
writer.Content(self.BetweenItems)
}
writer.OpenTag("a")
writer.Attrib("href", url)
writer.AttribIfNotDefault("title", linkModel.LinkTitle(context))
writer.AttribIfNotDefault("rel", linkModel.LinkRel(context))
content := linkModel.LinkContent(context)
if content != nil {
err = content.Render(context, writer)
if err != nil {
return err
}
}
writer.ForceCloseTag() // a
writer.ForceCloseTag() // li
}
writer.ForceCloseTag() // ul
return nil
}