Updates on Templates assets
parent
99f38eac79
commit
58946e691e
|
@ -79,10 +79,11 @@ type User struct {
|
|||
|
||||
// assets are the static and front-end assets, such as JS, CSS and HTML templates.
|
||||
type assets struct {
|
||||
requiredJS *rice.Box // JS that is always required to have in order to be usable.
|
||||
Templates *rice.Box
|
||||
CSS *rice.Box
|
||||
JS *rice.Box
|
||||
requiredJS *rice.Box // JS that is always required to have in order to be usable.
|
||||
baseTemplates *rice.Box
|
||||
Templates *rice.Box
|
||||
CSS *rice.Box
|
||||
JS *rice.Box
|
||||
}
|
||||
|
||||
// Rule is a dissalow/allow rule.
|
||||
|
@ -115,9 +116,9 @@ func New(scope string) *FileManager {
|
|||
BeforeSave: func(r *http.Request, m *FileManager, u *User) error { return nil },
|
||||
AfterSave: func(r *http.Request, m *FileManager, u *User) error { return nil },
|
||||
Assets: &assets{
|
||||
Templates: rice.MustFindBox("./_assets/templates"),
|
||||
CSS: rice.MustFindBox("./_assets/css"),
|
||||
requiredJS: rice.MustFindBox("./_assets/js"),
|
||||
baseTemplates: rice.MustFindBox("./_assets/templates"),
|
||||
CSS: rice.MustFindBox("./_assets/css"),
|
||||
requiredJS: rice.MustFindBox("./_assets/js"),
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -90,7 +90,7 @@ func serveListing(w http.ResponseWriter, r *http.Request, c *FileManager, u *Use
|
|||
Data: listing,
|
||||
}
|
||||
|
||||
return p.PrintAsHTML(w, c.Assets.Templates, "listing")
|
||||
return p.PrintAsHTML(w, c, "listing")
|
||||
}
|
||||
|
||||
// handleSortOrder gets and stores for a Listing the 'sort' and 'order',
|
||||
|
|
|
@ -43,8 +43,8 @@ func serveSingle(w http.ResponseWriter, r *http.Request, c *FileManager, u *User
|
|||
return http.StatusInternalServerError, err
|
||||
}
|
||||
|
||||
return p.PrintAsHTML(w, c.Assets.Templates, "frontmatter", "editor")
|
||||
return p.PrintAsHTML(w, c, "frontmatter", "editor")
|
||||
}
|
||||
|
||||
return p.PrintAsHTML(w, c.Assets.Templates, "single")
|
||||
return p.PrintAsHTML(w, c, "single")
|
||||
}
|
||||
|
|
15
page.go
15
page.go
|
@ -9,7 +9,6 @@ import (
|
|||
"net/http"
|
||||
"strings"
|
||||
|
||||
rice "github.com/GeertJohan/go.rice"
|
||||
"github.com/hacdias/filemanager/variables"
|
||||
)
|
||||
|
||||
|
@ -103,7 +102,7 @@ func (p page) PreviousLink() string {
|
|||
}
|
||||
|
||||
// PrintAsHTML formats the page in HTML and executes the template
|
||||
func (p page) PrintAsHTML(w http.ResponseWriter, box *rice.Box, templates ...string) (int, error) {
|
||||
func (p page) PrintAsHTML(w http.ResponseWriter, m *FileManager, templates ...string) (int, error) {
|
||||
if p.minimal {
|
||||
templates = append(templates, "minimal")
|
||||
} else {
|
||||
|
@ -115,7 +114,7 @@ func (p page) PrintAsHTML(w http.ResponseWriter, box *rice.Box, templates ...str
|
|||
// 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")
|
||||
Page, err := getTemplate(m, t+".tmpl")
|
||||
|
||||
// Check if there is some error. If so, the template doesn't exist
|
||||
if err != nil {
|
||||
|
@ -163,3 +162,13 @@ func (p page) PrintAsJSON(w http.ResponseWriter) (int, error) {
|
|||
|
||||
return http.StatusOK, nil
|
||||
}
|
||||
|
||||
func getTemplate(m *FileManager, template string) (string, error) {
|
||||
if m.Assets.Templates != nil {
|
||||
if tpl, err := m.Assets.Templates.String(template); err == nil {
|
||||
return tpl, err
|
||||
}
|
||||
}
|
||||
|
||||
return m.Assets.baseTemplates.String(template)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue