当前位置: 首页>>代码示例>>Golang>>正文


Golang XMLWriter.OpenTag方法代码示例

本文整理汇总了Golang中github.com/ungerik/go-start/utils.XMLWriter.OpenTag方法的典型用法代码示例。如果您正苦于以下问题:Golang XMLWriter.OpenTag方法的具体用法?Golang XMLWriter.OpenTag怎么用?Golang XMLWriter.OpenTag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/ungerik/go-start/utils.XMLWriter的用法示例。


在下文中一共展示了XMLWriter.OpenTag方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
}
开发者ID:sedzinreri,项目名称:go-start,代码行数:34,代码来源:textpreview.go

示例2: Render

func (self *DummyImage) Render(context *Context, writer *utils.XMLWriter) (err error) {
	src := fmt.Sprintf("http://dummyimage.com/%dx%d", self.Width, self.Height)

	if self.BackgroundColor != "" || self.ForegroundColor != "" {
		if self.BackgroundColor != "" {
			src += "/" + self.BackgroundColor
		} else {
			src += "/ccc"
		}

		if self.ForegroundColor != "" {
			src += "/" + self.ForegroundColor
		}
	}

	src += ".png"

	if self.Text != "" {
		src += "&text=" + url.QueryEscape(self.Text)
	}

	writer.OpenTag("img").Attrib("id", self.id).AttribIfNotDefault("class", self.Class)
	writer.Attrib("src", src)
	writer.AttribIfNotDefault("width", self.Width)
	writer.AttribIfNotDefault("height", self.Height)
	writer.AttribIfNotDefault("alt", self.Text)
	writer.CloseTag()
	return nil
}
开发者ID:sedzinreri,项目名称:go-start,代码行数:29,代码来源:dummyimage.go

示例3: Render

func (self *Video) Render(context *Context, writer *utils.XMLWriter) (err error) {
	youtubeId := ""

	switch {
	case strings.HasPrefix(self.URL, "http://youtu.be/"):
		i := len("http://youtu.be/")
		youtubeId = self.URL[i : i+11]

	case strings.HasPrefix(self.URL, "http://www.youtube.com/watch?v="):
		i := len("http://www.youtube.com/watch?v=")
		youtubeId = self.URL[i : i+11]
	}

	if youtubeId != "" {
		writer.OpenTag("iframe").Attrib("id", self.id).AttribIfNotDefault("class", self.Class)
		width := self.Width
		if width == 0 {
			width = 640
		}
		height := self.Height
		if height == 0 {
			height = 390
		}
		writer.Attrib("src", "http://www.youtube.com/embed/", youtubeId)
		writer.Attrib("width", width)
		writer.Attrib("height", height)
		writer.Attrib("frameborder", "0")
		writer.Attrib("allowfullscreen", "allowfullscreen")
		writer.CloseTag()
		return nil
	}

	return errs.Format("Unsupported video URL: %s", self.URL)
}
开发者ID:sedzinreri,项目名称:go-start,代码行数:34,代码来源:video.go

示例4: Render

func (self *TextArea) Render(context *Context, writer *utils.XMLWriter) (err error) {
	writer.OpenTag("textarea").Attrib("id", self.id).AttribIfNotDefault("class", self.Class)

	cols := self.Cols
	if cols == 0 {
		cols = TextAreaDefaultCols
	}
	rows := self.Rows
	if rows == 0 {
		rows = TextAreaDefaultRows
	}

	writer.Attrib("name", self.Name)
	writer.Attrib("rows", rows)
	writer.Attrib("cols", cols)
	writer.AttribIfNotDefault("tabindex", self.TabIndex)
	if self.Readonly {
		writer.Attrib("readonly", "readonly")
	}
	if self.Disabled {
		writer.Attrib("disabled", "disabled")
	}

	writer.EscapeContent(self.Text)
	writer.CloseTag()
	return nil
}
开发者ID:sedzinreri,项目名称:go-start,代码行数:27,代码来源:textarea.go

示例5: Render

func (self *TextField) Render(context *Context, writer *utils.XMLWriter) (err error) {
	writer.OpenTag("input").Attrib("id", self.id).AttribIfNotDefault("class", self.Class)

	writer.Attrib("name", self.Name)
	writer.AttribIfNotDefault("tabindex", self.TabIndex)
	if self.Readonly {
		writer.Attrib("readonly", "readonly")
	}
	if self.Disabled {
		writer.Attrib("disabled", "disabled")
	}

	switch self.Type {
	case PasswordTextField:
		writer.Attrib("type", "password")
	case EmailTextField:
		writer.Attrib("type", "email")
	default:
		writer.Attrib("type", "text")
	}

	writer.AttribIfNotDefault("size", self.Size)
	writer.AttribIfNotDefault("maxlength", self.MaxLength)
	writer.Attrib("value", self.Text)

	writer.CloseTag()
	return nil
}
开发者ID:sedzinreri,项目名称:go-start,代码行数:28,代码来源:textfield.go

示例6: Render

func (self *HiddenInput) Render(context *Context, writer *utils.XMLWriter) (err error) {
	writer.OpenTag("input").Attrib("id", self.id)
	writer.Attrib("type", "hidden")
	writer.Attrib("name", self.Name)
	writer.Attrib("value", self.Value)
	writer.CloseTag()
	return nil
}
开发者ID:sedzinreri,项目名称:go-start,代码行数:8,代码来源:hiddeninput.go

示例7: Render

func (self *Paragraph) Render(context *Context, writer *utils.XMLWriter) (err error) {
	writer.OpenTag("p").Attrib("id", self.id).AttribIfNotDefault("class", self.Class)
	if self.Content != nil {
		err = self.Content.Render(context, writer)
	}
	writer.ForceCloseTag()
	return err
}
开发者ID:sedzinreri,项目名称:go-start,代码行数:8,代码来源:paragraph.go

示例8: Render

func (self *Image) Render(context *Context, writer *utils.XMLWriter) (err error) {
	writer.OpenTag("img").Attrib("id", self.id).AttribIfNotDefault("class", self.Class)
	writer.Attrib("src", self.URL)
	writer.AttribIfNotDefault("width", self.Width)
	writer.AttribIfNotDefault("height", self.Height)
	writer.AttribIfNotDefault("alt", self.Description)
	writer.CloseTag()
	return nil
}
开发者ID:sedzinreri,项目名称:go-start,代码行数:9,代码来源:image.go

示例9: Render

func (self *FileInput) Render(context *Context, writer *utils.XMLWriter) (err error) {
	writer.OpenTag("input").Attrib("id", self.id).AttribIfNotDefault("class", self.Class)
	writer.Attrib("type", "file").Attrib("name", self.Name)
	if self.Disabled {
		writer.Attrib("disabled", "disabled")
	}
	writer.CloseTag()
	return err
}
开发者ID:sedzinreri,项目名称:go-start,代码行数:9,代码来源:fileinput.go

示例10: Render

func (self *ShortTag) Render(context *Context, writer *utils.XMLWriter) (err error) {
	writer.OpenTag(self.Tag).AttribIfNotDefault("class", self.Class)
	for key, value := range self.Attribs {
		writer.Attrib(key, value)
	}
	if self.Content != nil {
		err = self.Content.Render(context, writer)
	}
	writer.ForceCloseTag()
	return err
}
开发者ID:sedzinreri,项目名称:go-start,代码行数:11,代码来源:shorttag.go

示例11: Render

func (self *Label) Render(context *Context, writer *utils.XMLWriter) (err error) {
	var forID string
	if self.For != nil {
		forID = self.For.ID()
	}
	writer.OpenTag("label").Attrib("id", self.id).AttribIfNotDefault("class", self.Class)
	writer.AttribIfNotDefault("for", forID)
	if self.Content != nil {
		err = self.Content.Render(context, writer)
	}
	writer.CloseTag()
	return err
}
开发者ID:sedzinreri,项目名称:go-start,代码行数:13,代码来源:label.go

示例12: Render

func (self *Table) Render(context *Context, writer *utils.XMLWriter) (err error) {
	writer.OpenTag("table").Attrib("id", self.id).AttribIfNotDefault("class", self.Class)

	if self.Caption != "" {
		writer.OpenTag("caption").EscapeContent(self.Caption).CloseTag()
	}

	if self.Model != nil {
		rows := self.Model.Rows()
		columns := self.Model.Columns()

		for row := 0; row < rows; row++ {
			writer.OpenTag("tr")
			if row&1 == 0 {
				writer.Attrib("class", "row", row, " even")
			} else {
				writer.Attrib("class", "row", row, " odd")
			}

			for col := 0; col < columns; col++ {
				if self.HeaderRow && row == 0 {
					writer.OpenTag("th")
				} else {
					writer.OpenTag("td")
				}
				if col&1 == 0 {
					writer.Attrib("class", "col", col, " even")
				} else {
					writer.Attrib("class", "col", col, " odd")
				}
				view, err := self.Model.CellView(row, col, context)
				if view != nil && err == nil {
					view.Init(view)
					err = view.Render(context, writer)
				}
				if err != nil {
					return err
				}
				writer.ForceCloseTag() // td/th
			}

			writer.ForceCloseTag() // tr
		}
	}

	writer.ForceCloseTag() // table
	return nil
}
开发者ID:sedzinreri,项目名称:go-start,代码行数:48,代码来源:table.go

示例13: Render

func (self *Iframe) Render(context *Context, writer *utils.XMLWriter) (err error) {
	writer.OpenTag("iframe").Attrib("id", self.id).AttribIfNotDefault("class", self.Class)
	writer.Attrib("width", self.Width).Attrib("height", self.Height)
	writer.Attrib("frameborder", self.Border)
	writer.Attrib("marginwidth", self.MarginWidth).Attrib("marginheight", self.MarginHeight)
	if self.Scrolling {
		writer.Attrib("scrolling", "yes")
	} else {
		writer.Attrib("scrolling", "no")
	}
	if self.Seamless {
		writer.Attrib("seamless", "seamless")
	}
	writer.Attrib("src", self.URL)
	writer.ForceCloseTag()
	return nil
}
开发者ID:sedzinreri,项目名称:go-start,代码行数:17,代码来源:iframe.go

示例14: Render

func (self *Link) Render(context *Context, writer *utils.XMLWriter) (err error) {
	writer.OpenTag("a").AttribIfNotDefault("id", self.id)
	writer.AttribIfNotDefault("class", self.Class)
	if self.NewWindow {
		writer.Attrib("target", "_blank")
	}
	if self.Model != nil {
		writer.Attrib("href", self.Model.URL(context.PathArgs...))
		writer.AttribIfNotDefault("title", self.Model.LinkTitle(context))
		writer.AttribIfNotDefault("rel", self.Model.LinkRel(context))
		content := self.Model.LinkContent(context)
		if content != nil {
			err = content.Render(context, writer)
		}
	}
	writer.ForceCloseTag() // a
	return err
}
开发者ID:sedzinreri,项目名称:go-start,代码行数:18,代码来源:link.go

示例15: Render

func (self *Checkbox) Render(context *Context, writer *utils.XMLWriter) (err error) {
	writer.OpenTag("input").Attrib("id", self.id).AttribIfNotDefault("class", self.Class)
	writer.Attrib("type", "checkbox")
	writer.Attrib("name", self.Name)
	writer.Attrib("value", "true")
	if self.Disabled {
		writer.Attrib("disabled", "disabled")
	}
	if self.Checked {
		writer.Attrib("checked", "checked")
	}
	writer.CloseTag()

	if self.Label != "" {
		writer.OpenTag("label").Attrib("for", self.id).Content(self.Label).CloseTag()
	}
	return nil
}
开发者ID:sedzinreri,项目名称:go-start,代码行数:18,代码来源:checkbox.go


注:本文中的github.com/ungerik/go-start/utils.XMLWriter.OpenTag方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。