Skip to content

Commit ce44e39

Browse files
authored
Merge pull request #47 from Fenny/master
🩹 fix cloning dynamic partials
2 parents 8c3e62a + ac1d66f commit ce44e39

File tree

11 files changed

+65
-19
lines changed

11 files changed

+65
-19
lines changed

ace/ace.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ type Engine struct {
2727
extension string
2828
// layout variable name that incapsulates the template
2929
layout string
30+
// determines if the engine parsed all templates
31+
loaded bool
3032
// reload on each render
3133
reload bool
3234
// debug prints the parsed templates
@@ -187,6 +189,8 @@ func (e *Engine) Load() error {
187189
}
188190
return err
189191
}
192+
// notify engine that we parsed all templates
193+
e.loaded = true
190194
if e.fileSystem != nil {
191195
return utils.Walk(e.fileSystem, e.directory, walkFn)
192196
}
@@ -196,7 +200,7 @@ func (e *Engine) Load() error {
196200
// Execute will render the template by name
197201
func (e *Engine) Render(out io.Writer, template string, binding interface{}, layout ...string) error {
198202
// reload the views
199-
if e.reload {
203+
if !e.loaded || e.reload {
200204
ace.FlushCache()
201205
if err := e.Load(); err != nil {
202206
return err

amber/amber.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ type Engine struct {
2424
extension string
2525
// layout variable name that incapsulates the template
2626
layout string
27+
// determines if the engine parsed all templates
28+
loaded bool
2729
// reload on each render
2830
reload bool
2931
// debug prints the parsed templates
@@ -176,7 +178,8 @@ func (e *Engine) Load() error {
176178
}
177179
return err
178180
}
179-
181+
// notify engine that we parsed all templates
182+
e.loaded = true
180183
if e.fileSystem != nil {
181184
return utils.Walk(e.fileSystem, e.directory, walkFn)
182185
}
@@ -185,7 +188,7 @@ func (e *Engine) Load() error {
185188

186189
// Render will execute the template name along with the given values.
187190
func (e *Engine) Render(out io.Writer, template string, binding interface{}, layout ...string) error {
188-
if e.reload {
191+
if !e.loaded || e.reload {
189192
if err := e.Load(); err != nil {
190193
return err
191194
}

django/django.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"strings"
1010
"sync"
1111

12-
"github.com/flosch/pongo2/v4"
12+
"github.com/flosch/pongo2"
1313
"github.com/gofiber/fiber/v2"
1414
"github.com/gofiber/template/utils"
1515
)
@@ -27,6 +27,8 @@ type Engine struct {
2727
extension string
2828
// layout variable name that incapsulates the template
2929
layout string
30+
// determines if the engine parsed all templates
31+
loaded bool
3032
// reload on each render
3133
reload bool
3234
// debug prints the parsed templates
@@ -165,6 +167,8 @@ func (e *Engine) Load() error {
165167
}
166168
return err
167169
}
170+
// notify engine that we parsed all templates
171+
e.loaded = true
168172
if e.fileSystem != nil {
169173
return utils.Walk(e.fileSystem, e.directory, walkFn)
170174
}
@@ -194,7 +198,7 @@ func getPongoBinding(binding interface{}) pongo2.Context {
194198

195199
// Render will render the template by name
196200
func (e *Engine) Render(out io.Writer, template string, binding interface{}, layout ...string) error {
197-
if e.reload {
201+
if !e.loaded || e.reload {
198202
if err := e.Load(); err != nil {
199203
return err
200204
}

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ require (
99
github.com/aymerick/raymond v2.0.2+incompatible
1010
github.com/cbroglie/mustache v1.2.0
1111
github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385
12-
github.com/flosch/pongo2/v4 v4.0.0
13-
github.com/gofiber/fiber/v2 v2.0.1
12+
github.com/flosch/pongo2 v0.0.0-20200913210552-0d938eb266f3
13+
github.com/gofiber/fiber/v2 v2.0.2
1414
github.com/mattn/go-slim v0.0.0-20200618151855-bde33eecb5ee
1515
github.com/valyala/bytebufferpool v1.0.0
1616
github.com/yosssi/ace v0.0.5

go.sum

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385/go.mod h1:0vRUJqYpeSZi
7272
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
7373
github.com/fatih/color v1.9.0 h1:8xPHl4/q1VyqGIPif1F+1V3Y3lSmrq01EabUW3CoW5s=
7474
github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU=
75-
github.com/flosch/pongo2/v4 v4.0.0 h1:6eZe8NSNxtTTGwXgJqqXiiLEDAj7CvkwiYrZFQRW6cQ=
76-
github.com/flosch/pongo2/v4 v4.0.0/go.mod h1:B5ObFANs/36VwxxlgKpdchIJHMvHB562PW+BWPhwZD8=
75+
github.com/flosch/pongo2 v0.0.0-20200913210552-0d938eb266f3 h1:fmFk0Wt3bBxxwZnu48jqMdaOR/IZ4vdtJFuaFV8MpIE=
76+
github.com/flosch/pongo2 v0.0.0-20200913210552-0d938eb266f3/go.mod h1:bJWSKrZyQvfTnb2OudyUjurSG4/edverV7n82+K3JiM=
7777
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
7878
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
7979
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
@@ -113,8 +113,8 @@ github.com/go-xmlfmt/xmlfmt v0.0.0-20191208150333-d5b6f63a941b h1:khEcpUM4yFcxg4
113113
github.com/go-xmlfmt/xmlfmt v0.0.0-20191208150333-d5b6f63a941b/go.mod h1:aUCEOzzezBEjDBbFBoSiya/gduyIiWYRP6CnSFIV8AM=
114114
github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y=
115115
github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8=
116-
github.com/gofiber/fiber/v2 v2.0.1 h1:82Sw1SyHrEaKLYdXbNJGzI/t2okEeDIuw9nJGKpQmaI=
117-
github.com/gofiber/fiber/v2 v2.0.1/go.mod h1:GeIpT8VILgZt3Tn6gATjwb39Ff8OdM0qnZ2grAA0Vts=
116+
github.com/gofiber/fiber/v2 v2.0.2 h1:Zet9qNptQkhrLZhWBHZQNjeSnokp8xyiGQp4Je0p3yk=
117+
github.com/gofiber/fiber/v2 v2.0.2/go.mod h1:GeIpT8VILgZt3Tn6gATjwb39Ff8OdM0qnZ2grAA0Vts=
118118
github.com/gofrs/flock v0.7.1 h1:DP+LD/t0njgoPBvT5MJLeliUIVQR03hiKR6vezdwHlc=
119119
github.com/gofrs/flock v0.7.1/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU=
120120
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
@@ -539,9 +539,11 @@ golang.org/x/tools v0.0.0-20200422022333-3d57cf2e726e/go.mod h1:EkVYQZoAsY45+roY
539539
golang.org/x/tools v0.0.0-20200428185508-e9a00ec82136/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
540540
golang.org/x/tools v0.0.0-20200519015757-0d0afa43d58a/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
541541
golang.org/x/tools v0.0.0-20200625211823-6506e20df31f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
542+
golang.org/x/tools v0.0.0-20200702044944-0cc1aa72b347 h1:/e4fNMHdLn7SQSxTrRZTma2xjQW6ELdxcnpqMhpo9X4=
542543
golang.org/x/tools v0.0.0-20200702044944-0cc1aa72b347/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
543544
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
544545
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
546+
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
545547
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
546548
google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
547549
google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M=
@@ -573,25 +575,36 @@ gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8
573575
gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b h1:QRR6H1YWRnHb4Y/HeNFCTJLFVxaq6wH4YuVdsUOr75U=
574576
gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
575577
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
578+
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
576579
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
580+
gopkg.in/ini.v1 v1.51.0 h1:AQvPpx3LzTDM0AjnIRlVFwFFGC+npRopjZxLJj6gdno=
577581
gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
578582
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
583+
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
579584
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
580585
gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
581586
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
582587
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
583588
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
584589
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
590+
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
585591
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
592+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
586593
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
587594
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
588595
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
589596
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
590597
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
598+
honnef.co/go/tools v0.0.1-2020.1.4 h1:UoveltGrhghAA7ePc+e+QYDHXrBps2PqFZiHkGR/xK8=
591599
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
600+
mvdan.cc/gofumpt v0.0.0-20200513141252-abc0db2c416a h1:TTEzidAa7rn93JGy1ACigx6o9VcsRLKG7qICdErmvUs=
592601
mvdan.cc/gofumpt v0.0.0-20200513141252-abc0db2c416a/go.mod h1:4q/PlrZKQLU5MowSvCKM3U4xJUPtJ8vKWx7vsWFJ3MI=
602+
mvdan.cc/interfacer v0.0.0-20180901003855-c20040233aed h1:WX1yoOaKQfddO/mLzdV4wptyWgoH/6hwLs7QHTixo0I=
593603
mvdan.cc/interfacer v0.0.0-20180901003855-c20040233aed/go.mod h1:Xkxe497xwlCKkIaQYRfC7CSLworTXY9RMqwhhCm+8Nc=
604+
mvdan.cc/lint v0.0.0-20170908181259-adc824a0674b h1:DxJ5nJdkhDlLok9K6qO+5290kphDJbHOQO1DFFFTeBo=
594605
mvdan.cc/lint v0.0.0-20170908181259-adc824a0674b/go.mod h1:2odslEg/xrtNQqCYg2/jCoyKnw3vv5biOc3JnIcYfL4=
606+
mvdan.cc/unparam v0.0.0-20190720180237-d51796306d8f h1:Cq7MalBHYACRd6EesksG1Q8EoIAKOsiZviGKbOLIej4=
595607
mvdan.cc/unparam v0.0.0-20190720180237-d51796306d8f/go.mod h1:4G1h5nDURzA3bwVMZIVpwbkw+04kSxk3rAtzlimaUJw=
596608
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
609+
sourcegraph.com/sqs/pbtypes v0.0.0-20180604144634-d3ebe8f20ae4 h1:JPJh2pk3+X4lXAkZIk2RuE/7/FoK9maXw+TNPJhVS/c=
597610
sourcegraph.com/sqs/pbtypes v0.0.0-20180604144634-d3ebe8f20ae4/go.mod h1:ketZ/q3QxT9HOBeFhu6RdvsftgpsbFHBF5Cas6cDKZ0=

handlebars/handlebars.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ type Engine struct {
2323
extension string
2424
// layout variable name that incapsulates the template
2525
layout string
26+
// determines if the engine parsed all templates
27+
loaded bool
2628
// reload on each render
2729
reload bool
2830
// debug prints the parsed templates
@@ -170,12 +172,14 @@ func (e *Engine) Load() (err error) {
170172
e.Templates[i].RegisterPartialTemplate(n, t)
171173
}
172174
}
175+
// notify engine that we parsed all templates
176+
e.loaded = true
173177
return
174178
}
175179

176180
// Execute will render the template by name
177181
func (e *Engine) Render(out io.Writer, template string, binding interface{}, layout ...string) error {
178-
if e.reload {
182+
if !e.loaded || e.reload {
179183
if err := e.Load(); err != nil {
180184
return err
181185
}

html/html.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ type Engine struct {
2626
extension string
2727
// layout variable name that incapsulates the template
2828
layout string
29+
// determines if the engine parsed all templates
30+
loaded bool
2931
// reload on each render
3032
reload bool
3133
// debug prints the parsed templates
@@ -170,7 +172,8 @@ func (e *Engine) Load() error {
170172
}
171173
return err
172174
}
173-
175+
// notify engine that we parsed all templates
176+
e.loaded = true
174177
if e.fileSystem != nil {
175178
return utils.Walk(e.fileSystem, e.directory, walkFn)
176179
}
@@ -179,7 +182,7 @@ func (e *Engine) Load() error {
179182

180183
// Render will execute the template name along with the given values.
181184
func (e *Engine) Render(out io.Writer, template string, binding interface{}, layout ...string) error {
182-
if e.reload {
185+
if !e.loaded || e.reload {
183186
if err := e.Load(); err != nil {
184187
return err
185188
}

jet/jet.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ type Engine struct {
2828
extension string
2929
// layout variable name that incapsulates the template
3030
layout string
31+
// determines if the engine parsed all templates
32+
loaded bool
3133
// reload on each render
3234
reload bool
3335
// debug prints the parsed templates
@@ -177,6 +179,8 @@ func (e *Engine) Load() error {
177179
}
178180
return err
179181
}
182+
// notify engine that we parsed all templates
183+
e.loaded = true
180184
if e.fileSystem != nil {
181185
return utils.Walk(e.fileSystem, e.directory, walkFn)
182186
}
@@ -185,7 +189,7 @@ func (e *Engine) Load() error {
185189

186190
// Execute will render the template by name
187191
func (e *Engine) Render(out io.Writer, template string, binding interface{}, layout ...string) error {
188-
if e.reload {
192+
if !e.loaded || e.reload {
189193
if err := e.Load(); err != nil {
190194
return err
191195
}

mustache/mustache.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ type Engine struct {
2424
extension string
2525
// layout variable name that incapsulates the template
2626
layout string
27+
// determines if the engine parsed all templates
28+
loaded bool
2729
// reload on each render
2830
reload bool
2931
// debug prints the parsed templates
@@ -144,6 +146,8 @@ func (e *Engine) Load() error {
144146
}
145147
return err
146148
}
149+
// notify engine that we parsed all templates
150+
e.loaded = true
147151
if e.fileSystem != nil {
148152
return utils.Walk(e.fileSystem, e.directory, walkFn)
149153
}
@@ -152,7 +156,7 @@ func (e *Engine) Load() error {
152156

153157
// Execute will render the template by name
154158
func (e *Engine) Render(out io.Writer, template string, binding interface{}, layout ...string) error {
155-
if e.reload {
159+
if !e.loaded || e.reload {
156160
if err := e.Load(); err != nil {
157161
return err
158162
}

pug/pug.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ type Engine struct {
2828
extension string
2929
// layout variable name that incapsulates the template
3030
layout string
31+
// determines if the engine parsed all templates
32+
loaded bool
3133
// reload on each render
3234
reload bool
3335
// debug prints the parsed templates
@@ -177,7 +179,8 @@ func (e *Engine) Load() error {
177179
}
178180
return err
179181
}
180-
182+
// notify engine that we parsed all templates
183+
e.loaded = true
181184
if e.fileSystem != nil {
182185
return utils.Walk(e.fileSystem, e.directory, walkFn)
183186
}
@@ -186,7 +189,7 @@ func (e *Engine) Load() error {
186189

187190
// Execute will render the template by name
188191
func (e *Engine) Render(out io.Writer, template string, binding interface{}, layout ...string) error {
189-
if e.reload {
192+
if !e.loaded || e.reload {
190193
if err := e.Load(); err != nil {
191194
return err
192195
}

0 commit comments

Comments
 (0)