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

     1  <!-- Content managed by Project Forge, see [projectforge.md] for details. -->
     2  {% import (
     3    "strings"
     4  
     5    "github.com/kyleu/dbaudit/app/controller/cutil"
     6  ) %}
     7  
     8  {% func String(value string, classes ...string) %}{% stripspace %}
     9    {% if len(classes) == 0 %}
    10      {%s value %}
    11    {% else %}
    12      <span class="{%s strings.Join(classes, ` `) %}">{%s value %}</span>
    13    {% endif %}
    14  {% endstripspace %}{% endfunc %}
    15  
    16  {% func StringRich(value string, code bool, maxLength int, classes ...string) %}{% stripspace %}
    17    {% code if maxLength > 0 && len(value) > maxLength {
    18      value = value[:maxLength]
    19    } %}
    20    {% if code %}
    21    {% if len(classes) == 0 %}
    22      <pre>{%s value %}</pre>
    23    {% else %}
    24      <pre class="{%s strings.Join(classes, ` `) %}">{%s value %}</pre>
    25    {% endif %}
    26    {% else %}
    27      {%= String(value, classes...) %}
    28    {% endif %}
    29  {% endstripspace %}{% endfunc %}
    30  
    31  {% func StringArray(value []string) %}{% stripspace %}
    32    {% if len(value) == 0 %}
    33    <em>empty</em>
    34    {% endif %}
    35    {% code
    36      maxCount := 5
    37      display := value
    38      var extra int
    39      if len(value) > maxCount {
    40        extra = len(value) - maxCount
    41        display = display[:maxCount]
    42      }
    43    %}
    44    {% if extra > 0 %}<span title="{%s strings.Join(value, `, `) %}">{% endif %}
    45    {%- for idx, v := range display -%}
    46    {% if idx > 0 %},{% space %}{% endif %}
    47    {%s v %}
    48    {% endfor %}
    49    {% if extra > 0 %}, <em>and{% space %}{%d extra %}{% space %}more...</em>{% endif %}
    50    {% if extra > 0 %}</span>{% endif %}
    51  {% endstripspace %}{% endfunc %}
    52  
    53  
    54  {% func Format(v string, ext string) %}{% stripspace %}
    55    {% code out, err := cutil.FormatLang(v, ext) %}
    56    {% if err == nil %}
    57      {%s= out %}
    58    {% else %}
    59      {%s err.Error() %}
    60    {% endif %}
    61  {% endstripspace %}{% endfunc %}