MCPcopy Create free account
hub / github.com/cheikhshift/cleo / DebugTemplatePath

Function DebugTemplatePath

application.go:272–376  ·  view source on GitHub ↗
(tmpl string, intrf interface{})

Source from the content-addressed store, hash-verified

270}
271
272func DebugTemplatePath(tmpl string, intrf interface{}) {
273 lastline := 0
274 linestring := ""
275 defer func() {
276 if n := recover(); n != nil {
277
278 log.Println("Error on line :", lastline+1, ":"+strings.TrimSpace(linestring))
279 log.Println(n)
280 //http.Redirect(w,r,"/your-500-page",307)
281 }
282 }()
283
284 filename := tmpl
285 body, err := Asset(filename)
286
287 if err != nil {
288 log.Print(err)
289
290 } else {
291
292 lines := strings.Split(string(body), "\n")
293 // log.Println( lines )
294 linebuffer := ""
295 waitend := false
296 open := 0
297 for i, line := range lines {
298
299 processd := false
300
301 if strings.Contains(line, "{{with") || strings.Contains(line, "{{ with") || strings.Contains(line, "with}}") || strings.Contains(line, "with }}") || strings.Contains(line, "{{range") || strings.Contains(line, "{{ range") || strings.Contains(line, "range }}") || strings.Contains(line, "range}}") || strings.Contains(line, "{{if") || strings.Contains(line, "{{ if") || strings.Contains(line, "if }}") || strings.Contains(line, "if}}") || strings.Contains(line, "{{block") || strings.Contains(line, "{{ block") || strings.Contains(line, "block }}") || strings.Contains(line, "block}}") {
302 linebuffer += line
303 waitend = true
304
305 endstr := ""
306 if !(strings.Contains(line, "{{end") || strings.Contains(line, "{{ end") || strings.Contains(line, "end}}") || strings.Contains(line, "end }}")) {
307
308 open++
309
310 }
311
312 for i := 0; i < open; i++ {
313 endstr += "\n{{end}}"
314 }
315 //exec
316
317 processd = true
318 outp := new(bytes.Buffer)
319 t := template.New("PageWrapper")
320 t = t.Funcs(TemplateFuncStore)
321 t, _ = t.Parse(string([]byte(fmt.Sprintf("%s%s", linebuffer, endstr))))
322 lastline = i
323 linestring = line
324 erro := t.Execute(outp, intrf)
325 if erro != nil {
326 log.Println("Error on line :", i+1, line, erro.Error())
327 }
328 }
329

Callers 6

templateFNangFunction · 0.85
NetangFunction · 0.85
templateFNserverFunction · 0.85
NetserverFunction · 0.85
templateFNjqueryFunction · 0.85
NetjqueryFunction · 0.85

Calls 1

AssetFunction · 0.85

Tested by

no test coverage detected