Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@ var (
defaultExts = []string{".html", ".gohtml", ".tpl", ".tmpl"}
)

const (
// sections
bodySection = "body"
headSection = "head"
)

type (
templateSet map[string]*templateFile
moldEngine map[string]*template.Template
Expand Down Expand Up @@ -238,7 +232,7 @@ func parseView(set templateSet, layout *templateFile, name string) (*template.Te
for _, t := range body.Templates() {
tName := t.Name()
if tName == name {
tName = bodySection
tName = "body"
}
view.AddParseTree(tName, t.Tree)
}
Expand Down
12 changes: 6 additions & 6 deletions mold.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ func WithFuncMap(funcMap template.FuncMap) Option {
return func(c *Config) { c.funcMap = newVal(funcMap) }
}

// HideFS wraps an [fs.FS] and restricts access to files with specified extensions,
// HideFS wraps an [fs.FS] and restricts access to files with the specified extensions,
// essentially hiding them.
// This is useful to prevent exposing sensitive files like templates when serving
// This is useful to prevent exposing templates (or sensitive files) when serving
// static assets and templates from the same directory.
//
// Example:
Expand All @@ -148,21 +148,21 @@ func HideFS(fsys fs.FS, exts ...string) fs.FS {
if len(exts) == 0 {
exts = defaultExts
}
return &staticFS{
return &hideFS{
FS: fsys,
exts: exts,
}
}

var _ fs.FS = (*staticFS)(nil)
var _ fs.FS = (*hideFS)(nil)

type staticFS struct {
type hideFS struct {
exts []string
fs.FS
}

// Open implements fs.FS.
func (s *staticFS) Open(name string) (fs.File, error) {
func (s *hideFS) Open(name string) (fs.File, error) {
ext := filepath.Ext(name)
if hasExt(s.exts, ext) {
return nil, fs.ErrNotExist
Expand Down
2 changes: 1 addition & 1 deletion process.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func processActionNode(root *templateFile, parent *parse.ListNode, index int, no
arg = field
}
if name == "" {
return posErr{pos: int(actionNode.Pos), message: `view: path to partial file is not specified`}
return posErr{pos: int(actionNode.Pos), message: `path to partial file is not specified`}
}
case funcName == renderFunc.String():
if name == "" {
Expand Down
Loading