Skip to content

Commit

Permalink
Template debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
manucorporat committed Aug 3, 2015
1 parent fd5d429 commit 2b3aa51
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
18 changes: 17 additions & 1 deletion debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@

package gin

import "log"
import (
"bytes"
"html/template"
"log"
)

func init() {
log.SetFlags(0)
Expand All @@ -24,6 +28,18 @@ func debugPrintRoute(httpMethod, absolutePath string, handlers HandlersChain) {
}
}

func debugPrintLoadTemplate(tmpl *template.Template) {
if IsDebugging() {
var buf bytes.Buffer
for _, tmpl := range tmpl.Templates() {
buf.WriteString("\t- ")
buf.WriteString(tmpl.Name())
buf.WriteString("\n")
}
debugPrint("Loaded HTML Templates (%d): \n%s\n", len(tmpl.Templates()), buf.String())
}
}

func debugPrint(format string, values ...interface{}) {
if IsDebugging() {
log.Printf("[GIN-debug] "+format, values...)
Expand Down
1 change: 1 addition & 0 deletions gin.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ func (engine *Engine) allocateContext() *Context {

func (engine *Engine) LoadHTMLGlob(pattern string) {
if IsDebugging() {
debugPrintLoadTemplate(template.Must(template.ParseGlob(pattern)))
engine.HTMLRender = render.HTMLDebug{Glob: pattern}
} else {
templ := template.Must(template.ParseGlob(pattern))
Expand Down

0 comments on commit 2b3aa51

Please sign in to comment.