mirror of
https://github.com/kataras/iris.git
synced 2025-01-23 02:31:04 +01:00
view: allow only-custom template parsing
This commit is contained in:
parent
c9c13d76b5
commit
7672574232
|
@ -13,6 +13,8 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
|
||||||
|
"github.com/kataras/iris/v12/context"
|
||||||
|
|
||||||
"github.com/eknkc/amber"
|
"github.com/eknkc/amber"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -152,6 +154,11 @@ func (s *AmberEngine) AddFunc(funcName string, funcBody interface{}) {
|
||||||
//
|
//
|
||||||
// Returns an error if something bad happens, user is responsible to catch it.
|
// Returns an error if something bad happens, user is responsible to catch it.
|
||||||
func (s *AmberEngine) Load() error {
|
func (s *AmberEngine) Load() error {
|
||||||
|
// If only custom templates should be loaded.
|
||||||
|
if (s.fs == nil || context.IsNoOpFS(s.fs)) && len(s.templateCache) > 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
rootDirName := getRootDirName(s.fs)
|
rootDirName := getRootDirName(s.fs)
|
||||||
|
|
||||||
return walk(s.fs, "", func(path string, info os.FileInfo, err error) error {
|
return walk(s.fs, "", func(path string, info os.FileInfo, err error) error {
|
||||||
|
|
|
@ -222,6 +222,11 @@ func (s *DjangoEngine) RegisterTag(tagName string, fn TagParser) error {
|
||||||
//
|
//
|
||||||
// Returns an error if something bad happens, user is responsible to catch it.
|
// Returns an error if something bad happens, user is responsible to catch it.
|
||||||
func (s *DjangoEngine) Load() error {
|
func (s *DjangoEngine) Load() error {
|
||||||
|
// If only custom templates should be loaded.
|
||||||
|
if (s.fs == nil || context.IsNoOpFS(s.fs)) && len(s.templateCache) > 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
rootDirName := getRootDirName(s.fs)
|
rootDirName := getRootDirName(s.fs)
|
||||||
|
|
||||||
return walk(s.fs, "", func(path string, info os.FileInfo, err error) error {
|
return walk(s.fs, "", func(path string, info os.FileInfo, err error) error {
|
||||||
|
|
|
@ -10,6 +10,8 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/kataras/iris/v12/context"
|
||||||
|
|
||||||
"github.com/mailgun/raymond/v2"
|
"github.com/mailgun/raymond/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -134,6 +136,11 @@ func (s *HandlebarsEngine) AddGlobalFunc(funcName string, funcBody interface{})
|
||||||
//
|
//
|
||||||
// Returns an error if something bad happens, user is responsible to catch it.
|
// Returns an error if something bad happens, user is responsible to catch it.
|
||||||
func (s *HandlebarsEngine) Load() error {
|
func (s *HandlebarsEngine) Load() error {
|
||||||
|
// If only custom templates should be loaded.
|
||||||
|
if (s.fs == nil || context.IsNoOpFS(s.fs)) && len(s.templateCache) > 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
rootDirName := getRootDirName(s.fs)
|
rootDirName := getRootDirName(s.fs)
|
||||||
|
|
||||||
return walk(s.fs, "", func(path string, info os.FileInfo, _ error) error {
|
return walk(s.fs, "", func(path string, info os.FileInfo, _ error) error {
|
||||||
|
|
10
view/html.go
10
view/html.go
|
@ -10,6 +10,8 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/kataras/iris/v12/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
// HTMLEngine contains the html view engine structure.
|
// HTMLEngine contains the html view engine structure.
|
||||||
|
@ -61,7 +63,8 @@ var (
|
||||||
// Usage:
|
// Usage:
|
||||||
// HTML("./views", ".html") or
|
// HTML("./views", ".html") or
|
||||||
// HTML(iris.Dir("./views"), ".html") or
|
// HTML(iris.Dir("./views"), ".html") or
|
||||||
// HTML(embed.FS, ".html") or HTML(AssetFile(), ".html") for embedded data.
|
// HTML(embed.FS, ".html") or HTML(AssetFile(), ".html") for embedded data or
|
||||||
|
// HTML("","").ParseTemplate("hello", `[]byte("hello {{.Name}}")`, nil) for custom template parsing only.
|
||||||
func HTML(dirOrFS interface{}, extension string) *HTMLEngine {
|
func HTML(dirOrFS interface{}, extension string) *HTMLEngine {
|
||||||
s := &HTMLEngine{
|
s := &HTMLEngine{
|
||||||
name: "HTML",
|
name: "HTML",
|
||||||
|
@ -243,6 +246,11 @@ func (s *HTMLEngine) load() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If only custom templates should be loaded.
|
||||||
|
if (s.fs == nil || context.IsNoOpFS(s.fs)) && len(s.Templates.DefinedTemplates()) > 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
rootDirName := getRootDirName(s.fs)
|
rootDirName := getRootDirName(s.fs)
|
||||||
|
|
||||||
err := walk(s.fs, "", func(path string, info os.FileInfo, err error) error {
|
err := walk(s.fs, "", func(path string, info os.FileInfo, err error) error {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user