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


Golang XMLWriter.ForceCloseTag方法代码示例

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


在下文中一共展示了XMLWriter.ForceCloseTag方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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 *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

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

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

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

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

示例7: Render

func (self *Button) Render(context *Context, writer *utils.XMLWriter) (err error) {
	if self.Submit {
		writer.OpenTag("input").Attrib("id", self.id).AttribIfNotDefault("class", self.Class)
		writer.Attrib("type", "submit")
		writer.AttribIfNotDefault("name", self.Name)
		writer.AttribIfNotDefault("value", self.Value)
		if self.Disabled {
			writer.Attrib("disabled", "disabled")
		}
		writer.AttribIfNotDefault("tabindex", self.TabIndex)
		if self.OnClickConfirm != "" {
			writer.Attrib("onclick", "return confirm('", self.OnClickConfirm, "');")
		} else {
			writer.AttribIfNotDefault("onclick", self.OnClick)
		}
		writer.CloseTag()
	} else {
		writer.OpenTag("button").Attrib("id", self.id).AttribIfNotDefault("class", self.Class)
		writer.Attrib("type", "button")
		writer.AttribIfNotDefault("name", self.Name)
		writer.AttribIfNotDefault("value", self.Value)
		if self.Disabled {
			writer.Attrib("disabled", "disabled")
		}
		writer.AttribIfNotDefault("tabindex", self.TabIndex)
		if self.OnClickConfirm != "" {
			writer.Attrib("onclick", "return confirm('", self.OnClickConfirm, "');")
		} else {
			writer.AttribIfNotDefault("onclick", self.OnClick)
		}
		if self.Content != nil {
			err = self.Content.Render(context, writer)
		}
		writer.ForceCloseTag()
	}
	return nil
}
开发者ID:sedzinreri,项目名称:go-start,代码行数:37,代码来源:button.go

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

示例9: Render

func (self *Canvas) Render(context *Context, writer *utils.XMLWriter) (err error) {
	writer.OpenTag("label").Attrib("id", self.id).AttribIfNotDefault("class", self.Class)
	writer.Attrib("width", self.Width).Attrib("height", self.Height)
	writer.ForceCloseTag()
	return err
}
开发者ID:sedzinreri,项目名称:go-start,代码行数:6,代码来源:canvas.go

示例10: Render


//.........这里部分代码省略.........
	fieldFactory := self.GetFieldFactory()
	if fieldFactory == nil {
		panic("view.Form.GetFieldFactory() returned nil")
	}

	var formModel interface{}
	var hasErrors bool
	content := Views{&HiddenInput{Name: FormIDName, Value: self.FormID}}
	isPost := self.IsPost(context)

	if self.GetModel == nil {
		submitButton := self.GetFieldFactory().NewSubmitButton(self.GetSubmitButtonText(), self.SubmitButtonConfirm, self)
		content = append(content, submitButton)
	} else {
		formModel, err = self.GetModel(self, context)
		if err != nil {
			return err
		}
		if isPost {
			setPostValues := &setPostValuesStructVisitor{
				form:      self,
				formModel: formModel,
				context:   context,
			}
			err = model.Visit(formModel, setPostValues)
			if err != nil {
				return err
			}
		}
		validateAndFormLayout := &validateAndFormLayoutStructVisitor{
			form:        self,
			formLayout:  layout,
			formModel:   formModel,
			formContent: &content,
			context:     context,
			isPost:      isPost,
		}
		err = model.Visit(formModel, validateAndFormLayout)
		if err != nil {
			return err
		}
		hasErrors = len(validateAndFormLayout.fieldValidationErrors) > 0 || len(validateAndFormLayout.generalValidationErrors) > 0
	}

	if isPost && !hasErrors {
		message, redirect, err := self.OnSubmit(self, formModel, context)
		if err == nil {
			if redirect == nil {
				redirect = self.Redirect
			}
			if redirect != nil {
				return Redirect(redirect.URL(context.PathArgs...))
			}
			if message == "" {
				message = self.SuccessMessage
			}
			if message != "" {
				self.GetLayout().SubmitSuccess(message, self, context, &content)
			}
		} else {
			if message == "" {
				message = err.Error()
			}
			self.GetLayout().SubmitError(message, self, context, &content)
		}
	}

	// Render HTML form element
	method := strings.ToUpper(self.Method)
	if method == "" {
		method = "POST"
	}
	action := self.Action
	if action == "" {
		action = "."
		if i := strings.Index(context.Request.RequestURI, "?"); i != -1 {
			action += context.Request.RequestURI[i:]
		}
	}
	// Hack: Value of hidden input FormIDName is not available when
	// enctype is multipart/form-data (bug?), so pass the form id as
	// URL parameter
	if self.Enctype == MultipartFormData && context.Request.Method != "POST" {
		action = utils.AddUrlParam(action, FormIDName, self.FormID)
	}

	writer.OpenTag("form").Attrib("id", self.id).AttribIfNotDefault("class", self.Class)
	writer.Attrib("method", method)
	writer.Attrib("action", action)
	writer.AttribIfNotDefault("enctype", self.Enctype)
	if len(content) > 0 {
		content.Init(content)
		err = content.Render(context, writer)
		if err != nil {
			return err
		}
	}
	writer.ForceCloseTag() // form
	return nil
}
开发者ID:sedzinreri,项目名称:go-start,代码行数:101,代码来源:form.go

示例11: 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
}
开发者ID:sedzinreri,项目名称:go-start,代码行数:70,代码来源:menu.go


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