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

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

示例1: TemplateFuncMap

// TemplateFuncMap returns a map of functions that are usable in templates
func TemplateFuncMap() template.FuncMap {
    v := config.Raw.View
    f := make(template.FuncMap)

    f["JS"] = func(s string) template.HTML {
        path, err := v.AssetTimePath(s)

        if err != nil {
            log.Println("JS Error:", err)
            return template.HTML("<!-- JS Error: " + s + " -->")
        }

        return template.HTML(`<script type="text/javascript" src="` + path + `"></script>`)
    }

    f["CSS"] = func(s string) template.HTML {
        path, err := v.AssetTimePath(s)

        if err != nil {
            log.Println("CSS Error:", err)
            return template.HTML("<!-- CSS Error: " + s + " -->")
        }

        return template.HTML(`<link rel="stylesheet" type="text/css" href="` + path + `" />`)
    }

    f["LINK"] = func(path, name string) template.HTML {
        return template.HTML(`<a href="` + v.PrependBaseURI(path) + `">` + name + `</a>`)
    }

    return f
}

开发者ID:diegobernardes,项目名称:gowebapp,代码行数:33,代码来源:plugin.go

示例2: itemToBody

func itemToBody(feed *feedparser.Feed, item *feedparser.FeedItem) io.Reader {

    tmpl := template.Must(template.New("message").Parse(ctx.Template))

    type tmplData struct {
        Link    string
        Title   string
        Author  string
        Content template.HTML
    }

    data := tmplData{
        Link:  item.Link,
        Title: item.Title,
    }

    if len(item.Content) > 0 {
        data.Content = template.HTML(item.Content)
    } else {
        data.Content = template.HTML(item.Description)
    }

    var doc bytes.Buffer
    tmpl.Execute(&doc, data)
    return &doc
}

开发者ID:rcarmo,项目名称:go-rss2imap,代码行数:26,代码来源:feed.go

示例3: ServeHTTP

// Base handler for HTTP requests.
func (*handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
    path := r.URL.Path

    if strings.HasPrefix(path, "/css/") {
        path = strings.TrimLeft(path, "/css/")
        if css, ok := assets.Css[path]; ok {
            w.Header().Set("Content-Type", "text/css; charset=utf-8")
            w.Write([]byte(css))
        } else {
            w.WriteHeader(http.StatusNotFound)
        }
    } else if path == "/favicon.ico" {
    } else {
        var file []byte

        path = strings.TrimLeft(path, "/")
        if path == "" {
            file = markdown.GetReadme()
        } else {
            file = markdown.GetFile(path)
        }
        data := data{
            Title:   "Knowledge Base",
            Index:   template.HTML(string(markdown.GetIndex())),
            Content: template.HTML(string(file)),
        }
        render(w, data)
    }
}

开发者ID:mehulsbhatt,项目名称:kb,代码行数:30,代码来源:web.go

示例4: GetPanelConfig

func (bbp *BuildBaronPlugin) GetPanelConfig() (*plugin.PanelConfig, error) {
    root := plugin.StaticWebRootFromSourceFile()
    panelHTML, err := ioutil.ReadFile(root + "/partials/ng_include_task_build_baron.html")
    if err != nil {
        return nil, fmt.Errorf("Can't load panel html file, %v, %v",
            root+"/partials/ng_include_task_build_baron.html", err)
    }

    includeJS, err := ioutil.ReadFile(root + "/partials/script_task_build_baron_js.html")
    if err != nil {
        return nil, fmt.Errorf("Can't load panel html file, %v, %v",
            root+"/partials/script_task_build_baron_js.html", err)
    }

    includeCSS, err := ioutil.ReadFile(root +
        "/partials/link_task_build_baron_css.html")
    if err != nil {
        return nil, fmt.Errorf("Can't load panel html file, %v, %v",
            root+"/partials/link_task_build_baron_css.html", err)
    }

    return &plugin.PanelConfig{
        StaticRoot: plugin.StaticWebRootFromSourceFile(),
        Panels: []plugin.UIPanel{
            {
                Page:      plugin.TaskPage,
                Position:  plugin.PageRight,
                PanelHTML: template.HTML(panelHTML),
                Includes:  []template.HTML{template.HTML(includeCSS), template.HTML(includeJS)},
            },
        },
    }, nil
}

开发者ID:IanWhalen,项目名称:build-baron-plugin,代码行数:33,代码来源:build_baron.go

示例5: render

func (t *Template) render(rctx core.RenderContext) string {
    b := &bytes.Buffer{}

    // Update functions for current rendering context.
    t.tmpl.Funcs(map[string]interface{}{
        "slot": func(name, elt string) template.HTML {
            s := t.node.Slot(name)
            if elt == "" {
                return template.HTML(s.Node().Render(rctx))
            }
            return template.HTML(fmt.Sprintf("<%s id='%s'>%s</%s>", elt, s.ID(), s.Node().Render(rctx), elt))
        },
        "event": func(name string) template.JS {
            return template.JS(fmt.Sprintf("stdweb.events.onClick('%s', '%s', event)", template.JSEscapeString(t.node.ID()), template.JSEscapeString(name)))
        },
    })

    err := t.tmpl.Execute(b, &tplData{
        ID:       t.node.ID(),
        RunID:    rctx.RunID(),
        UpdateID: rctx.UpdateID(),
        Data:     t.data,
    })

    if err == nil {
        return b.String()
    }
    return html.EscapeString(err.Error())
}

开发者ID:Palats,项目名称:stdweb,代码行数:29,代码来源:template.go

最后编辑: kuteng  文档更新时间: 2021-08-23 19:14   作者:kuteng