Skip to content

Commit 75bec52

Browse files
committed
🩹 fix dynamic layouts
1 parent b71ebc8 commit 75bec52

File tree

11 files changed

+48
-15
lines changed

11 files changed

+48
-15
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: 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
@@ -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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ require (
1010
github.com/cbroglie/mustache v1.2.0
1111
github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385
1212
github.com/flosch/pongo2/v4 v4.0.0
13-
github.com/gofiber/fiber/v2 v2.0.1
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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=

‎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)