diff --git a/.github/README.md b/.github/README.md index 3add6c6..fac2857 100644 --- a/.github/README.md +++ b/.github/README.md @@ -60,6 +60,10 @@ func main() { // and template extension using .New(dir, ext string) engine := html.New("./views", ".html") + // We also support the http.FileSystem interface + // See examples below to load templates from embedded files + engine := html.NewFileSystem(http.Dir("./views"), ".html") + // Reload the templates on each render, good for development engine.Reload(true) // Optional. Default: false diff --git a/go.mod b/go.mod index d80baf0..2e04958 100644 --- a/go.mod +++ b/go.mod @@ -10,6 +10,7 @@ require ( github.com/cbroglie/mustache v1.1.0 github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385 github.com/flosch/pongo2 v0.0.0-20200518135938-dfb43dbdc22a + github.com/mattn/go-slim v0.0.0-20190926010428-236f1c35e4e6 github.com/valyala/bytebufferpool v1.0.0 github.com/yosssi/ace v0.0.5 gopkg.in/yaml.v2 v2.3.0 // indirect diff --git a/go.sum b/go.sum index 3b103f9..652bd4b 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/CloudyKit/fastprinter v0.0.0-20200109182630-33d98a066a53 h1:sR+/8Yb4slttB4vD+b9btVEnWgL3Q00OBTzVT8B9C0c= github.com/CloudyKit/fastprinter v0.0.0-20200109182630-33d98a066a53/go.mod h1:+3IMCy2vIlbG1XG/0ggNQv0SvxCAIpPM5b1nCz56Xno= +github.com/CloudyKit/jet v2.1.2+incompatible h1:ybZoYzMBdoijK6I+Ke3vg9GZsmlKo/ZhKdNMWz0P26c= +github.com/CloudyKit/jet v2.1.2+incompatible/go.mod h1:HPYO+50pSWkPoj9Q/eq0aRGByCL6ScRlUmiEX5Zgm+w= github.com/CloudyKit/jet/v3 v3.0.0 h1:1PwO5w5VCtlUUl+KTOBsTGZlhjWkcybsGaAau52tOy8= github.com/CloudyKit/jet/v3 v3.0.0/go.mod h1:HKQPgSJmdK8hdoAbKUUWajkHyHo4RaU5rMdUywE7VMo= github.com/Joker/hpp v0.0.0-20180418125244-6893e659854a h1:PiDAizhfJbwZMISZ1Itx1ZTFeOFCml89Ofmz3V8rhoU= @@ -41,6 +43,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= +github.com/mattn/go-slim v0.0.0-20190926010428-236f1c35e4e6 h1:GF43XHtQ/ewS07mITQZyi9gXhWZ7x7crGWp2hvHUEkM= +github.com/mattn/go-slim v0.0.0-20190926010428-236f1c35e4e6/go.mod h1:ma9TUJeni8LGZMJvOwbAv/FOwiwqIMQN570LnpqCBSM= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= diff --git a/pug/pug.go b/pug/pug.go index a936226..7fbfb15 100644 --- a/pug/pug.go +++ b/pug/pug.go @@ -49,7 +49,6 @@ func New(directory, extension string) *Engine { extension: extension, layout: "embed", funcmap: make(map[string]interface{}), - Templates: template.New(directory), } engine.AddFunc(engine.layout, func() error { return fmt.Errorf("layout called unexpectedly.") @@ -124,6 +123,8 @@ func (e *Engine) Load() error { e.mutex.Lock() defer e.mutex.Unlock() + e.Templates = template.New(e.directory) + // Set template settings e.Templates.Delims(e.left, e.right) e.Templates.Funcs(e.funcmap)