package gallery import ( "fmt" "html/template" ) // A family page: the family's title is the page's heading; under it // the family's sentence, the idiom rules where the family is the // primitives, and its examples listed by name with each one's blurb, // so every section of the rail has a page of its own and the sequence // a step to stand on. const familyBody = `{{define "ds-body-family"}}{{with .Family}}{{if .Blurb}}

{{.Blurb}}

{{end}}{{range .Rules}}
{{.Title}}

{{.Body}}

{{end}}{{end}}{{end}}` // familyBody renders the body of the family page p is. func (s *site) familyBody(p page) (template.HTML, error) { f, ok := s.familyByKey(p.Kind) if !ok { return "", fmt.Errorf("no family %s", p.Kind) } blurbs := map[string]string{} for _, e := range f.Examples { blurbs[e.Name] = s.proseIn(p.Locale, "examples."+e.Name+".blurb", s.prose.Examples[e.Name].Blurb) } return s.body(p.Locale, "ds-body-family", struct { page Family family Blurbs map[string]string }{p, s.familyIn(p.Locale, f), blurbs}) } // familyByKey is the family with key, if there is one. func (s *site) familyByKey(key string) (family, bool) { for _, f := range s.families { if f.Key == key { return f, true } } return family{}, false } // familyIn is f with its title, blurb and rules in locale. func (s *site) familyIn(locale string, f family) family { out := f out.Title = s.proseIn(locale, "families."+f.Key+".title", f.Title) out.Blurb = s.proseIn(locale, "families."+f.Key+".blurb", f.Blurb) out.Rules = nil for _, r := range f.Rules { out.Rules = append(out.Rules, idiomRule{ Idiom: r.Idiom, Title: s.proseIn(locale, "pages.idioms."+r.Idiom+".title", r.Title), Body: s.proseIn(locale, "pages.idioms."+r.Idiom+".body", r.Body), }) } return out } func init() { registerTemplate(familyBody) }