本文整理匯總了Golang中github.com/hoisie/mustache.RenderFileInLayout函數的典型用法代碼示例。如果您正苦於以下問題:Golang RenderFileInLayout函數的具體用法?Golang RenderFileInLayout怎麽用?Golang RenderFileInLayout使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了RenderFileInLayout函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: postedHandler
func postedHandler(s Services, w http.ResponseWriter, r *http.Request) {
user, err := getUser(s, w, r)
if err != nil {
// TODO don't leak errors
renderError(w, fmt.Sprintf("%s", err))
return
}
if user == nil {
renderError(w, "You aren't logged in!")
return
}
tweets, err := getTweets(s, *user, true)
if err != nil {
renderError(w, fmt.Sprintf("%s", err))
return
}
args := map[string]interface{}{
"posted": "yes",
"username": user.screenName,
"tweets": tweets,
}
data := mustache.RenderFileInLayout(
"/usr/share/tweetautofeeder/templates/posted_page.must",
"/usr/share/tweetautofeeder/templates/layout.must",
args)
w.Write([]byte(data))
return
}
示例2: LoginHandler
// LoginHandler writes out login template
func LoginHandler(r *http.Request, w http.ResponseWriter) {
context := map[string]interface{}{
"title": "Access magnet",
"csrf_token": nosurf.Token(r),
}
w.Write([]byte(mustache.RenderFileInLayout("templates/login.mustache", "templates/base.mustache", context)))
}
示例3: DiscoverHandler
func DiscoverHandler(w http.ResponseWriter, r *http.Request) {
c := appengine.NewContext(r)
vineApi := VineRequest{c}
db := DB{c}
var recentUsers []*VineUser
var recentVerified []StoredUserMeta
recent := datastore.NewQuery("Queue").Order("-Discovered").Limit(5).KeysOnly()
k, _ := recent.GetAll(c, nil)
for i, _ := range k {
user, err := vineApi.GetUser(strconv.FormatInt(k[i].IntID(), 10))
if err == nil {
recentUsers = append(recentUsers, user)
}
}
verified := datastore.NewQuery("UserMeta").Filter("Verified =", true).Limit(5).KeysOnly()
k, _ = verified.GetAll(c, nil)
for i, _ := range k {
user, err := db.GetUserMeta(k[i].IntID())
if err == nil {
recentVerified = append(recentVerified, user.(StoredUserMeta))
}
}
data := map[string]interface{}{"recentUsers": recentUsers, "recentVerified": recentVerified}
dir := path.Join(os.Getenv("PWD"), "templates")
discover := path.Join(dir, "discover.html")
layout := path.Join(dir, "pageLayout.html")
page := mustache.RenderFileInLayout(discover, layout, data)
fmt.Fprint(w, page)
}
示例4: DonateHandler
func DonateHandler(w http.ResponseWriter, r *http.Request) {
dir := path.Join(os.Getenv("PWD"), "templates")
donate := path.Join(dir, "donate.html")
layout := path.Join(dir, "pageLayout.html")
page := mustache.RenderFileInLayout(donate, layout, nil)
fmt.Fprint(w, page)
}
示例5: listHosts
func listHosts(store configstore.Store, w http.ResponseWriter, req *http.Request) {
names, err := store.Names()
if err != nil {
log.Printf("Error: %s", err)
http.Error(w, "error :(", 500)
return
}
if req.Header.Get("Accept") == "application/json" {
w.Header().Set("Content-type", "application/json")
enc := json.NewEncoder(w)
err := enc.Encode(struct {
Hostnames []string
}{
Hostnames: names,
})
if err != nil {
log.Printf("Error: %s", err)
http.Error(w, "error :(", 500)
return
}
} else {
io.WriteString(w, mustache.RenderFileInLayout("templates/hosts.html.mustache", "templates/layout.html.mustache", names))
}
}
示例6: renderPage
func renderPage(ctx *web.Context) string {
home := new(Home)
user := ctx.Params["user"]
followedBy, following, err := GetFollow(user)
if err != nil {
print(err.Error() + " in renderPage ")
}
jits, err := GetJits(user)
if err != nil {
print(err.Error() + " in renderPage jiterror ")
}
home.CardRender = FetchUserInfo(user)
home.StreamRender = &Stream{UserID: user, Items: jits}
//home.StreamRender = &Stream{UserID: user, Items: []*StreamItem{
// dummyStreamItem(), dummyStreamItem()}}
home.FollowRender = new(Follow)
home.FollowRender.UserID = user
home.FollowRender.FollowedBy = followedBy
home.FollowRender.Following = following
compileHome(home)
home.Html = mustache.RenderFileInLayout("Pages/Home.mustache", "Pages/layout.mustache", home)
return home.Html
}
示例7: contact
func contact(w http.ResponseWriter, r *http.Request) {
var submitted string
if r.Method == "POST" {
c := appengine.NewContext(r)
name := r.FormValue("name")
email := r.FormValue("email")
info := r.FormValue("info")
if name == "" || email == "" || info == "" {
submitted = "Submission failed. Please enter all the information on the form. Thanks!"
} else {
msg := &mail.Message{
Sender: "[email protected]",
To: []string{"[email protected]"},
Subject: fmt.Sprintf("Website Contact - %s", name),
Body: fmt.Sprintf("Name: %s\nEmail: %s\nInformation: %s", name, email, info),
HTMLBody: fmt.Sprintf("<html><body><p>Name: %s</p><p>Email: %s</p><p>Information: %s</p></body></html>", name, email, info),
}
if err := mail.Send(c, msg); err != nil {
c.Errorf("Could not send email: %v", err)
submitted = "Your information could not be sent. Could you try again later? Apologies!"
} else {
submitted = "Your information has been sent. I'll get back to you as soon as possible!"
}
}
c.Infof("Contact submitted: name=%s, email=%s, info=%s", name, email, info)
}
out := mustache.RenderFileInLayout("mustache/contact.html.mustache", "mustache/layout.html.mustache", map[string]string{"submitted": submitted})
fmt.Fprint(w, out)
}
示例8: diffBackup
func diffBackup(store configstore.Store, w http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req)
t1, err := time.Parse(file.DefaultDateFormat, vars["date1"])
if err != nil {
log.Printf("Error: %s", err)
http.Error(w, "error :(", 500)
return
}
t2, err := time.Parse(file.DefaultDateFormat, vars["date2"])
if err != nil {
log.Printf("Error: %s", err)
http.Error(w, "error :(", 500)
return
}
e1 := configstore.Entry{
Name: vars["hostname"],
Date: t1,
}
e2 := configstore.Entry{
Name: vars["hostname"],
Date: t2,
}
err = store.Get(&e1)
if err != nil {
log.Printf("Error: %s", err)
http.Error(w, "error :(", 500)
return
}
err = store.Get(&e2)
if err != nil {
log.Printf("Error: %s", err)
http.Error(w, "error :(", 500)
return
}
dmp := diffmatchpatch.New()
diffs := dmp.DiffMain(e1.Content.String(), e2.Content.String(), true)
em := struct {
Hostname string
Date1 time.Time
Date2 time.Time
Diff string
}{
vars["hostname"],
t1,
t2,
dmp.DiffPrettyHtml(diffs),
}
io.WriteString(w, mustache.RenderFileInLayout("templates/diff.html.mustache", "templates/layout.html.mustache", em))
}
示例9: NotFoundHandler
func NotFoundHandler(w http.ResponseWriter, r *http.Request) {
dir := path.Join(os.Getenv("PWD"), "templates")
notFound := path.Join(dir, "404.html")
layout := path.Join(dir, "pageLayout.html")
data := map[string]string{"url": r.RequestURI}
page := mustache.RenderFileInLayout(notFound, layout, data)
w.WriteHeader(404)
fmt.Fprint(w, page)
}
示例10: homeHandler
func homeHandler(w http.ResponseWriter, r *http.Request) {
data.Title = "Home"
data.Posts = make([]Post, 5)
for k, v := range posts[:5] {
data.Posts[k] = *v
data.Posts[k].PrettyDate = humanize.Time(v.Date)
}
fmt.Fprint(w, mustache.RenderFileInLayout("templates/home.html.mustache", "templates/layout.html.mustache", data))
}
示例11: hostBackup
func hostBackup(store configstore.Store, w http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req)
t, err := time.Parse(file.DefaultDateFormat, vars["date"])
if err != nil {
log.Printf("Error: %s", err)
http.Error(w, "error :(", 500)
return
}
e := configstore.Entry{
Name: vars["hostname"],
Date: t,
}
err = store.Get(&e)
if err != nil {
log.Printf("Error: %s", err)
http.Error(w, "error :(", 500)
return
}
if req.Header.Get("Accept") == "application/json" {
w.Header().Set("Content-type", "application/json")
enc := json.NewEncoder(w)
err := enc.Encode(struct {
Hostname string
Date string
Content string
}{
Hostname: e.Name,
Date: e.Date.Format(file.DefaultDateFormat),
Content: e.Content.String(),
})
if err != nil {
log.Printf("Error: %s", err)
http.Error(w, "error :(", 500)
return
}
} else {
em := struct {
Hostname string
Date string
Content string
}{
vars["hostname"],
t.String(),
e.Content.String(),
}
io.WriteString(w, mustache.RenderFileInLayout("templates/entry.html.mustache", "templates/layout.html.mustache", em))
}
}
示例12: renderError
func renderError(w http.ResponseWriter, errorMessage string) {
data := mustache.RenderFileInLayout(
"/usr/share/tweetautofeeder/templates/error_page.must",
"/usr/share/tweetautofeeder/templates/layout.must",
map[string]string{
"errorMessage": errorMessage,
})
w.Write([]byte(data))
w.WriteHeader(http.StatusBadRequest)
return
}
示例13: loginHandler
func loginHandler(s Services, w http.ResponseWriter, r *http.Request) {
url, _ := s.router.Get("login_begin").URLPath()
data := mustache.RenderFileInLayout(
"/usr/share/tweetautofeeder/templates/main_page.must",
"/usr/share/tweetautofeeder/templates/layout.must",
map[string]string{"url": url.String()})
w.Write([]byte(data))
return
}
示例14: listDates
func listDates(store configstore.Store, w http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req)
datesStore, err := store.Dates(vars["hostname"])
if err != nil {
log.Printf("Error: %s", err)
http.Error(w, "error :(", 500)
return
}
if req.Header.Get("Accept") == "application/json" {
w.Header().Set("Content-type", "application/json")
var dates []string
for _, date := range datesStore {
dates = append(dates, date.Format(file.DefaultDateFormat))
}
enc := json.NewEncoder(w)
err := enc.Encode(struct {
Hostname string
Dates []string
}{
Hostname: vars["hostname"],
Dates: dates,
})
if err != nil {
log.Printf("Error: %s", err)
http.Error(w, "error :(", 500)
return
}
} else {
var data = struct {
Hostname string
Dates []struct {
String string
URL string
}
}{
Hostname: vars["hostname"],
}
for _, date := range datesStore {
data.Dates = append(data.Dates, struct {
String string
URL string
}{
String: date.String(),
URL: date.Format(file.DefaultDateFormat),
})
}
io.WriteString(w, mustache.RenderFileInLayout("templates/dates.html.mustache", "templates/layout.html.mustache", data))
}
}
示例15: TopHandler
func TopHandler(w http.ResponseWriter, r *http.Request) {
c := appengine.NewContext(r)
db := DB{c}
dir := path.Join(os.Getenv("PWD"), "templates")
top := path.Join(dir, "top.html")
layout := path.Join(dir, "pageLayout.html")
data := db.GetTop()
data["LastUpdated"] = db.GetLastUpdated()
page := mustache.RenderFileInLayout(top, layout, data)
fmt.Fprint(w, page)
}