本文整理汇总了Golang中github.com/hoisie/mustache.RenderFile函数的典型用法代码示例。如果您正苦于以下问题:Golang RenderFile函数的具体用法?Golang RenderFile怎么用?Golang RenderFile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RenderFile函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: show
func show(w http.ResponseWriter, r *http.Request) {
coinflipKey := strings.Split(r.URL.Path, "/")[2]
coinflip, _ := database.FindCoinflip(coinflipKey)
participants := coinflip.FindParticipants()
email_list := participantsMap(participants, func(p database.Participant) map[string]string {
var seen_at string
if p.Seen.Time.IsZero() {
seen_at = "hasn't registered yet"
} else {
seen_at = p.Seen.Time.Format("Monday 2 January 2006")
}
return map[string]string{"email": p.Email, "seen_at": seen_at}
})
var result string
if coinflip.Result.String == "" {
result = "Nothing yet! Not everybody checked in. Perhaps a little encouragement?"
} else {
result = coinflip.Result.String
}
str_to_str := map[string]string{"count": fmt.Sprint(len(email_list)), "head": coinflip.Head, "tail": coinflip.Tail, "result": result}
str_to_slice := map[string][]map[string]string{"participants": email_list}
fmt.Fprint(w, mustache.RenderFile("./views/layout.html", map[string]string{"body": mustache.RenderFile("./views/show.html", str_to_str, str_to_slice)}))
}
开发者ID:haarts,项目名称:coinflips,代码行数:27,代码来源:coinflips.go
示例2: parseTemplate
func parseTemplate(filename string, data *Container) (string, error) {
fileLocation := fmt.Sprintf("%s/%s.mustache", utils.GetOriginFolder(), filename)
if utils.Exists(fileLocation) {
log.Debugf(" + Parsing %s template", fileLocation)
before := fmt.Sprintf("%s/%s/%s/%s.before.mustache", utils.GetOriginFolder(), data.Config["client"], data.Config["enviroment"], filename)
after := fmt.Sprintf("%s/%s/%s/%s.after.mustache", utils.GetOriginFolder(), data.Config["client"], data.Config["enviroment"], filename)
if utils.Exists(before) {
log.Debugf(" + Parsing %s:before template", before)
data.SubTemplate.Before = mustache.RenderFile(before, data)
} else {
log.Debugf(" + Not Parsing %s:before template", before)
}
if utils.Exists(after) {
log.Debugf(" + Parsing %s:after template", after)
data.SubTemplate.After = mustache.RenderFile(after, data)
} else {
log.Debugf(" + Not Parsing %s:after template", after)
}
parsedData := mustache.RenderFile(fileLocation, data)
return parsedData, nil
}
return "", errors.New(fmt.Sprintf("Can not find %s", fileLocation))
}
开发者ID:flexiant,项目名称:tt,代码行数:26,代码来源:container.go
示例3: std_layout
func std_layout(blog_config map[string]interface{}, f func(w http.ResponseWriter, req *http.Request)) func(w http.ResponseWriter, req *http.Request) {
p := func(w http.ResponseWriter, req *http.Request) {
appcontext := appengine.NewContext(req)
myurl, err := realhostname(req, appcontext)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
scheme := "http://"
if req.TLS != nil {
scheme = "https://"
}
context := map[string]interface{}{"app_url": scheme + myurl + config.Stringify(blog_config["blog_root"])}
bloginfo := config.Stringify_map(config.Merge(blog_config, context))
start := time.Now()
template_dir := "templates/"
h := mustache.RenderFile(template_dir+"header.html.mustache", bloginfo)
io.WriteString(w, h)
f(w, req)
sidebar(w, req, blog_config)
delta := time.Since(start).Seconds()
timing := map[string]interface{}{"timing": fmt.Sprintf("%0.2fs", delta)}
if delta > 0.100 {
timing["slow_code"] = "true"
}
u := user.Current(appcontext)
if u != nil {
logout, err := user.LogoutURL(appcontext, "/")
if err != nil {
http.Error(w, "error generating logout URL!", http.StatusInternalServerError)
appcontext.Errorf("user.LogoutURL: %v", err)
return
}
timing["me"] = fmt.Sprintf("%s", u)
timing["logout"] = logout
}
bloginfo = config.Stringify_map(config.Merge(blog_config, timing))
f := mustache.RenderFile(template_dir+"footer.html.mustache", bloginfo)
io.WriteString(w, f)
}
return p
}
开发者ID:wickedchicken,项目名称:blarg,代码行数:53,代码来源:layout.go
示例4: home
func home(w http.ResponseWriter, r *http.Request) {
/* static file serve */
if len(r.URL.Path) != 1 {
http.ServeFile(w, r, "./views"+r.URL.Path)
return
}
/* the real root */
count := database.TotalNumberOfParticipants()
/*long, very long line */
fmt.Fprint(w, mustache.RenderFile("./views/layout.html", map[string]string{"body": mustache.RenderFile("./views/home.html", map[string]string{"title": "Awesome coin tosses - Coinflips.net", "nr_of_flips": fmt.Sprint(count)})}))
}
开发者ID:haarts,项目名称:coinflips,代码行数:13,代码来源:coinflips.go
示例5: adminGet
func adminGet(ctx *web.Context) string {
if !checkGodLevel(ctx) {
return mustache.RenderFile("templ/admin_login.mustache")
}
Db := DBGet()
defer Db.Close()
posts, _ := Db.GetLastNPosts(256)
x := map[interface{}]interface{}{
"Posts": posts,
}
return mustache.RenderFile("templ/admin_post.mustache", &x)
}
开发者ID:youngking,项目名称:fettemama,代码行数:14,代码来源:admin.go
示例6: GetSitemap
func GetSitemap(blog_config map[string]interface{}) func(w http.ResponseWriter, req *http.Request) {
template_dir := "templates/"
l := func(w http.ResponseWriter, req *http.Request) {
appcontext := appengine.NewContext(req)
myurl, err := realhostname(req, appcontext)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
scheme := "http://"
if req.TLS != nil {
scheme = "https://"
}
urlprefix := scheme + myurl + config.Stringify(blog_config["blog_root"])
postchan := make(chan post.Post, 16)
errchan := make(chan error)
go post.ExecuteQuery(appcontext, post.GetAllPosts(), -1, -1, post.NullFilter, postchan, errchan)
entries := bytes.NewBufferString("")
me_context := map[string]interface{}{"url": urlprefix,
"lastmod_date": post.GetLatestDate(appcontext).Format("2006-01-02")}
me_total_con := config.Stringify_map(config.Merge(blog_config, me_context))
me_c := mustache.RenderFile(template_dir+"sitemap_entry.mustache", me_total_con)
io.WriteString(entries, me_c)
for p := range postchan {
context := map[string]interface{}{"url": urlprefix + "article/" + p.StickyUrl,
"lastmod_date": p.Postdate.Format("2006-01-02")}
total_con := config.Stringify_map(config.Merge(blog_config, context))
c := mustache.RenderFile(template_dir+"sitemap_entry.mustache", total_con)
io.WriteString(entries, c)
}
err, ok := <-errchan
if ok {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
context := map[string]interface{}{"content": entries}
total_con := config.Stringify_map(config.Merge(blog_config, context))
c := mustache.RenderFile(template_dir+"sitemap.mustache", total_con)
io.WriteString(w, c)
}
return l
}
开发者ID:wickedchicken,项目名称:blarg,代码行数:48,代码来源:layout.go
示例7: CacheHandler
func CacheHandler(w http.ResponseWriter, r *auth.AuthenticatedRequest) {
switch r.Method {
case "GET":
params := r.URL.Query()
page, err := strconv.Atoi(params.Get("page"))
if err != nil {
page = 1
}
subcat := params.Get("subcat")
responseContent := search.CacheSearch(subcat, page)
var responseBody []byte
if strings.Contains(r.Header["Accept"][0], "application/json") {
responseBody, err = json.Marshal(responseContent)
if err != nil {
internalServerError(w, &r.Request)
return
}
} else {
responseBody = []byte(mustache.RenderFile("view/cache.html", responseContent))
}
w.Write(responseBody)
default:
methodNotAllowed(w, &r.Request)
}
}
开发者ID:codingkoi,项目名称:oldbailey,代码行数:27,代码来源:view.go
示例8: compileStream
func compileStream(s *Stream) *Stream {
for _, v := range s.Items {
compileStreamItem(v)
}
s.Html = mustache.RenderFile("Pages/Stream.mustache", s)
return s
}
开发者ID:ericfode,项目名称:Hive,代码行数:7,代码来源:hive.go
示例9: AdminHandler
func AdminHandler(w http.ResponseWriter, r *http.Request) {
c := appengine.NewContext(r)
db := DB{c}
adminUser := user.Current(c)
if adminUser == nil {
url, _ := user.LoginURL(c, "/admin/dashboard")
http.Redirect(w, r, url, 301)
return
}
if r.Method == "GET" {
dir := path.Join(os.Getenv("PWD"), "templates")
admin := path.Join(dir, "admin.html")
data := map[string]interface{}{"user": adminUser.String(), "config": Config}
page := mustache.RenderFile(admin, data)
fmt.Fprint(w, page)
} else if r.Method == "POST" {
if len(r.FormValue("v")) == 0 {
return
}
switch r.FormValue("op") {
case "UnqueueUser":
db.Context.Infof("unqueuing %v", r.FormValue("v"))
db.UnqueueUser(r.FormValue("v"))
case "BatchUsers":
users := strings.Split(r.FormValue("v"), ",")
for _, v := range users {
QueueUser(v, c)
}
}
fmt.Fprintf(w, "{\"op\":\"%v\",\"success\":true}", r.FormValue("op"))
}
}
开发者ID:vishnuvr,项目名称:davine,代码行数:32,代码来源:routes.go
示例10: permalink
func permalink(w http.ResponseWriter, r *http.Request) {
idstr := r.URL.Path[len("/post/"):]
post, err := PostBySlug(idstr)
if err != nil {
http.Error(w, fmt.Sprintf("invalid post %s: %s", idstr, err.Error()), http.StatusBadRequest)
return
}
if r.Method == "DELETE" {
if !IsAuthed(w, r) {
return
}
post.MarkDeleted()
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusNoContent)
w.Write([]byte("{\"ok\":true}"))
return
}
owner := AccountForOwner()
data := map[string]interface{}{
"post": post,
"OwnerName": owner.DisplayName,
}
html := mustache.RenderFile("html/permalink.html", data)
w.Write([]byte(html))
}
开发者ID:markpasc,项目名称:cares,代码行数:29,代码来源:web.go
示例11: Render
func Render(ctx *web.Context, tmpl string, config *Config, name string, data interface{}) {
tmpl = filepath.Join(config.Get("datadir"), tmpl)
ctx.WriteString(mustache.RenderFile(tmpl,
map[string]interface{}{
"config": config,
name: data}))
}
开发者ID:fjj596894378,项目名称:blogo,代码行数:7,代码来源:blogo.go
示例12: entrybar
func entrybar(blog_config map[string]interface{}, w http.ResponseWriter, req *http.Request) {
template_dir := "templates/"
appcontext := appengine.NewContext(req)
myurl, err := realhostname(req, appcontext)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
scheme := "http://"
if req.TLS != nil {
scheme = "https://"
}
urlprefix := scheme + myurl + config.Stringify(blog_config["blog_root"])
postchan := make(chan post.Post, 16)
errchan := make(chan error)
go post.ExecuteQuery(appcontext, post.GetAllPosts(), -1, -1, func(post.Post) bool { return true }, postchan, errchan)
for p := range postchan {
context := map[string]interface{}{"url": urlprefix + "article/" + p.StickyUrl,
"lastmod_date": p.Postdate.Format("2006-01-02")}
total_con := config.Stringify_map(config.Merge(blog_config, context))
c := mustache.RenderFile(template_dir+"edit_entrybar.html.mustache", total_con)
io.WriteString(w, c)
}
err, ok := <-errchan
if ok {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}
开发者ID:wickedchicken,项目名称:blarg,代码行数:33,代码来源:layout.go
示例13: ServeHTTP
func (i *IndexHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
data := map[string]string{}
path := filepath.Join(i.templates, "index.mustache")
html := mustache.RenderFile(path, data)
buff := bytes.NewReader([]byte(html))
http.ServeContent(w, r, "index.html", i.updated, buff)
log.Printf("Request: %v", r.RequestURI)
}
开发者ID:kurrik,项目名称:livestream,代码行数:8,代码来源:main.go
示例14: BuildMessage
func (m *BaseMail) BuildMessage(subject string, template string, data interface{}) []byte {
//mime := "MIME-version: 1.0;\nContent-Type: text/html; charset=\"UTF-8\";\n\n"
// load the template
body := mustache.RenderFile(template, data)
msg := []byte(body)
return msg
}
开发者ID:nicholasjackson,项目名称:blackpuppy-api-mail,代码行数:9,代码来源:sendmail.go
示例15: editGet
func editGet(ctx *web.Context) string {
if !checkGodLevel(ctx) {
return mustache.RenderFile("templ/admin_login.mustache")
}
Db := DBGet()
defer Db.Close()
id, _ := strconv.ParseInt(ctx.Params["id"], 10, 64)
post, err := Db.GetPost(id)
if err != nil {
return "couldn't load post with given id!"
}
posts, _ := Db.GetLastNPosts(256)
x := map[interface{}]interface{}{
"Posts": posts,
}
return mustache.RenderFile("templ/admin_edit.mustache", &post, &x)
}
开发者ID:youngking,项目名称:fettemama,代码行数:19,代码来源:admin.go
示例16: home
func home() string {
c := Content{
"Hello",
"My name is abhi",
}
return mustache.RenderFile(
"template/layout.html",
map[string]string{
"title": c.Title, "content": c.Content,
},
nil,
)
}
开发者ID:AbhiAgarwal,项目名称:experiments,代码行数:13,代码来源:mustache.go
示例17: compileFiles
func compileFiles(fullPath string, f os.FileInfo, err error) error {
if !f.IsDir() {
newPath := mustache.Render(fullPath, templateConfig.Variables)
rendered := mustache.RenderFile(fullPath, templateConfig.Variables)
os.Remove(fullPath)
ioutil.WriteFile(newPath, []byte(rendered), f.Mode())
printCreating(newPath)
}
return nil
}
开发者ID:unbalancedparentheses,项目名称:gut,代码行数:13,代码来源:gut.go
示例18: Preview
func (ac *ActionsConfig) Preview(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
username := ps.ByName("username")
chopid := ps.ByName("chopid")
s := chopper.NewSlapchop(ac.Host, username, chopid)
t_files, _ := s.LoadFiles(ac.UploadDir)
tiles := s.LoadTiles(ac.HostName, t_files)
grid := s.Grid(tiles)
html := mustache.RenderFile(ac.TemplatePath, grid)
w.WriteHeader(http.StatusOK)
w.Write([]byte(html))
}
开发者ID:billyninja,项目名称:slapchop,代码行数:14,代码来源:actions.go
示例19: sidebar
func sidebar(w http.ResponseWriter, req *http.Request, blog_config map[string]interface{}) {
template_dir := "templates/"
sidebar_links := bytes.NewBufferString("")
context := map[string]interface{}{"label_link": "http://qrunk.com",
"label_title": "qrunk.com"}
total_con := config.Stringify_map(config.Merge(blog_config, context))
c := mustache.RenderFile(template_dir+"sidebar_entry.html.mustache", total_con)
io.WriteString(sidebar_links, c)
sidebar_topics := bytes.NewBufferString("")
appcontext := appengine.NewContext(req)
tags, counts, err := post.GetAllTags(appcontext)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
for i := range tags {
n, count := tags[i], counts[i]
context = map[string]interface{}{"label_link": "/label/" + n,
"label_title": n,
"label_count": fmt.Sprintf("%v", count)}
total_con = config.Stringify_map(config.Merge(blog_config, context))
c = mustache.RenderFile(template_dir+"sidebar_entry.html.mustache", total_con)
io.WriteString(sidebar_topics, c)
}
context = map[string]interface{}{"sidebar_links": string(sidebar_links.Bytes()),
"sidebar_topics": string(sidebar_topics.Bytes())}
total_con = config.Stringify_map(config.Merge(blog_config, context))
c = mustache.RenderFile(template_dir+"sidebar.html.mustache", total_con)
io.WriteString(w, c)
}
开发者ID:wickedchicken,项目名称:blarg,代码行数:36,代码来源:layout.go
示例20: main
func main() {
raw, err := ioutil.ReadFile("json-generator.json")
if err != nil {
log.Fatal("opening json", err.Error())
}
var users []User
json.Unmarshal([]byte(raw), &users)
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
content := mustache.RenderFile("application.mustache", users)
fmt.Fprintf(w, "<!DOCTYPE html><html><head></head><body><div id='react'>%s</div><script>window.INITIAL_DATA = %s;</script></body></html>", content, raw)
})
log.Fatal(http.ListenAndServe(":3000", nil))
}
开发者ID:alexpods,项目名称:ssr-comparison,代码行数:16,代码来源:server.go
注:本文中的github.com/hoisie/mustache.RenderFile函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论