rastrillo / fiesta Public

Clone
git clone https://amadan.net/rastrillo/fiesta

Plain git — no account needed to clone.

Download

Download this file

1package gallery
2
3import (
4 "fmt"
5 "html/template"
6)
7
8// A family page: the family's title is the page's heading; under it
9// the family's sentence, the idiom rules where the family is the
10// primitives, and its examples listed by name with each one's blurb,
11// so every section of the rail has a page of its own and the sequence
12// a step to stand on.
13const familyBody = `{{define "ds-body-family"}}{{with .Family}}{{if .Blurb}}<p class="ds-lead">{{.Blurb}}</p>
14{{end}}{{range .Rules}}<div rst-callout rst-tone="info"><span rst-callout-ic aria-hidden="true">{{icon "info"}}</span><div rst-callout-body><strong>{{.Title}}</strong>
15<p>{{.Body}}</p></div></div>
16{{end}}<ul class="ds-routes">{{range .Examples}}
17<li><a class="rst-mono" data-gallery-nav href="{{$.Href (print .Name ".html")}}">{{.Name}}</a><span>{{index $.Blurbs .Name}}</span></li>{{end}}
18</ul>{{end}}{{end}}`
19
20// familyBody renders the body of the family page p is.
21func (s *site) familyBody(p page) (template.HTML, error) {
22 f, ok := s.familyByKey(p.Kind)
23 if !ok {
24 return "", fmt.Errorf("no family %s", p.Kind)
25 }
26 blurbs := map[string]string{}
27 for _, e := range f.Examples {
28 blurbs[e.Name] = s.proseIn(p.Locale, "examples."+e.Name+".blurb", s.prose.Examples[e.Name].Blurb)
29 }
30 return s.body(p.Locale, "ds-body-family", struct {
31 page
32 Family family
33 Blurbs map[string]string
34 }{p, s.familyIn(p.Locale, f), blurbs})
35}
36
37// familyByKey is the family with key, if there is one.
38func (s *site) familyByKey(key string) (family, bool) {
39 for _, f := range s.families {
40 if f.Key == key {
41 return f, true
42 }
43 }
44 return family{}, false
45}
46
47// familyIn is f with its title, blurb and rules in locale.
48func (s *site) familyIn(locale string, f family) family {
49 out := f
50 out.Title = s.proseIn(locale, "families."+f.Key+".title", f.Title)
51 out.Blurb = s.proseIn(locale, "families."+f.Key+".blurb", f.Blurb)
52 out.Rules = nil
53 for _, r := range f.Rules {
54 out.Rules = append(out.Rules, idiomRule{
55 Idiom: r.Idiom,
56 Title: s.proseIn(locale, "pages.idioms."+r.Idiom+".title", r.Title),
57 Body: s.proseIn(locale, "pages.idioms."+r.Idiom+".body", r.Body),
58 })
59 }
60 return out
61}
62
63func init() { registerTemplate(familyBody) }
64