Core

/views/components/view/Bool.html (1.3 KB)

 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
{% import (
"fmt"

"{{{ .Package }}}/app/controller/cutil"
"{{{ .Package }}}/app/util"
"{{{ .Package }}}/views/components"
) %}

{% func Bool(b bool) %}{% stripspace %}
{% if b %}true{% else %}false{% endif %}
{% endstripspace %}{% endfunc %}

{% func BoolTable(title string, value bool, indent int, ps *cutil.PageState) %}{% stripspace %}
<tr>
{%= components.Indent(true, indent + 1) %}
<th class="shrink">{%s title %}</th>
{%= components.Indent(true, indent + 1) %}
<td>{%= Bool(value) %}</td>
{%= components.Indent(true, indent) %}
</tr>
{% endstripspace %}{% endfunc %}

{% func BoolIcon(b bool, size int, cls string, ps *cutil.PageState, titles ...string) %}{% stripspace %}
{% code
if cls == "" {
cls = "inline"
}
var extra string
switch len(titles) {
case 0:
if b {
extra = "true"
} else {
extra = "false"
}
case 1:
l, r := util.StringSplitLast(titles[0], '|', true)
extra = util.Choose(b || r == "", l, r)
case 2:
extra = util.Choose(b, titles[0], titles[1])
}
if extra != "" {
extra = fmt.Sprintf(" title=%q", extra)
}
icon := util.Choose(b, "check", "times")
%}
<span{%s= extra %}>{%= components.SVGRef(icon, size, size, cls, ps) %}</span>
{% endstripspace %}{% endfunc %}