Browse Source

loader(s) must be passed on initialization

Darko Luketic 2 years ago
parent
commit
135199c774
2 changed files with 6 additions and 14 deletions
  1. 3 1
      README.md
  2. 3 13
      render.go

+ 3 - 1
README.md

@@ -17,11 +17,13 @@ If you'd like to use pongo2.v3 see github.com/dalu/pongo2v3
         func main () {
         	r := gin.Default()
 
+            pl := pongo2.MustNewLocalFileSystemLoader("templates")
+
     		// templates is the basePath
     		// gin.IsDebugging() means if gin is in debug/dev mode then templates
     		// will always be reloaded from disk, otherwise from cache and never
     		// reloaded.
-    		pr := ginpongo2.New("templates", gin.IsDebugging())
+    		pr := ginpongo2.New(gin.IsDebugging(), pl)
  
     		ginpongo2.Suffix = ".html.twig" // this is default
     		// when ever you render something reference it by prefix

+ 3 - 13
render.go

@@ -2,11 +2,9 @@ package ginpongo2
 
 import (
 	"fmt"
-	"net/http"
-	"strings"
-
 	"github.com/flosch/pongo2"
 	"github.com/gin-gonic/gin/render"
+	"net/http"
 )
 
 var Suffix = ".html.twig"
@@ -45,17 +43,9 @@ func (r *PongoRenderer) WriteContentType(w http.ResponseWriter) {
 	}
 }
 
-func New(basedir string, debug bool, loaders ...pongo2.TemplateLoader) *Pongo {
+func New(debug bool, loaders ...pongo2.TemplateLoader) *Pongo {
 	p := new(Pongo)
-	p.set = pongo2.NewSet("html")
+	p.set = pongo2.NewSet("html", loaders...)
 	p.set.Debug = debug
-	if !strings.HasSuffix(basedir, "/") {
-		basedir = basedir + "/"
-	}
-	if len(loaders) > 0 {
-		p.set.AddLoader(loaders...)
-	} else {
-		p.set.AddLoader(pongo2.MustNewLocalFileSystemLoader(basedir))
-	}
 	return p
 }