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:
23
view/pug.go
23
view/pug.go
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user