-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathViewFuncProvider.go
47 lines (40 loc) · 1.3 KB
/
ViewFuncProvider.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
// Author: James Mallon <jamesmallondev@gmail.com>
// layout package -
package vfprovider
import (
"html/template"
"strings"
"time"
)
// Struct type ViewFuncProvider -
type ViewFuncProvider struct{}
// Flash method - method receives a non obligatory param in form of a variadic to
// supress errors of layout requirements, converts the value into a map again and
// print the message accordingly with the website sample layout
func (this *ViewFuncProvider) Flash(msg ...interface{}) (flash template.HTML) {
m := msg[0].(*map[string]string) // converts it back to a map
if m != nil { // check if not nil - necessary for empty fms
fMsg := *m // get the value
flash = template.HTML("<div class='alert alert-" + fMsg["type"] + " role='alert'>" +
"<span>" + fMsg["message"] + "</span>" +
"</div>")
}
return
}
// FormatDate method - format a date
func (this *ViewFuncProvider) FormatDate(t time.Time) string {
layout := "2006-01-01"
return t.Format(layout)
}
// ToLower method -
func (this *ViewFuncProvider) ToLower(text string) string {
return strings.ToLower(text)
}
// ToUpper method -
func (this *ViewFuncProvider) ToUpper(text string) string {
return strings.ToUpper(text)
}
// UCFirst method -
func (this *ViewFuncProvider) UCFirst(text string) string {
return strings.Title(text)
}