Browse Source

upgrade jet parser to version 6 as requested

relative to: https://github.com/kataras/iris/issues/1723
pull/1729/head
Gerasimos (Makis) Maropoulos 5 months ago
parent
commit
ed33a77019
No known key found for this signature in database GPG Key ID: A771A828097B36C7
4 changed files with 13 additions and 16 deletions
  1. +1
    -1
      _examples/README.md
  2. +0
    -1
      _examples/view/template_jet_3/main.go
  3. +1
    -1
      go.mod
  4. +11
    -13
      view/jet.go

+ 1
- 1
_examples/README.md View File

@@ -89,7 +89,7 @@
* [Root and Proxy AccessLog instances](logging/request-logger/accesslog-proxy/main.go)
* API Documentation
* [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)
* [Recovery](recover/main.go)
* [Profiling](pprof/main.go)


+ 0
- 1
_examples/view/template_jet_3/main.go View File

@@ -10,7 +10,6 @@ import (
)

func main() {

tmpl := iris.Jet("./views", ".jet")
tmpl.Reload(true)



+ 1
- 1
go.mod View File

@@ -4,7 +4,7 @@ go 1.15

require (
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/andybalholm/brotli v1.0.1
github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible


+ 11
- 13
view/jet.go View File

@@ -12,7 +12,7 @@ import (

"github.com/kataras/iris/v12/context"

"github.com/CloudyKit/jet/v5"
"github.com/CloudyKit/jet/v6"
)

const jetEngineName = "jet"
@@ -209,14 +209,10 @@ func (l *jetLoader) Open(name string) (io.ReadCloser, error) {
return l.fs.Open(name)
}

// 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) (string, bool) {
if _, err := l.fs.Open(name); err == nil {
return name, true
}

return "", false
// Exists checks if the template name exists by walking the list of template paths.
func (l *jetLoader) Exists(name string) bool {
_, err := l.fs.Open(name)
return err == nil
}

// 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 {
s.initSet()

_, err := s.Set.LoadTemplate(name, contents)
_, err := s.Set.Parse(name, contents)
return err
}

func (s *JetEngine) initSet() {
s.mu.Lock()
if s.Set == nil {
s.Set = jet.NewHTMLSetLoader(s.loader)
s.Set.Delims(s.left, s.right)
var opts = []jet.Option{
jet.WithDelims(s.left, s.right),
}
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 can be produced when nil fs passed
// 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 {
for key, value := range s.vars {
s.Set.AddGlobal(key, value)


Loading…
Cancel
Save