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


Golang template.HTMLAttr函数代码示例

本文整理汇总了Golang中html/template.HTMLAttr函数的典型用法代码示例。如果您正苦于以下问题:Golang HTMLAttr函数的具体用法?Golang HTMLAttr怎么用?Golang HTMLAttr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了HTMLAttr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: GetAssetUrl

func (s *SprocketsDirectory) GetAssetUrl(name string) (template.HTMLAttr, error) {
	src, ok := s.assets[name]
	if !ok {
		return template.HTMLAttr(s.prefix + "__NOT_FOUND__" + name), errors.New("Asset not found: " + name)
	}
	return template.HTMLAttr(s.prefix + src), nil
}
开发者ID:vinays,项目名称:goodies,代码行数:7,代码来源:prebuilt_sprockets.go

示例2: NewTagEntry

// NewTagEntry creates a new ArchiveEntry for the given values.
func NewTagEntry(file, title string) *TagEntry {
	url := file + ".html"

	// Not all pages have a metadata title defined.
	// Use the page url instead, after we prettify it a bit.
	if len(title) == 0 {
		title = file

		if strings.HasSuffix(title, "/index") {
			title, _ = filepath.Split(title)
		}

		if title == "/" {
			title = "Home"
		}
	}

	// If the url ends with /index.html, we strip off the index part.
	// It just takes up unnecessary bytes in the output and
	// `foo/bar/` looks better than `foo/bar/index.html`.
	if strings.HasSuffix(url, "/index.html") {
		url, _ = filepath.Split(url)
	}

	te := new(TagEntry)
	te.Url = template.HTMLAttr(url)
	te.Title = template.HTMLAttr(title)
	return te
}
开发者ID:jteeuwen,项目名称:blargh,代码行数:30,代码来源:tags.go

示例3: GetAssetUrl

func (s *SprocketsServer) GetAssetUrl(name string) (template.HTMLAttr, error) {
	src, ok := s.assets[name]
	if !ok {
		return template.HTMLAttr(s.baseUrl + "__NOT_FOUND__" + name), errors.New("Asset not found: " + name)
	}
	return template.HTMLAttr(s.baseUrl + src), nil
}
开发者ID:vinays,项目名称:goodies,代码行数:7,代码来源:remote_sprockets.go

示例4: InjectRender

func InjectRender(c *web.C, h http.Handler) http.Handler {
	fn := func(w http.ResponseWriter, r *http.Request) {

		c.Env["render"] = render.New(render.Options{
			Directory:  "views",
			Layout:     "",
			Extensions: []string{".tmpl"},
			Funcs: []template.FuncMap{template.FuncMap{
				"classIfHere": func(path, class string) template.HTMLAttr {
					if r.URL.Path == path {
						return template.HTMLAttr(fmt.Sprintf(`class="%s"`, class))
					}
					return template.HTMLAttr("")
				},
				"date": func(date time.Time) string {
					return date.Format("January 2, 2006")
				},
				"checkIfInArray": func(x string, slice []string) template.HTMLAttr {
					for _, y := range slice {
						if x == y {
							return template.HTMLAttr("checked")
						}
					}
					return template.HTMLAttr("")
				},
			}},
		})

		h.ServeHTTP(w, r)

	}

	return http.HandlerFunc(fn)
}
开发者ID:ignaciocarvajal,项目名称:go-portafolio,代码行数:34,代码来源:render.go

示例5: EchoSelectSelected

func EchoSelectSelected(option string, value interface{}) htmlTemplate.HTMLAttr {
	if option == fmt.Sprint(value) {
		return htmlTemplate.HTMLAttr(" selected")
	}

	return htmlTemplate.HTMLAttr("")
}
开发者ID:peteraba,项目名称:go-blah,代码行数:7,代码来源:select_selected.go

示例6: NewArchiveEntry

// NewArchiveEntry creates a new ArchiveEntry for the given values.
func NewArchiveEntry(file, title, desc string, stamp time.Time) *ArchiveEntry {
	url := file + ".html"

	// Not all pages have a metadata title defined.
	// Use the page url instead, after we prettify it a bit.
	if len(title) == 0 {
		title = file

		if strings.HasSuffix(title, "/index") {
			title, _ = filepath.Split(title)
		}

		if title == "/" {
			title = "Home"
		}
	}

	// If the url ends with /index.html, we strip off the index part.
	// It just takes up unnecessary bytes in the output and
	// `foo/bar/` looks better than `foo/bar/index.html`.
	if strings.HasSuffix(url, "/index.html") {
		url, _ = filepath.Split(url)
	}

	ae := new(ArchiveEntry)
	ae.Url = template.HTMLAttr(url)
	ae.Title = template.HTMLAttr(title)
	ae.Description = template.HTMLAttr(desc)
	ae.Stamp = stamp
	return ae
}
开发者ID:jteeuwen,项目名称:blargh,代码行数:32,代码来源:archive.go

示例7: EnumClassAttr

func (ep EnumParam) EnumClassAttr(named, classif string, optelse ...string) (template.HTMLAttr, error) {
	classelse, err := EnumClassAttrArgs(optelse)
	if err != nil {
		return template.HTMLAttr(""), err
	}
	_, uptr := ep.EnumDecodec.Unew()
	if err := uptr.Unmarshal(named, new(bool)); err != nil {
		return template.HTMLAttr(""), err
	}
	if ep.Number.Uint != uptr.Touint() {
		classif = classelse
	}
	return SprintfAttr(" class=%q", classif), nil
}
开发者ID:vadv,项目名称:ostent,代码行数:14,代码来源:pipemethods.go

示例8: EnumClassAttr

func (n Nota) EnumClassAttr(named, classif string, optelse ...string) (template.HTMLAttr, error) {
	classelse, err := params.EnumClassAttrArgs(optelse)
	if err != nil {
		return template.HTMLAttr(""), err
	}
	eparams := params.NewParamsENUM(nil)
	ed := eparams[n.Base()].EnumDecodec
	_, uptr := ed.Unew()
	if err := uptr.Unmarshal(named, new(bool)); err != nil {
		return template.HTMLAttr(""), err
	}
	return SprintfAttr(" className={(%s.Uint == %d) ? %q : %q}",
		n, uptr.Touint(), classif, classelse), nil
}
开发者ID:vadv,项目名称:ostent,代码行数:14,代码来源:methods.go

示例9: UserTFAPage

func UserTFAPage(w http.ResponseWriter, req *http.Request) {
	args := handlers.GetArgs(req)

	u := quimby.NewUser(args.Vars["username"], quimby.UserDB(args.DB), quimby.UserTFA(handlers.TFA))
	if err := u.Fetch(); err != nil {
		context.Set(req, "error", err)
		return
	}

	qrData, err := u.UpdateTFA()
	if err != nil {
		context.Set(req, "error", err)
		return
	}

	if _, err := u.Save(); err != nil {
		context.Set(req, "error", err)
		return
	}

	qr := qrPage{
		userPage: userPage{
			User:  args.User.Username,
			Admin: handlers.Admin(args),
			Links: []link{
				{"quimby", "/"},
				{"admin", "/admin.html"},
			},
		},
		QR: template.HTMLAttr(base64.StdEncoding.EncodeToString(qrData)),
	}
	templates["qr-code.html"].template.ExecuteTemplate(w, "base", qr)
}
开发者ID:cswank,项目名称:quimby,代码行数:33,代码来源:admin.go

示例10: EchoActiveLink

func EchoActiveLink(link_href string) htmlTemplate.HTMLAttr {
	if strings.Contains(active_page, link_href) {
		return htmlTemplate.HTMLAttr(" class=\"active\"")
	}

	return ""
}
开发者ID:peteraba,项目名称:go-blah,代码行数:7,代码来源:active_link.go

示例11: BoolClassAttr

func (b Bool) BoolClassAttr(fstclass, sndclass string) template.HTMLAttr {
	s := fstclass
	if !b {
		s = sndclass
	}
	return template.HTMLAttr(fmt.Sprintf(" class=%q", s))
}
开发者ID:vadv,项目名称:ostent,代码行数:7,代码来源:operating.go

示例12: Data

func (f *Field) Data() map[string]interface{} {
	safeParams := make(map[template.HTMLAttr]interface{})
	for k, v := range f.params {
		safeParams[template.HTMLAttr(k)] = v
	}
	data := map[string]interface{}{
		"classes":      f.class,
		"id":           f.id,
		"name":         f.name,
		"params":       safeParams,
		"css":          f.css,
		"type":         f.fieldType,
		"label":        f.label,
		"labelClasses": f.labelClass,
		"tags":         f.tag,
		"value":        f.value,
		"helptext":     f.helptext,
		"errors":       f.errors,
		"container":    "form",
		"choices":      f.choices,
	}
	for k, v := range f.additionalData {
		data[k] = v
	}
	for k, v := range f.AppendData {
		data[k] = v
	}
	return data
}
开发者ID:webx-top,项目名称:webx,代码行数:29,代码来源:field.go

示例13: safeHTMLAttr

// safeHTMLAttr returns the attribute an HTML element as k=v.
// If v contains double quotes "", the attribute value will be wrapped
// in single quotes '', and vice versa. Defaults to double quotes.
func safeHTMLAttr(k, v string) html.HTMLAttr {
	q := `"`
	if strings.ContainsRune(v, '"') {
		q = "'"
	}
	return html.HTMLAttr(k + "=" + q + v + q)
}
开发者ID:pathikdevani,项目名称:ioweb2015,代码行数:10,代码来源:template.go

示例14: createLiveBlogSample

func createLiveBlogSample(newStatus int, timestamp time.Time, firstBlogID string, originSource string, page Page) LiveBlogSample {
	if newStatus > len(blogs) {
		newStatus = len(blogs)
	}
	blogItems := getBlogEntries(newStatus, timestamp)
	score := createScore(newStatus, 0)
	firstItemIndex := getBlogEntryIndexFromID(firstBlogID, blogItems)
	lenghtCurrentPageBlog := int(math.Min(float64(len(blogItems)), float64(firstItemIndex+MAX_BLOG_ITEMS_NUMBER_PER_PAGE)))

	urlPrefix := buildPrefixPaginationURL(originSource, page)
	nextPageId := getNextPageId(blogItems, firstItemIndex+MAX_BLOG_ITEMS_NUMBER_PER_PAGE)
	previousPageId := getPrevPageId(firstItemIndex)
	nextPageUrl := buildPaginationURL(urlPrefix, nextPageId)
	prevPageUrl := buildPaginationURL(urlPrefix, previousPageId)
	disabled := ""
	if prevPageUrl != "" {
		disabled = "disabled"
	}
	blogMetadata, _ := json.MarshalIndent(createMetadata(originSource), "        ", "  ")

	return LiveBlogSample{BlogItems: blogItems[firstItemIndex:lenghtCurrentPageBlog],
		FootballScore: score,
		BlogMetadata:  template.JS(blogMetadata),
		NextPageURL:   nextPageUrl,
		PrevPageURL:   prevPageUrl,
		PageNumber:    getPageNumberFromProductIndex(firstItemIndex),
		Disabled:      template.HTMLAttr(disabled)}
}
开发者ID:ampproject,项目名称:amp-by-example,代码行数:28,代码来源:amp-live-list.go

示例15: init

func init() {
	HtmlFuncBoot.Register(func(w *Web) {
		// HTML Marksafe
		w.HtmlFunc["html"] = func(str string) html.HTML {
			return html.HTML(str)
		}

		// HTML Attr MarkSafe
		w.HtmlFunc["htmlattr"] = func(str string) html.HTMLAttr {
			return html.HTMLAttr(str)
		}

		// JS Marksafe
		w.HtmlFunc["js"] = func(str string) html.JS {
			return html.JS(str)
		}

		// JS String Marksafe
		w.HtmlFunc["jsstr"] = func(str string) html.JSStr {
			return html.JSStr(str)
		}

		// CSS Marksafe
		w.HtmlFunc["css"] = func(str string) html.CSS {
			return html.CSS(str)
		}
	})
}
开发者ID:venliong,项目名称:webby,代码行数:28,代码来源:html.go


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