github.com/kyleu/dbaudit@v0.0.2-0.20240321155047-ff2f2c940496/views/Render.html (about)

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