當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。