當前位置: 首頁>>代碼示例>>Golang>>正文


Golang utils.XMLWriter類代碼示例

本文整理匯總了Golang中github.com/ungerik/go-start/utils.XMLWriter的典型用法代碼示例。如果您正苦於以下問題:Golang XMLWriter類的具體用法?Golang XMLWriter怎麽用?Golang XMLWriter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了XMLWriter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: 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

示例2: Render

func (self *Format) Render(context *Context, writer *utils.XMLWriter) (err error) {
	if self.Escape {
		writer.PrintfEscape(self.Text, self.Args...)
	} else {
		writer.Printf(self.Text, self.Args...)
	}
	return nil
}
開發者ID:sedzinreri,項目名稱:go-start,代碼行數:8,代碼來源:format.go

示例3: 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

示例4: 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

示例5: Render

func (self *CachedView) Render(context *Context, writer *utils.XMLWriter) (err error) {
	if self.Content == nil {
		return nil
	}
	if Config.DisableCachedViews || len(context.Params) > 0 || context.Request.Method != "GET" {
		return self.Content.Render(context, writer)
	}
	if self.data == nil || time.Now().After(self.validUntil) {
		xmlBuffer := utils.NewXMLBuffer()
		err = self.Content.Render(context, &xmlBuffer.XMLWriter)
		if err != nil {
			return err
		}
		self.data = xmlBuffer.Bytes()
		self.validUntil = time.Now().Add(self.Duration)
	}
	_, err = writer.Write(self.data)
	return err
}
開發者ID:sedzinreri,項目名稱:go-start,代碼行數:19,代碼來源:cachedview.go

示例6: Render

func (self *StaticFile) Render(context *Context, writer *utils.XMLWriter) (err error) {
	filePath, found, modified := FindStaticFile(self.Filename)
	if !found {
		return errs.Format("Static file not found: %s", self.Filename)
	}

	if self.ContentTypeExt == "" {
		self.ContentTypeExt = path.Ext(filePath)
	}

	if self.fileContent == nil || modified > self.modifiedTime {
		self.fileContent, err = ioutil.ReadFile(filePath)
		if err != nil {
			return err
		}
	}

	context.ContentType(self.ContentTypeExt)
	writer.Write(self.fileContent)
	return nil
}
開發者ID:sedzinreri,項目名稱:go-start,代碼行數:21,代碼來源:staticfile.go

示例7: Render

func (self *Tag) Render(context *Context, writer *utils.XMLWriter) (err error) {
	writer.OpenTag(self.Tag).Attrib("id", self.id).AttribIfNotDefault("class", self.Class)
	for key, value := range self.Attribs {
		writer.Attrib(key, value)
	}
	if self.Content != nil {
		err = self.Content.Render(context, writer)
	}
	if self.ExtraClose {
		writer.ForceCloseTag()
	} else {
		writer.CloseTag()
	}
	return err
}
開發者ID:sedzinreri,項目名稱:go-start,代碼行數:15,代碼來源:tag.go

示例8: 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

示例9: Render

func (self HTML) Render(context *Context, writer *utils.XMLWriter) (err error) {
	writer.Content(string(self))
	return nil
}
開發者ID:sedzinreri,項目名稱:go-start,代碼行數:4,代碼來源:html.go

示例10: 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

示例11: 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

示例12: RenderItem

func (self *StringsSelectModel) RenderItem(index int, context *Context, writer *utils.XMLWriter) (err error) {
	writer.Content(self.Options[index])
	return nil
}
開發者ID:sedzinreri,項目名稱:go-start,代碼行數:4,代碼來源:select.go

示例13: 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

示例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 *List) Render(context *Context, writer *utils.XMLWriter) (err error) {
	if self.Ordered {
		writer.OpenTag("ol").Attrib("id", self.id).AttribIfNotDefault("class", self.Class)
		writer.Attrib("start", self.OrderOffset+1)
	} else {
		writer.OpenTag("ul").Attrib("id", self.id).AttribIfNotDefault("class", self.Class)
	}

	if self.Model != nil {
		numItems := self.Model.NumItems()
		for i := 0; i < numItems; i++ {
			writer.OpenTag("li").Attrib("id", self.id, "_", i)
			view, err := self.Model.ItemView(i, context)
			if view != nil && err == nil {
				view.Init(view)
				err = view.Render(context, writer)
			}
			if err != nil {
				return err
			}
			writer.ForceCloseTag() // li
		}
	}

	writer.ForceCloseTag() // ol/ul
	return nil
}
開發者ID:sedzinreri,項目名稱:go-start,代碼行數:27,代碼來源:list.go


注:本文中的github.com/ungerik/go-start/utils.XMLWriter類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。