Permalink
Branch: master
Find file Copy path
b9cfb69 Apr 29, 2016
1 contributor

Users who have contributed to this file

45 lines (33 sloc) 1000 Bytes
package plugin
import (
"html/template"
"log"
"app/shared/view"
)
// TagHelper returns a template.FuncMap
// * JS returns JavaScript tag
// * CSS returns stylesheet tag
// * LINK returns hyperlink tag
func TagHelper(v view.View) template.FuncMap {
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
}