1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-23 11:56:00 +00:00

Full support of the http.FileSystem on all view engines as requested at #1575

Also, the HandleDir accepts both string and http.FileSystem (interface{}) (like the view's fs)
This commit is contained in:
Gerasimos (Makis) Maropoulos
2020-09-05 08:34:09 +03:00
parent 7e6d453dad
commit e1f25eb098
50 changed files with 1613 additions and 1226 deletions

View File

@@ -2,9 +2,6 @@ package view
import (
"bytes"
"io/ioutil"
"path"
"strings"
"github.com/iris-contrib/jade"
)
@@ -16,26 +13,23 @@ import (
//
// Read more about the Jade Go Parser: https://github.com/Joker/jade
//
// Usage:
// Pug("./views", ".pug") or
// Pug(iris.Dir("./views"), ".pug") or
// Pug(AssetFile(), ".pug") for embedded data.
//
// Examples:
// https://github.com/kataras/iris/tree/master/_examples/view/template_pug_0
// https://github.com/kataras/iris/tree/master/_examples/view/template_pug_1
// https://github.com/kataras/iris/tree/master/_examples/view/template_pug_2
// https://github.com/kataras/iris/tree/master/_examples/view/template_pug_3
func Pug(directory, extension string) *HTMLEngine {
s := HTML(directory, extension)
func Pug(fs interface{}, extension string) *HTMLEngine {
s := HTML(fs, extension)
s.middleware = func(name string, text []byte) (contents string, err error) {
name = path.Join(path.Clean(directory), name)
tmpl := jade.New(name)
tmpl.ReadFunc = func(name string) ([]byte, error) {
if !strings.HasPrefix(path.Clean(name), path.Clean(directory)) {
name = path.Join(directory, name)
}
if s.assetFn != nil {
return s.assetFn(name)
}
return ioutil.ReadFile(name)
return asset(s.fs, name)
}
// Fixes: https://github.com/kataras/iris/issues/1450
@@ -43,7 +37,6 @@ func Pug(directory, extension string) *HTMLEngine {
// 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.
exec, err := tmpl.Parse(text)
if err != nil {
return