Skip to content

Commit 7672574

Browse files
committed
view: allow only-custom template parsing
1 parent c9c13d7 commit 7672574

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

view/amber.go

+7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import (
1313
"sync"
1414
"sync/atomic"
1515

16+
"github.com/kataras/iris/v12/context"
17+
1618
"github.com/eknkc/amber"
1719
)
1820

@@ -152,6 +154,11 @@ func (s *AmberEngine) AddFunc(funcName string, funcBody interface{}) {
152154
//
153155
// Returns an error if something bad happens, user is responsible to catch it.
154156
func (s *AmberEngine) Load() error {
157+
// If only custom templates should be loaded.
158+
if (s.fs == nil || context.IsNoOpFS(s.fs)) && len(s.templateCache) > 0 {
159+
return nil
160+
}
161+
155162
rootDirName := getRootDirName(s.fs)
156163

157164
return walk(s.fs, "", func(path string, info os.FileInfo, err error) error {

view/django.go

+5
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,11 @@ func (s *DjangoEngine) RegisterTag(tagName string, fn TagParser) error {
222222
//
223223
// Returns an error if something bad happens, user is responsible to catch it.
224224
func (s *DjangoEngine) Load() error {
225+
// If only custom templates should be loaded.
226+
if (s.fs == nil || context.IsNoOpFS(s.fs)) && len(s.templateCache) > 0 {
227+
return nil
228+
}
229+
225230
rootDirName := getRootDirName(s.fs)
226231

227232
return walk(s.fs, "", func(path string, info os.FileInfo, err error) error {

view/handlebars.go

+7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
"strings"
1111
"sync"
1212

13+
"github.com/kataras/iris/v12/context"
14+
1315
"github.com/mailgun/raymond/v2"
1416
)
1517

@@ -134,6 +136,11 @@ func (s *HandlebarsEngine) AddGlobalFunc(funcName string, funcBody interface{})
134136
//
135137
// Returns an error if something bad happens, user is responsible to catch it.
136138
func (s *HandlebarsEngine) Load() error {
139+
// If only custom templates should be loaded.
140+
if (s.fs == nil || context.IsNoOpFS(s.fs)) && len(s.templateCache) > 0 {
141+
return nil
142+
}
143+
137144
rootDirName := getRootDirName(s.fs)
138145

139146
return walk(s.fs, "", func(path string, info os.FileInfo, _ error) error {

view/html.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
"path/filepath"
1111
"strings"
1212
"sync"
13+
14+
"github.com/kataras/iris/v12/context"
1315
)
1416

1517
// HTMLEngine contains the html view engine structure.
@@ -61,7 +63,8 @@ var (
6163
// Usage:
6264
// HTML("./views", ".html") or
6365
// HTML(iris.Dir("./views"), ".html") or
64-
// HTML(embed.FS, ".html") or HTML(AssetFile(), ".html") for embedded data.
66+
// HTML(embed.FS, ".html") or HTML(AssetFile(), ".html") for embedded data or
67+
// HTML("","").ParseTemplate("hello", `[]byte("hello {{.Name}}")`, nil) for custom template parsing only.
6568
func HTML(dirOrFS interface{}, extension string) *HTMLEngine {
6669
s := &HTMLEngine{
6770
name: "HTML",
@@ -243,6 +246,11 @@ func (s *HTMLEngine) load() error {
243246
return err
244247
}
245248

249+
// If only custom templates should be loaded.
250+
if (s.fs == nil || context.IsNoOpFS(s.fs)) && len(s.Templates.DefinedTemplates()) > 0 {
251+
return nil
252+
}
253+
246254
rootDirName := getRootDirName(s.fs)
247255

248256
err := walk(s.fs, "", func(path string, info os.FileInfo, err error) error {

0 commit comments

Comments
 (0)