mirror of
https://github.com/kataras/iris.git
synced 2026-01-10 05:25:58 +00:00
version 12.1.5
Former-commit-id: cda69f08955cb0d594e98bf26197ee573cbba4b2
This commit is contained in:
@@ -33,8 +33,8 @@ func Amber(directory, extension string) *AmberEngine {
|
||||
s := &AmberEngine{
|
||||
directory: directory,
|
||||
extension: extension,
|
||||
templateCache: make(map[string]*template.Template, 0),
|
||||
funcs: make(map[string]interface{}, 0),
|
||||
templateCache: make(map[string]*template.Template),
|
||||
funcs: make(map[string]interface{}),
|
||||
}
|
||||
|
||||
return s
|
||||
|
||||
@@ -113,9 +113,9 @@ func Django(directory, extension string) *DjangoEngine {
|
||||
s := &DjangoEngine{
|
||||
directory: directory,
|
||||
extension: extension,
|
||||
globals: make(map[string]interface{}, 0),
|
||||
filters: make(map[string]FilterFunction, 0),
|
||||
templateCache: make(map[string]*pongo2.Template, 0),
|
||||
globals: make(map[string]interface{}),
|
||||
filters: make(map[string]FilterFunction),
|
||||
templateCache: make(map[string]*pongo2.Template),
|
||||
}
|
||||
|
||||
return s
|
||||
@@ -235,7 +235,7 @@ func (s *DjangoEngine) loadDirectory() (templateErr error) {
|
||||
defer s.mu.Unlock()
|
||||
|
||||
// Walk the supplied directory and compile any files that match our extension list.
|
||||
filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
|
||||
err = filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
|
||||
// Fix same-extension-dirs bug: some dir might be named to: "users.tmpl", "local.html".
|
||||
// These dirs should be excluded as they are not valid golang templates, but files under
|
||||
// them should be treat as normal.
|
||||
@@ -270,6 +270,10 @@ func (s *DjangoEngine) loadDirectory() (templateErr error) {
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -294,8 +298,6 @@ func (s *DjangoEngine) loadAssets() error {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
var templateErr error
|
||||
|
||||
names := namesFn()
|
||||
for _, path := range names {
|
||||
if !strings.HasPrefix(path, virtualDirectory) {
|
||||
@@ -304,7 +306,6 @@ func (s *DjangoEngine) loadAssets() error {
|
||||
|
||||
rel, err := filepath.Rel(virtualDirectory, path)
|
||||
if err != nil {
|
||||
templateErr = err
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -313,18 +314,18 @@ func (s *DjangoEngine) loadAssets() error {
|
||||
|
||||
buf, err := assetFn(path)
|
||||
if err != nil {
|
||||
templateErr = err
|
||||
return err
|
||||
}
|
||||
|
||||
name := filepath.ToSlash(rel)
|
||||
s.templateCache[name], err = set.FromString(string(buf))
|
||||
if err != nil {
|
||||
templateErr = err
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return templateErr
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// getPongoContext returns the pongo2.Context from map[string]interface{} or from pongo2.Context, used internaly
|
||||
|
||||
@@ -29,15 +29,3 @@ type Engine interface {
|
||||
// Ext should return the final file extension which this view engine is responsible to render.
|
||||
Ext() string
|
||||
}
|
||||
|
||||
type namedEngine interface {
|
||||
String() string
|
||||
}
|
||||
|
||||
func getEngineName(e Engine) string {
|
||||
if n, ok := e.(namedEngine); ok {
|
||||
return n.String()
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -8,11 +8,3 @@ type EngineFuncer interface {
|
||||
// AddFunc should adds a function to the template's function map.
|
||||
AddFunc(funcName string, funcBody interface{})
|
||||
}
|
||||
|
||||
// these will be added to all template engines used
|
||||
// and completes the EngineFuncer interface.
|
||||
//
|
||||
// There are a lot of default functions but some of them are placed inside of each
|
||||
// template engine because of the different behavior, i.e urlpath and url are inside framework itself,
|
||||
// yield,partial,partial_r,current and render as inside html engine etc...
|
||||
var defaultSharedFuncs = map[string]interface{}{}
|
||||
|
||||
@@ -34,8 +34,8 @@ func Handlebars(directory, extension string) *HandlebarsEngine {
|
||||
s := &HandlebarsEngine{
|
||||
directory: directory,
|
||||
extension: extension,
|
||||
templateCache: make(map[string]*raymond.Template, 0),
|
||||
helpers: make(map[string]interface{}, 0),
|
||||
templateCache: make(map[string]*raymond.Template),
|
||||
helpers: make(map[string]interface{}),
|
||||
}
|
||||
|
||||
// register the render helper here
|
||||
@@ -133,7 +133,7 @@ func (s *HandlebarsEngine) loadDirectory() error {
|
||||
// instead of the html/template engine which works like {{ render "myfile.html"}} and accepts the parent binding, with handlebars we can't do that because of lack of runtime helpers (dublicate error)
|
||||
|
||||
var templateErr error
|
||||
filepath.Walk(dir, func(path string, info os.FileInfo, _ error) error {
|
||||
err := filepath.Walk(dir, func(path string, info os.FileInfo, _ error) error {
|
||||
if info == nil || info.IsDir() {
|
||||
return nil
|
||||
}
|
||||
@@ -165,6 +165,10 @@ func (s *HandlebarsEngine) loadDirectory() error {
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return templateErr
|
||||
}
|
||||
|
||||
@@ -186,7 +190,6 @@ func (s *HandlebarsEngine) loadAssets() error {
|
||||
virtualDirectory = virtualDirectory[1:]
|
||||
}
|
||||
}
|
||||
var templateErr error
|
||||
|
||||
names := namesFn()
|
||||
for _, path := range names {
|
||||
@@ -198,28 +201,27 @@ func (s *HandlebarsEngine) loadAssets() error {
|
||||
|
||||
rel, err := filepath.Rel(virtualDirectory, path)
|
||||
if err != nil {
|
||||
templateErr = err
|
||||
return err
|
||||
}
|
||||
|
||||
buf, err := assetFn(path)
|
||||
if err != nil {
|
||||
templateErr = err
|
||||
return err
|
||||
}
|
||||
|
||||
contents := string(buf)
|
||||
name := filepath.ToSlash(rel)
|
||||
|
||||
tmpl, err := raymond.Parse(contents)
|
||||
if err != nil {
|
||||
templateErr = err
|
||||
return err
|
||||
}
|
||||
s.templateCache[name] = tmpl
|
||||
|
||||
}
|
||||
}
|
||||
return templateErr
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *HandlebarsEngine) fromCache(relativeName string) *raymond.Template {
|
||||
|
||||
18
view/html.go
18
view/html.go
@@ -10,7 +10,6 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
// HTMLEngine contains the html view engine structure.
|
||||
@@ -71,8 +70,8 @@ func HTML(directory, extension string) *HTMLEngine {
|
||||
left: "{{",
|
||||
right: "}}",
|
||||
layout: "",
|
||||
layoutFuncs: make(map[string]interface{}, 0),
|
||||
funcs: make(map[string]interface{}, 0),
|
||||
layoutFuncs: make(map[string]interface{}),
|
||||
funcs: make(map[string]interface{}),
|
||||
}
|
||||
|
||||
return s
|
||||
@@ -244,7 +243,7 @@ func (s *HTMLEngine) loadDirectory() error {
|
||||
s.Templates = template.New(dir)
|
||||
s.Templates.Delims(s.left, s.right)
|
||||
|
||||
filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
|
||||
err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
|
||||
if info == nil || info.IsDir() {
|
||||
} else {
|
||||
rel, err := filepath.Rel(dir, path)
|
||||
@@ -288,6 +287,10 @@ func (s *HTMLEngine) loadDirectory() error {
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return templateErr
|
||||
}
|
||||
|
||||
@@ -374,7 +377,10 @@ func (s *HTMLEngine) loadAssets() error {
|
||||
}
|
||||
|
||||
// Add our funcmaps.
|
||||
tmpl.Funcs(emptyFuncs).Funcs(s.funcs).Parse(contents)
|
||||
if _, err = tmpl.Funcs(emptyFuncs).Funcs(s.funcs).Parse(contents); err != nil {
|
||||
templateErr = err
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
return templateErr
|
||||
@@ -455,8 +461,6 @@ func (s *HTMLEngine) runtimeFuncsFor(name string, binding interface{}) {
|
||||
}
|
||||
}
|
||||
|
||||
var zero = time.Time{}
|
||||
|
||||
// ExecuteWriter executes a template and writes its result to the w writer.
|
||||
func (s *HTMLEngine) ExecuteWriter(w io.Writer, name string, layout string, bindingData interface{}) error {
|
||||
// re-parse the templates if reload is enabled.
|
||||
|
||||
Reference in New Issue
Block a user