-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
template_PUT.go
executable file
·149 lines (129 loc) · 2.98 KB
/
template_PUT.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// File generated by Gopher Sauce
// DO NOT EDIT!!
package templates
import (
"bytes"
"encoding/json"
"fmt"
"html"
"html/template"
"log"
"github.com/fatih/color"
"github.com/thestrukture/IDE/api/assets"
"github.com/thestrukture/IDE/types"
)
//
// Renders HTML of template
// PUT with struct types.Aput
func PUT(d types.Aput) string {
return netbPUT(d)
}
// recovery function used to log a
// panic.
func templateFNPUT(localid string, d interface{}) {
if n := recover(); n != nil {
color.Red(fmt.Sprintf("Error loading template in path (ui/user/forms/aput) : %s", localid))
// log.Println(n)
DebugTemplatePath(localid, d)
}
}
var templateIDPUT = "tmpl/ui/user/forms/aput.tmpl"
// Render template with JSON string as
// data.
func netPUT(args ...interface{}) string {
localid := templateIDPUT
var d *types.Aput
defer templateFNPUT(localid, d)
if len(args) > 0 {
jso := args[0].(string)
var jsonBlob = []byte(jso)
err := json.Unmarshal(jsonBlob, d)
if err != nil {
return err.Error()
}
} else {
d = &types.Aput{}
}
output := new(bytes.Buffer)
if _, ok := templateCache.Get(localid); !ok || !Prod {
body, er := assets.Asset(localid)
if er != nil {
return ""
}
var localtemplate = template.New("PUT")
localtemplate.Funcs(TemplateFuncStore)
var tmpstr = string(body)
localtemplate.Parse(tmpstr)
body = nil
templateCache.Put(localid, localtemplate)
}
erro := templateCache.JGet(localid).Execute(output, d)
if erro != nil {
color.Red(fmt.Sprintf("Error processing template %s", localid))
DebugTemplatePath(localid, d)
}
var outps = output.String()
var outpescaped = html.UnescapeString(outps)
d = nil
output.Reset()
output = nil
args = nil
return outpescaped
}
// alias of template render function.
func bPUT(d types.Aput) string {
return netbPUT(d)
}
//
// template render function
func netbPUT(d types.Aput) string {
localid := templateIDPUT
defer templateFNPUT(localid, d)
output := new(bytes.Buffer)
if _, ok := templateCache.Get(localid); !ok || !Prod {
body, er := assets.Asset(localid)
if er != nil {
return ""
}
var localtemplate = template.New("PUT")
localtemplate.Funcs(TemplateFuncStore)
var tmpstr = string(body)
localtemplate.Parse(tmpstr)
body = nil
templateCache.Put(localid, localtemplate)
}
erro := templateCache.JGet(localid).Execute(output, d)
if erro != nil {
log.Println(erro)
}
var outps = output.String()
var outpescaped = html.UnescapeString(outps)
d = types.Aput{}
output.Reset()
output = nil
return outpescaped
}
// Unmarshal a json string to the template's struct
// type
func netcPUT(args ...interface{}) (d types.Aput) {
if len(args) > 0 {
var jsonBlob = []byte(args[0].(string))
err := json.Unmarshal(jsonBlob, &d)
if err != nil {
log.Println("error:", err)
return
}
} else {
d = types.Aput{}
}
return
}
// Create a struct variable of template.
func cPUT(args ...interface{}) (d types.Aput) {
if len(args) > 0 {
d = netcPUT(args[0])
} else {
d = netcPUT()
}
return
}