updates...

Former-commit-id: 2d19655aac80ec7033829b0b3d708bf86986252c [formerly b8bb006bd1a5492960c1d4793e15e80775ddc5fd] [formerly 4641277c14953bdb2ddab89ba866cf63f3dac0f9 [formerly 95b91a64a3c648e1414c7feb4b597bf0da195664]]
Former-commit-id: 5a6e07758bbe67fd202effa5b2975c65227eaebd [formerly 9a161548d270750b8da949189ad6f3b641779bfc]
Former-commit-id: 84e0bbcbbead53c5e91987574d5c854a9792515f
This commit is contained in:
Henrique Dias
2017-06-28 11:45:41 +01:00
parent 826d491ff1
commit 0a65393527
1893 changed files with 492634 additions and 10336 deletions

63
page.go
View File

@@ -5,7 +5,6 @@ import (
"encoding/base64"
"encoding/json"
"html/template"
"log"
"net/http"
"strconv"
"strings"
@@ -32,14 +31,14 @@ var functions = template.FuncMap{
// page contains the information needed to fill a page template.
type page struct {
minimal bool
User *User
Name string
Path string
BaseURL string
WebDavURL string
IsEditor bool
Data interface{}
User *User `json:"-"`
BaseURL string `json:"-"`
WebDavURL string `json:"-"`
Name string
Path string
Kind string // listing, editor or preview
Data interface{}
}
// breadcrumbItem contains the Name and the URL of a breadcrumb piece.
@@ -102,46 +101,24 @@ func (p page) PreviousLink() string {
}
// PrintHTML formats the page in HTML and executes the template
func (p page) PrintHTML(w http.ResponseWriter, box *rice.Box, templates ...string) (int, error) {
templates = append(templates, "actions")
templates = append(templates, "templates")
if p.minimal {
templates = append(templates, "minimal")
} else {
templates = append(templates, "base")
}
func (p page) PrintHTML(w http.ResponseWriter, box *rice.Box) (int, error) {
var tpl *template.Template
// For each template, add it to the the tpl variable
for i, t := range templates {
// Get the template from the assets
Page, err := box.String(t + ".tmpl")
// Get the template from the assets
file, err := box.String("index.html")
// Check if there is some error. If so, the template doesn't exist
if err != nil {
log.Print(err)
return http.StatusInternalServerError, err
}
// Check if there is some error. If so, the template doesn't exist
if err != nil {
return http.StatusInternalServerError, err
}
// If it's the first iteration, creates a new template and add the
// functions map
if i == 0 {
tpl, err = template.New(t).Funcs(functions).Parse(Page)
} else {
tpl, err = tpl.Parse(string(Page))
}
if err != nil {
log.Print(err)
return http.StatusInternalServerError, err
}
tpl, err = template.New("index").Funcs(functions).Parse(file)
if err != nil {
return http.StatusInternalServerError, err
}
buf := &bytes.Buffer{}
err := tpl.Execute(buf, p)
err = tpl.Execute(buf, p)
if err != nil {
return http.StatusInternalServerError, err
}
@@ -153,7 +130,7 @@ func (p page) PrintHTML(w http.ResponseWriter, box *rice.Box, templates ...strin
// PrintAsJSON prints the current Page information in JSON
func (p page) PrintJSON(w http.ResponseWriter) (int, error) {
marsh, err := json.MarshalIndent(p.Data, "", " ")
marsh, err := json.MarshalIndent(p, "", " ")
if err != nil {
return http.StatusInternalServerError, err
}