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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
| {% import ( "fmt" "net/url" "time"
"github.com/google/uuid"
"{{{ .Package }}}/app/controller/cutil" "{{{ .Package }}}/app/util"{{{ if .HasModule "numeric" }}} "{{{ .Package }}}/app/util/numeric"{{{ end }}} "{{{ .Package }}}/views/components" ) %}
{% func Any(x any, ps *cutil.PageState) %}{% stripspace %} {% if x == nil %} <em>nil</em> {% else %} {% switch t := x.(type) %} {% case bool %} {%= Bool(t) %} {% case util.Diffs %} {%= Diffs(t) %} {% case float32 %} {%= Float(t) %} {% case float64 %} {%= Float(t) %} {% case int %} {%= Int(t) %} {% case int32 %} {%= Int(t) %} {% case int64 %} {%= Int(t) %} {% case util.ToOrderedMap[any] %} {%= OrderedMap(false, t.ToOrderedMap(), ps) %} {% case *util.OrderedMap[any] %} {%= OrderedMap(false, t, ps) %} {% case util.ToOrderedMaps[any] %} {%= OrderedMapArray(false, ps, t.ToOrderedMaps()...) %} {% case []*util.OrderedMap[any] %} {%= OrderedMapArray(false, ps, t...) %} {% case util.ToMap %} {%= Map(false, t.ToMap(), ps) %} {% case util.ValueMap %} {%= Map(false, t, ps) %} {% case map[string]any %} {%= Map(false, t, ps) %} {% case util.ToMaps %} {%= MapArray(false, ps, t.ToMaps()...) %} {% case []util.ValueMap %} {%= MapArray(false, ps, t...) %}{{{ if .HasModule "numeric" }}} {% case numeric.Numeric %} {%= Numeric(t) %}{{{ end }}} {% case util.Pkg %} {%= Package(t) %} {% case string %} {%= String(t) %} {% case []string %} {%= StringArray(t) %} {% case time.Time %} {%= Timestamp(&t) %} {% case *time.Time %} {%= Timestamp(t) %} {% case url.URL %} {%= URL(t, "", true, ps) %} {% case *url.URL %} {%= URL(t, "", true, ps) %} {% case uuid.UUID %} {%= UUID(&t) %} {% case *uuid.UUID %} {%= UUID(t) %} {% case []any %} {%- if len(t) == 0 -%} <em>empty array</em> {%- else -%} {% code arr, extra := util.ArrayLimit(t, 8) %} {%- for idx, e := range arr -%} <div class="flex bb"> <div class="mts mrs mbs"><em>{%d idx + 1 %}</em></div> <div class="mts mbs">{%= Any(e, ps) %}</div> </div> {%- endfor -%} {% if extra > 0 %} <div class="mts"><em>...and{% space %}{%d extra %}{% space %}more</em></div> {% endif %} {%- endif -%} {% case fmt.Stringer %} {%= String(t.String()) %} {% default %} unhandled type [{%s fmt.Sprintf("%T", x) %}] {% endswitch %} {% endif %} {% endstripspace %}{% endfunc %}
{% func AnyTable(title string, value any, indent int, ps *cutil.PageState) %}{% stripspace %} <tr> {%= components.Indent(true, indent + 1) %} <th class="shrink">{%s title %}</th> {%= components.Indent(true, indent + 1) %} <td>{%= Any(value, ps) %}</td> {%= components.Indent(true, indent) %} </tr> {% endstripspace %}{% endfunc %}
|