1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| {% import ( "fmt" "strings"
"{{{ .Package }}}/app" "{{{ .Package }}}/app/controller/cutil" "{{{ .Package }}}/app/lib/telemetry" "{{{ .Package }}}/app/util" "{{{ .Package }}}/views/components" "{{{ .Package }}}/views/layout" ) %}
{% func Render(page layout.Page, as *app.State, ps *cutil.PageState) %}{% code ctx, span, _ := telemetry.StartSpan(ps.Context, "html:" + strings.TrimPrefix(fmt.Sprintf("%T", page), "*"), ps.Logger) ps.Context = ctx defer func() { span.Complete() x := recover() if x != nil { ps.LogError("error processing template [%T]: %+v", x, x) panic(x) } }() %}<!DOCTYPE html> <html lang="en"> <!-- {%s cutil.PageComment %} --> <head>{%= page.Head(as, ps) %}</head> <body{%s= ps.ClassDecl() %}{%- if ps.Action != "" -%}{% space %}data-action="{%s ps.Action %}"{%- endif -%}{% space %}data-version="{%s as.BuildInfo.Version %}">{%- if len(ps.Flashes) > 0 -%}{%= renderFlashes(ps.Flashes) %}{%- endif -%}{%= page.Nav(as, ps) %} <main id="content"{% if ps.HideMenu %} class="nomenu"{% endif %}>{%= page.Body(as, ps) %}</main> {%= renderIcons(ps.Icons) %}</body> </html> {% endfunc %}
{% func renderFlashes(flashes []string) %}{% stripspace %} {% if len(flashes) > 0 %} <div id="flash-container"> {% for idx, f := range flashes %} {% code level, msg := util.StringSplit(f, ':', true) %} <div class="flash"> <input type="radio" style="display:none;" id="hide-flash-{%d idx %}"> <label for="hide-flash-{%d idx %}"><span>×</span></label> <div class="content flash-{%s level %}"> {%s msg %} </div> </div> {% endfor %} </div> {% endif %} {% endstripspace %}{% endfunc %}
{% func renderIcons(icons []string) %}{% stripspace %} {% if len(icons) > 0 %} <div class="icon-list" style="display: none;">{% newline %} {% for _, icon := range icons %} {% space %}{% space %}{%= components.SVG(icon) %}{% newline %} {% endfor %} </div>{% newline %} {% endif %} {% endstripspace %}{% endfunc %}
|