Skip to content

Commit

Permalink
templates: make template names actually be filled on creation
Browse files Browse the repository at this point in the history
templates: fix data race on just returning the list of names, instead we
make a new slice when filling in names

mocks: add missing Executor method that we added in previous commit
  • Loading branch information
Wessie committed Apr 27, 2024
1 parent 00b343a commit bf80adb
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 10 deletions.
44 changes: 44 additions & 0 deletions mocks/templates.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 17 additions & 10 deletions templates/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,27 +60,33 @@ func (s *Site) Reload() error {
return errors.E(op, err)
}
s.themes = themes
s.populateNames()

return nil
}

type TemplateSelector interface {
Template(theme, page string) (*template.Template, error)
}

func (s *Site) Executor() Executor {
return newExecutor(s)
}

func (s *Site) populateNames() {
// populate the theme name lists, one for public, one for admin
names := maps.Keys(themes)
names := maps.Keys(s.themes)
slices.Sort(names)

s.themeNamesAdmin = make([]string, 0, len(s.themeNamesAdmin))
s.themeNamesPublic = make([]string, 0, len(s.themeNamesPublic))
for _, name := range names {
if strings.HasPrefix(name, ADMIN_PREFIX) {
s.themeNamesAdmin = append(s.themeNamesAdmin, name)
} else {
s.themeNamesPublic = append(s.themeNamesPublic, name)
}
}
return nil
}

type TemplateSelector interface {
Template(theme, page string) (*template.Template, error)
}

func (s *Site) Executor() Executor {
return newExecutor(s)
}

func (s *Site) ThemeNames() []string {
Expand Down Expand Up @@ -201,6 +207,7 @@ func FromFS(fsys fs.FS) (*Site, error) {
if err != nil {
return nil, errors.E(op, err)
}
tmpl.populateNames()

return &tmpl, nil
}
Expand Down

0 comments on commit bf80adb

Please sign in to comment.