mirror of
https://github.com/kataras/iris.git
synced 2025-02-02 15:30:36 +01:00
upgrade jet parser to version 6 as requested
relative to: https://github.com/kataras/iris/issues/1723
This commit is contained in:
parent
36bd452b7a
commit
ed33a77019
|
@ -89,7 +89,7 @@
|
||||||
* [Root and Proxy AccessLog instances](logging/request-logger/accesslog-proxy/main.go)
|
* [Root and Proxy AccessLog instances](logging/request-logger/accesslog-proxy/main.go)
|
||||||
* API Documentation
|
* API Documentation
|
||||||
* [Yaag](apidoc/yaag/main.go)
|
* [Yaag](apidoc/yaag/main.go)
|
||||||
* [Swagger](https://github.com/iris-contrib/swagger/tree/master/example)
|
* [Swagger](https://github.com/iris-contrib/swagger/tree/master/_examples/basic)
|
||||||
* [Testing](testing/httptest/main_test.go)
|
* [Testing](testing/httptest/main_test.go)
|
||||||
* [Recovery](recover/main.go)
|
* [Recovery](recover/main.go)
|
||||||
* [Profiling](pprof/main.go)
|
* [Profiling](pprof/main.go)
|
||||||
|
|
|
@ -10,7 +10,6 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
tmpl := iris.Jet("./views", ".jet")
|
tmpl := iris.Jet("./views", ".jet")
|
||||||
tmpl.Reload(true)
|
tmpl.Reload(true)
|
||||||
|
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -4,7 +4,7 @@ go 1.15
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/BurntSushi/toml v0.3.1
|
github.com/BurntSushi/toml v0.3.1
|
||||||
github.com/CloudyKit/jet/v5 v5.1.1
|
github.com/CloudyKit/jet/v6 v6.0.2
|
||||||
github.com/Shopify/goreferrer v0.0.0-20181106222321-ec9c9a553398
|
github.com/Shopify/goreferrer v0.0.0-20181106222321-ec9c9a553398
|
||||||
github.com/andybalholm/brotli v1.0.1
|
github.com/andybalholm/brotli v1.0.1
|
||||||
github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible
|
github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible
|
||||||
|
|
24
view/jet.go
24
view/jet.go
|
@ -12,7 +12,7 @@ import (
|
||||||
|
|
||||||
"github.com/kataras/iris/v12/context"
|
"github.com/kataras/iris/v12/context"
|
||||||
|
|
||||||
"github.com/CloudyKit/jet/v5"
|
"github.com/CloudyKit/jet/v6"
|
||||||
)
|
)
|
||||||
|
|
||||||
const jetEngineName = "jet"
|
const jetEngineName = "jet"
|
||||||
|
@ -209,14 +209,10 @@ func (l *jetLoader) Open(name string) (io.ReadCloser, error) {
|
||||||
return l.fs.Open(name)
|
return l.fs.Open(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exists checks if the template name exists by walking the list of template paths
|
// Exists checks if the template name exists by walking the list of template paths.
|
||||||
// returns string with the full path of the template and bool true if the template file was found
|
func (l *jetLoader) Exists(name string) bool {
|
||||||
func (l *jetLoader) Exists(name string) (string, bool) {
|
_, err := l.fs.Open(name)
|
||||||
if _, err := l.fs.Open(name); err == nil {
|
return err == nil
|
||||||
return name, true
|
|
||||||
}
|
|
||||||
|
|
||||||
return "", false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load should load the templates from a physical system directory or by an embedded one (assets/go-bindata).
|
// Load should load the templates from a physical system directory or by an embedded one (assets/go-bindata).
|
||||||
|
@ -250,22 +246,24 @@ func (s *JetEngine) Load() error {
|
||||||
func (s *JetEngine) ParseTemplate(name string, contents string) error {
|
func (s *JetEngine) ParseTemplate(name string, contents string) error {
|
||||||
s.initSet()
|
s.initSet()
|
||||||
|
|
||||||
_, err := s.Set.LoadTemplate(name, contents)
|
_, err := s.Set.Parse(name, contents)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *JetEngine) initSet() {
|
func (s *JetEngine) initSet() {
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
if s.Set == nil {
|
if s.Set == nil {
|
||||||
s.Set = jet.NewHTMLSetLoader(s.loader)
|
var opts = []jet.Option{
|
||||||
s.Set.Delims(s.left, s.right)
|
jet.WithDelims(s.left, s.right),
|
||||||
|
}
|
||||||
if s.developmentMode && !isNoOpFS(s.fs) {
|
if s.developmentMode && !isNoOpFS(s.fs) {
|
||||||
// this check is made to avoid jet's fs lookup on noOp fs (nil passed by the developer).
|
// this check is made to avoid jet's fs lookup on noOp fs (nil passed by the developer).
|
||||||
// This can be produced when nil fs passed
|
// This can be produced when nil fs passed
|
||||||
// and only `ParseTemplate` is used.
|
// and only `ParseTemplate` is used.
|
||||||
s.Set.SetDevelopmentMode(true)
|
opts = append(opts, jet.InDevelopmentMode())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s.Set = jet.NewSet(s.loader, opts...)
|
||||||
if s.vars != nil {
|
if s.vars != nil {
|
||||||
for key, value := range s.vars {
|
for key, value := range s.vars {
|
||||||
s.Set.AddGlobal(key, value)
|
s.Set.AddGlobal(key, value)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user