package gallery import ( "fmt" "html/template" "regexp" "amadan.net/rastrillo/fiesta/example" ) // The modal route: the modal idiom at the URL the idiom insists on. // The modal example's frame shows the markup inside a widget; this is // the same markup as a page of its own, demo-modal.html (modal.html is // the modal example's page), linked from the Demos group and from that // page. // // The document is the modal example's own, with Rastrillo's three // deviations, each the difference between a sample and a page that // exists: the backdrop holds a real screen (a page header and a box) // instead of a bare heading, so there is something behind the panel; // the panel's tabs link this page, so switching one keeps the modal // open rather than landing on a route this tree does not serve; and // Close returns to the Overview, since the backdrop's screen has no // address of its own here, which the panel says. The panel stays a // , never showModal()'d, as the example is. // // It is framed as a sample document is: the gallery's assets, noindex, // frame.js first so a scheme the reader chose comes with them, and the // padding rule, which leaves a page with a backdrop unpadded. // modalHref is the modal route's address. func (s *site) modalHref(theme, locale string) string { return s.href(theme, locale, "demo-modal.html") } var ( // The example's backdrop, a page with one heading. modalBackdrop = regexp.MustCompile(`(?s)
.*?
\s*`) // The panel's tabs and its section, each rewritten whole. modalNav = regexp.MustCompile(`(?s)`) modalSection = regexp.MustCompile(`(?s)
.*?
`) ) // modal builds one theme and locale's modal route. func (s *site) modal(theme, locale string) ([]byte, error) { const name = "modal" e, ok := s.m.Entry(name) if !ok { return nil, fmt.Errorf("the manifest has no %s example to build the modal route from", name) } doc, err := example.Document(s.src, name, e.Default) if err != nil { return nil, err } say := func(id string) string { return template.HTMLEscapeString(s.say(locale, id)) } self := s.modalHref(theme, locale) overview := s.href(theme, locale, s.fileOf("overview")) steps := []struct { what string re *regexp.Regexp with string }{ {"the title", titleTag, "" + template.HTMLEscapeString(s.say(locale, "gallery.title", "page", s.say(locale, "gallery.demos.modal"), "theme", theme)) + ""}, {"the backdrop", modalBackdrop, `

` + say("gallery.modal.settings") + `

` + say("gallery.modal.sub") + `

` + say("gallery.modal.account") + `

` + say("gallery.modal.own") + `

`}, {"the panel's tabs", modalNav, ``}, {"the panel's section", modalSection, `
✕

` + say("gallery.modal.body") + `

` + say("gallery.modal.nojs") + `

` + say("gallery.modal.inapp") + `

` + say("gallery.back") + `

`}, } for _, step := range steps { if n := len(step.re.FindAllStringIndex(doc, -1)); n != 1 { return nil, fmt.Errorf("%s/%s has %d of %s to rewrite, want one", name, e.Default, n, step.what) } doc = step.re.ReplaceAllLiteralString(doc, step.with) } framed, err := s.framed(doc, theme, locale, e, nil) if err != nil { return nil, fmt.Errorf("demo-modal.html: %w", err) } return []byte(framed), nil }