package gallery
import (
"html/template"
"amadan.net/rastrillo/fiesta/internal/tokens"
)
// The Tokens page: the theme's palette, then the structure every
// theme shares, each group under a heading the rail links.
const tokensBody = `{{define "ds-body-tokens"}}
{{say "gallery.tokens.lead" "theme" .Theme}}
{{say "gallery.tokens.note"}}
{{range .Groups}}{{.Title}}
{{$kind := .Kind}}{{range .Rows}}- {{if eq $kind "type"}}Ag{{else if eq $kind "space"}}{{else if eq $kind "radius"}}{{else if .Preview}}{{end}}{{.Name}}{{.Value}}
{{end}}
{{end}}{{end}}`
// tokenGroupView is one group with its anchor id and its title in the
// page's language.
type tokenGroupView struct {
tokens.Group
ID, Title string
}
// tokenGroups is one theme's groups: its palette, then the structure.
// Read once per theme at setup, so a theme whose stylesheet does not
// parse fails the render before a page is written.
func (s *site) tokenGroups(theme string) []tokens.Group { return s.tokens[theme] }
// readTokens parses every theme's palette and the shared structure.
func (s *site) readTokens() error {
structure, err := tokens.Structural()
if err != nil {
return err
}
s.tokens = map[string][]tokens.Group{}
for _, theme := range s.themes() {
palette, err := tokens.Palette(theme)
if err != nil {
return err
}
s.tokens[theme] = append(palette, structure...)
}
return nil
}
// tokensBody renders the Tokens page's body for p.
func (s *site) tokensBody(p page) (template.HTML, error) {
var groups []tokenGroupView
for _, g := range s.tokenGroups(p.Theme) {
groups = append(groups, tokenGroupView{Group: g, ID: anchorID("tokens", g.Key), Title: s.say(p.Locale, "gallery.tokens.group."+g.Key)})
}
return s.body(p.Locale, "ds-body-tokens", struct {
page
Groups []tokenGroupView
}{p, groups})
}
func init() { registerTemplate(tokensBody) }