-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtailush.go
89 lines (68 loc) · 1.74 KB
/
tailush.go
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
package tailush
import (
"fmt"
"strings"
"github.com/gobuffalo/flect"
"github.com/gobuffalo/tags/v3"
)
var (
//csrfTokenKey is the key where the authenticity token
//is stored in the helper context
csrfTokenKey = "authenticity_token"
//defaultFormVar is the default variable name for
//the form in the push template.
defaultFormVar = "f"
)
// divWrapper
func divWrapper(opts tags.Options, fn func(opts tags.Options) tags.Body) *tags.Tag {
divClass := opts["containerClass"]
delete(opts, "containerClass")
hasErrors := false
errors := []string{}
if divClass == nil {
divClass = "mb-2 w-full"
}
if opts["errors"] != nil && len(opts["errors"].([]string)) > 0 {
divClass = fmt.Sprintf("%v %v", divClass, "has-error")
hasErrors = true
errors = opts["errors"].([]string)
delete(opts, "errors")
}
div := tags.New("div", tags.Options{
"class": divClass,
})
if opts["label"] == nil && opts["tags-field"] != nil {
if tf, ok := opts["tags-field"].(string); ok {
tf = strings.Join(strings.Split(tf, "."), " ")
opts["label"] = flect.Titleize(tf)
}
}
delete(opts, "tags-field")
useLabel := opts["hide_label"] == nil
if useLabel {
div.Prepend(tags.New("label", tags.Options{
"body": opts["label"],
"class": "block text-sm font-medium text-gray-700 mb-1",
}))
delete(opts, "hide_label")
}
delete(opts, "label")
delete(opts, "hide_label")
idiv := tags.New("div", tags.Options{
"class": divClass,
})
// buildOptions(opts, hasErrors)
if opts["tag_only"] == true {
return fn(opts).(*tags.Tag)
}
idiv.Append(fn(opts))
div.Append(idiv)
if !hasErrors {
return div
}
idiv.Append(tags.New("p", tags.Options{
"class": "mt-1 text-xs text-red-600 mb-2",
"body": strings.Join(errors, ". "),
}))
return div
}