Skip to content

Commit 820c48b

Browse files
authored
chore: minor code cleanups (#8)
Signed-off-by: Abiola Ibrahim <git@abiosoft.com>
1 parent 19b4adb commit 820c48b

3 files changed

Lines changed: 8 additions & 14 deletions

File tree

engine.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@ var (
1919
defaultExts = []string{".html", ".gohtml", ".tpl", ".tmpl"}
2020
)
2121

22-
const (
23-
// sections
24-
bodySection = "body"
25-
headSection = "head"
26-
)
27-
2822
type (
2923
templateSet map[string]*templateFile
3024
moldEngine map[string]*template.Template
@@ -238,7 +232,7 @@ func parseView(set templateSet, layout *templateFile, name string) (*template.Te
238232
for _, t := range body.Templates() {
239233
tName := t.Name()
240234
if tName == name {
241-
tName = bodySection
235+
tName = "body"
242236
}
243237
view.AddParseTree(tName, t.Tree)
244238
}

mold.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,9 @@ func WithFuncMap(funcMap template.FuncMap) Option {
131131
return func(c *Config) { c.funcMap = newVal(funcMap) }
132132
}
133133

134-
// HideFS wraps an [fs.FS] and restricts access to files with specified extensions,
134+
// HideFS wraps an [fs.FS] and restricts access to files with the specified extensions,
135135
// essentially hiding them.
136-
// This is useful to prevent exposing sensitive files like templates when serving
136+
// This is useful to prevent exposing templates (or sensitive files) when serving
137137
// static assets and templates from the same directory.
138138
//
139139
// Example:
@@ -148,21 +148,21 @@ func HideFS(fsys fs.FS, exts ...string) fs.FS {
148148
if len(exts) == 0 {
149149
exts = defaultExts
150150
}
151-
return &staticFS{
151+
return &hideFS{
152152
FS: fsys,
153153
exts: exts,
154154
}
155155
}
156156

157-
var _ fs.FS = (*staticFS)(nil)
157+
var _ fs.FS = (*hideFS)(nil)
158158

159-
type staticFS struct {
159+
type hideFS struct {
160160
exts []string
161161
fs.FS
162162
}
163163

164164
// Open implements fs.FS.
165-
func (s *staticFS) Open(name string) (fs.File, error) {
165+
func (s *hideFS) Open(name string) (fs.File, error) {
166166
ext := filepath.Ext(name)
167167
if hasExt(s.exts, ext) {
168168
return nil, fs.ErrNotExist

process.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func processActionNode(root *templateFile, parent *parse.ListNode, index int, no
8888
arg = field
8989
}
9090
if name == "" {
91-
return posErr{pos: int(actionNode.Pos), message: `view: path to partial file is not specified`}
91+
return posErr{pos: int(actionNode.Pos), message: `path to partial file is not specified`}
9292
}
9393
case funcName == renderFunc.String():
9494
if name == "" {

0 commit comments

Comments
 (0)