1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-08 04:21:57 +00:00

minor fixes on jet and pug view engines

This commit is contained in:
Gerasimos (Makis) Maropoulos
2022-09-27 22:42:42 +03:00
parent 29010bfd7c
commit 50d346de84
6 changed files with 37 additions and 16 deletions

View File

@@ -2,8 +2,9 @@ package view
import (
"bytes"
"os"
"github.com/iris-contrib/jade"
"github.com/Joker/jade"
)
// Pug (or Jade) returns a new pug view engine.
@@ -26,18 +27,12 @@ import (
func Pug(fs interface{}, extension string) *HTMLEngine {
s := HTML(fs, extension)
s.name = "Pug"
s.middleware = func(name string, text []byte) (contents string, err error) {
tmpl := jade.New(name)
tmpl.ReadFunc = func(name string) ([]byte, error) {
return asset(s.fs, name)
jade.ReadFunc = func(filename string) ([]byte, error) {
return asset(s.fs, filename)
}
// Fixes: https://github.com/kataras/iris/issues/1450
// by adding a custom ReadFunc inside the jade parser.
// And Also able to use relative paths on "extends" and "include" directives:
// e.g. instead of extends "templates/layout.pug" we use "layout.pug"
// so contents of templates are independent of their root location.
tmpl := jade.New(name)
exec, err := tmpl.Parse(text)
if err != nil {
return
@@ -45,6 +40,7 @@ func Pug(fs interface{}, extension string) *HTMLEngine {
b := new(bytes.Buffer)
exec.WriteIn(b)
jade.ReadFunc = os.ReadFile // reset to original.
return b.String(), nil
}
return s