本文整理汇总了Golang中github.com/hoisie/mustache.RenderFile函数的典型用法代码示例。如果您正苦于以下问题:Golang RenderFile函数的具体用法?Golang RenderFile怎么用?Golang RenderFile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RenderFile函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)}))
}
示例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))
}
示例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
}
示例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)})}))
}
示例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)
}
示例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
}
示例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)
}
}
示例8: compileStream
func compileStream(s *Stream) *Stream {
for _, v := range s.Items {
compileStreamItem(v)
}
s.Html = mustache.RenderFile("Pages/Stream.mustache", s)
return s
}
示例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"))
}
}
示例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))
}
示例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}))
}
示例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
}
}
示例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)
}
示例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
}
示例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)
}