mirror of
https://github.com/kataras/iris.git
synced 2025-02-02 15:30:36 +01:00
Update jet parser to v4.0.0 as requested at: #1551
Former-commit-id: 1ad89532d11716af7a49fe9aafca59e943d98ebe
This commit is contained in:
parent
38b0a796bd
commit
87e08dbddc
|
@ -371,6 +371,11 @@ Other Improvements:
|
||||||
|
|
||||||
![DBUG routes](https://iris-go.com/images/v12.2.0-dbug2.png?v=0)
|
![DBUG routes](https://iris-go.com/images/v12.2.0-dbug2.png?v=0)
|
||||||
|
|
||||||
|
- Update jet parser to v4.0.0, closes [#1551](https://github.com/kataras/iris/issues/1551). It contains two breaking changes by its author:
|
||||||
|
- Relative paths on `extends, import, include...` tmpl functions, e.g. `{{extends "../layouts/application.jet"}}` instead of `layouts/application.jet`
|
||||||
|
- the new [jet.Ranger](https://github.com/CloudyKit/jet/pull/165) interface now requires a `ProvidesIndex() bool` method too
|
||||||
|
- Example has been [updated](https://github.com/kataras/iris/tree/master/_examples/view/template_jet_0)
|
||||||
|
|
||||||
- Fix [#1552](https://github.com/kataras/iris/issues/1552).
|
- Fix [#1552](https://github.com/kataras/iris/issues/1552).
|
||||||
|
|
||||||
- Proper listing of root directories on `Party.HandleDir` when its `DirOptions.ShowList` was set to true.
|
- Proper listing of root directories on `Party.HandleDir` when its `DirOptions.ShowList` was set to true.
|
||||||
|
|
|
@ -49,6 +49,9 @@ func (dt *doneTODOs) Range() (reflect.Value, reflect.Value, bool) {
|
||||||
return reflect.Value{}, reflect.Value{}, true
|
return reflect.Value{}, reflect.Value{}, true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Note: jet version 4 requires this.
|
||||||
|
func (dt *doneTODOs) ProvidesIndex() bool { return true }
|
||||||
|
|
||||||
func (dt *doneTODOs) Render(r *view.JetRuntime) {
|
func (dt *doneTODOs) Render(r *view.JetRuntime) {
|
||||||
r.Write([]byte(fmt.Sprintf("custom renderer")))
|
r.Write([]byte(fmt.Sprintf("custom renderer")))
|
||||||
}
|
}
|
||||||
|
@ -73,11 +76,6 @@ func main() {
|
||||||
// from middlewares as well, by:
|
// from middlewares as well, by:
|
||||||
// view.AddJetRuntimeVars(ctx, vars)
|
// view.AddJetRuntimeVars(ctx, vars)
|
||||||
// or tmpl.AddRuntimeVars(ctx, vars)
|
// or tmpl.AddRuntimeVars(ctx, vars)
|
||||||
//
|
|
||||||
// The Iris Jet fixes the issue when custom jet.Ranger and custom jet.Renderer are not actually work at all,
|
|
||||||
// hope that this is a temp issue on the jet parser itself and authors will fix it soon
|
|
||||||
// so we can remove the "hacks" we've putted for those to work as expected.
|
|
||||||
|
|
||||||
app := iris.New()
|
app := iris.New()
|
||||||
tmpl := iris.Jet("./views", ".jet") // <--
|
tmpl := iris.Jet("./views", ".jet") // <--
|
||||||
tmpl.Reload(true) // remove in production.
|
tmpl.Reload(true) // remove in production.
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
{{extends "layouts/application.jet"}}
|
{{extends "../layouts/application.jet"}}
|
||||||
|
|
||||||
{{block button(label, href="javascript:void(0)")}}
|
{{block button(label, href="javascript:void(0)")}}
|
||||||
<a href="{{ href }}">{{ label }}</a>
|
<a href="{{ href }}">{{ label }}</a>
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
{{extends "layouts/application.jet"}}
|
{{extends "../layouts/application.jet"}}
|
||||||
|
|
||||||
{{block documentBody()}}
|
{{block documentBody()}}
|
||||||
<h1>Show TODO</h1>
|
<h1>Show TODO</h1>
|
||||||
<p>This uses a custom renderer by implementing the jet.Renderer (or view.JetRenderer) interface.
|
<p>This uses a custom renderer by implementing the Renderer interface.
|
||||||
<p>
|
<p>
|
||||||
{{.}}
|
{{.}}
|
||||||
</p>
|
</p>
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
// Code generated by go-bindata. DO NOT EDIT.
|
// Code generated by go-bindata. DO NOT EDIT.
|
||||||
// sources:
|
// sources:
|
||||||
// views\includes\_partial.jet
|
// views/includes/_partial.jet
|
||||||
// views\includes\blocks.jet
|
// views/includes/blocks.jet
|
||||||
// views\index.jet
|
// views/index.jet
|
||||||
// views\layouts\application.jet
|
// views/layouts/application.jet
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -41,12 +40,7 @@ func bindataRead(data []byte, name string) ([]byte, error) {
|
||||||
|
|
||||||
type asset struct {
|
type asset struct {
|
||||||
bytes []byte
|
bytes []byte
|
||||||
info fileInfoEx
|
info os.FileInfo
|
||||||
}
|
|
||||||
|
|
||||||
type fileInfoEx interface {
|
|
||||||
os.FileInfo
|
|
||||||
MD5Checksum() string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type bindataFileInfo struct {
|
type bindataFileInfo struct {
|
||||||
|
@ -54,7 +48,6 @@ type bindataFileInfo struct {
|
||||||
size int64
|
size int64
|
||||||
mode os.FileMode
|
mode os.FileMode
|
||||||
modTime time.Time
|
modTime time.Time
|
||||||
md5checksum string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fi bindataFileInfo) Name() string {
|
func (fi bindataFileInfo) Name() string {
|
||||||
|
@ -69,9 +62,6 @@ func (fi bindataFileInfo) Mode() os.FileMode {
|
||||||
func (fi bindataFileInfo) ModTime() time.Time {
|
func (fi bindataFileInfo) ModTime() time.Time {
|
||||||
return fi.modTime
|
return fi.modTime
|
||||||
}
|
}
|
||||||
func (fi bindataFileInfo) MD5Checksum() string {
|
|
||||||
return fi.md5checksum
|
|
||||||
}
|
|
||||||
func (fi bindataFileInfo) IsDir() bool {
|
func (fi bindataFileInfo) IsDir() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -79,143 +69,89 @@ func (fi bindataFileInfo) Sys() interface{} {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _bindataViewsincludespartialjet = []byte(
|
var _viewsIncludes_partialJet = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xb2\x29\xb0\xf3\xcc\x4b\xce\x29\x4d\x49\x4d\x51\x28\x48\x2c\x2a\xc9\x4c\xcc\xb1\xd1\x2f\xb0\xe3\xe5\x02\x04\x00\x00\xff\xff\x90\x62\x4f\xfb\x19\x00\x00\x00")
|
||||||
"\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xb2\x29\xb0\xf3\xcc\x4b\xce\x29\x4d\x49\x4d\x51\x28\x48\x2c\x2a\xc9\x4c" +
|
|
||||||
"\xcc\xb1\xd1\x2f\xb0\xe3\x02\x04\x00\x00\xff\xff\xd0\x10\x20\x0a\x18\x00\x00\x00")
|
|
||||||
|
|
||||||
func bindataViewsincludespartialjetBytes() ([]byte, error) {
|
func viewsIncludes_partialJetBytes() ([]byte, error) {
|
||||||
return bindataRead(
|
return bindataRead(
|
||||||
_bindataViewsincludespartialjet,
|
_viewsIncludes_partialJet,
|
||||||
"views/includes/_partial.jet",
|
"views/includes/_partial.jet",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func bindataViewsincludespartialjet() (*asset, error) {
|
func viewsIncludes_partialJet() (*asset, error) {
|
||||||
bytes, err := bindataViewsincludespartialjetBytes()
|
bytes, err := viewsIncludes_partialJetBytes()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
info := bindataFileInfo{
|
info := bindataFileInfo{name: "views/includes/_partial.jet", size: 25, mode: os.FileMode(438), modTime: time.Unix(1565946441, 0)}
|
||||||
name: "views/includes/_partial.jet",
|
|
||||||
size: 24,
|
|
||||||
md5checksum: "",
|
|
||||||
mode: os.FileMode(438),
|
|
||||||
modTime: time.Unix(1533831061, 0),
|
|
||||||
}
|
|
||||||
|
|
||||||
a := &asset{bytes: bytes, info: info}
|
a := &asset{bytes: bytes, info: info}
|
||||||
|
|
||||||
return a, nil
|
return a, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _bindataViewsincludesblocksjet = []byte(
|
var _viewsIncludesBlocksJet = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xaa\xae\x4e\xca\xc9\x4f\xce\x56\xc8\x4d\xcd\x2b\xd5\xd0\xac\xad\xe5\xe5\x52\x50\xb0\x29\xb0\x0b\xc9\x48\x05\x0b\x29\x40\x64\xcb\x13\x8b\x15\x32\xf3\xca\xf2\xb3\x53\x53\xf4\x6c\xf4\x0b\xec\x78\xb9\xaa\xab\x53\xf3\x52\x40\xca\x01\x01\x00\x00\xff\xff\xa0\xd9\xd9\x5d\x41\x00\x00\x00")
|
||||||
"\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xaa\xae\x4e\xca\xc9\x4f\xce\x56\xc8\x4d\xcd\x2b\xd5\xd0\xac\xad\xe5\x52" +
|
|
||||||
"\x50\xb0\x29\xb0\x0b\xc9\x48\x05\x8b\x28\x40\x24\xcb\x13\x8b\x15\x32\xf3\xca\xf2\xb3\x53\x53\xf4\x6c\xf4\x0b\xec" +
|
|
||||||
"\xb8\xaa\xab\x53\xf3\x52\x6a\x6b\xb9\x00\x01\x00\x00\xff\xff\x3f\xde\x27\x27\x3e\x00\x00\x00")
|
|
||||||
|
|
||||||
func bindataViewsincludesblocksjetBytes() ([]byte, error) {
|
func viewsIncludesBlocksJetBytes() ([]byte, error) {
|
||||||
return bindataRead(
|
return bindataRead(
|
||||||
_bindataViewsincludesblocksjet,
|
_viewsIncludesBlocksJet,
|
||||||
"views/includes/blocks.jet",
|
"views/includes/blocks.jet",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func bindataViewsincludesblocksjet() (*asset, error) {
|
func viewsIncludesBlocksJet() (*asset, error) {
|
||||||
bytes, err := bindataViewsincludesblocksjetBytes()
|
bytes, err := viewsIncludesBlocksJetBytes()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
info := bindataFileInfo{
|
info := bindataFileInfo{name: "views/includes/blocks.jet", size: 65, mode: os.FileMode(438), modTime: time.Unix(1565946441, 0)}
|
||||||
name: "views/includes/blocks.jet",
|
|
||||||
size: 62,
|
|
||||||
md5checksum: "",
|
|
||||||
mode: os.FileMode(438),
|
|
||||||
modTime: time.Unix(1533831061, 0),
|
|
||||||
}
|
|
||||||
|
|
||||||
a := &asset{bytes: bytes, info: info}
|
a := &asset{bytes: bytes, info: info}
|
||||||
|
|
||||||
return a, nil
|
return a, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _bindataViewsindexjet = []byte(
|
var _viewsIndexJet = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x64\x90\xb1\x6a\xf3\x30\x14\x85\xf7\x1f\xfe\x77\x38\xf5\xd2\x74\xa9\xc9\x5a\x8c\x87\x42\x86\x2e\x5d\xfa\x00\x45\xb6\x6e\xb0\x1a\x59\x57\xf8\x5e\xd7\x36\x22\xef\x5e\x2c\x9b\x10\xda\xed\x48\xe7\x3b\xe8\x43\x29\xd1\xac\x14\xac\xa0\xf0\x66\xe1\x51\xa5\x34\x31\x7a\xd7\x1a\x75\x1c\x9e\xbf\x48\x8b\xeb\xf5\xff\xbf\x94\x5c\x1f\x79\x50\x14\x2e\xb4\x7e\xb4\x24\x65\xe3\xb9\xbd\xc8\x8d\x58\x99\x7c\x05\xcb\xed\xd8\x53\xd0\x57\xb6\xcb\xe1\x69\xed\x80\xaa\x3b\xd6\xa7\xbe\x21\x6b\xc9\x82\x66\xd3\x47\x4f\x55\xd9\x1d\xeb\x75\x08\x54\xc1\x7c\xd7\x6b\x00\x52\x5a\x1c\x79\x8b\x9e\xc2\x78\x5b\x97\x5b\xbf\xe6\x94\x76\x83\x3b\x95\xcf\x68\x06\x75\xc6\xdf\xc9\x64\xf0\x8c\x87\x9d\x79\x3b\x9f\x66\x27\x2a\x87\xc2\x32\xc9\x3b\x6b\x3e\x66\x7e\x7f\x03\xa8\x62\xfd\xd1\xf1\x24\xe8\x78\xfa\x33\xc4\xc4\xc3\x45\x5e\xf0\x7b\x8e\xc9\x08\x02\x2b\x76\xde\xa2\xa1\xd6\x8c\x42\x70\x9a\xe1\xf0\xa8\xa0\x4c\x57\x65\xac\x37\x31\x0a\x76\xfb\xd4\x3d\xfc\x04\x00\x00\xff\xff\x28\x5a\x9d\x42\x85\x01\x00\x00")
|
||||||
"\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x64\x90\xb1\x6e\xf3\x30\x0c\x84\x77\x3d\xc5\xfd\x5e\xfe\x74\xa9\x91\xb5" +
|
|
||||||
"\x30\x3c\x14\xc8\xd0\xa5\x4b\x1f\xa0\x50\x2c\x06\x56\x23\x8b\x42\x48\xd7\x36\x04\xbf\x7b\x11\xc5\x29\x8a\x76\x22" +
|
|
||||||
"\xc8\xfb\x8e\x3c\x30\x67\x9a\x95\xa2\x13\x54\xc1\x2e\x3c\xaa\xd4\x36\xa5\xe0\x3b\xab\x9e\xe3\xe3\x07\x69\xb5\xae" +
|
|
||||||
"\x26\x67\x3f\x24\xbe\x28\x2a\x1f\xbb\x30\x3a\x92\xfa\x18\xb8\x3b\xcb\x1d\x30\x39\x97\x01\x1c\x77\xe3\x40\x51\x9f" +
|
|
||||||
"\xd9\x2d\xbb\x87\x75\x35\x40\xd3\xef\xdb\xc3\x70\x24\xe7\xc8\x81\x66\x3b\xa4\x40\x4d\xdd\xef\x5b\x73\x15\xa3\xfd" +
|
|
||||||
"\x6c\x0d\x00\xe4\xbc\x78\x0a\x0e\x03\xc5\xf1\xee\xac\x8b\x6a\xae\xe2\x76\xf8\x47\x82\xf7\x64\x2f\xea\x6d\xf8\xce" +
|
|
||||||
"\x50\xb0\x13\xfe\x6d\xc4\xcb\xe9\x30\x7b\x51\xd9\x55\x8e\x49\x5e\x59\x4b\x5b\xe8\xdb\x7a\xa0\x49\xed\x5b\xcf\x93" +
|
|
||||||
"\xa0\xe7\xe9\x8f\x0f\x13\x5f\xce\xf2\x84\xdf\x6e\x4c\x56\x10\x59\xb1\xf1\x0e\x47\xea\xec\x28\x04\xaf\x05\x8e\xff" +
|
|
||||||
"\x15\x54\xe8\xa6\x4e\x6d\x89\x45\xd1\x95\x37\xde\xea\x57\x00\x00\x00\xff\xff\xff\xe0\x1f\xae\x75\x01\x00\x00")
|
|
||||||
|
|
||||||
func bindataViewsindexjetBytes() ([]byte, error) {
|
func viewsIndexJetBytes() ([]byte, error) {
|
||||||
return bindataRead(
|
return bindataRead(
|
||||||
_bindataViewsindexjet,
|
_viewsIndexJet,
|
||||||
"views/index.jet",
|
"views/index.jet",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func bindataViewsindexjet() (*asset, error) {
|
func viewsIndexJet() (*asset, error) {
|
||||||
bytes, err := bindataViewsindexjetBytes()
|
bytes, err := viewsIndexJetBytes()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
info := bindataFileInfo{
|
info := bindataFileInfo{name: "views/index.jet", size: 389, mode: os.FileMode(438), modTime: time.Unix(1594059793, 0)}
|
||||||
name: "views/index.jet",
|
|
||||||
size: 373,
|
|
||||||
md5checksum: "",
|
|
||||||
mode: os.FileMode(438),
|
|
||||||
modTime: time.Unix(1561227802, 0),
|
|
||||||
}
|
|
||||||
|
|
||||||
a := &asset{bytes: bytes, info: info}
|
a := &asset{bytes: bytes, info: info}
|
||||||
|
|
||||||
return a, nil
|
return a, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _bindataViewslayoutsapplicationjet = []byte(
|
var _viewsLayoutsApplicationJet = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x3c\x8e\xbd\xae\xc2\x30\x0c\x85\xf7\x4a\x7d\x07\xdf\x4c\x97\x01\x75\x65\x70\x3b\x00\x65\x85\xa1\x0c\x8c\x69\x6d\x11\x44\x7e\x10\x18\x89\x2a\xca\xbb\x23\xda\xc0\x64\xcb\x3e\xdf\xa7\x83\x7f\xdb\xfd\xa6\x3b\x1d\x5a\x30\xe2\x6c\x53\x16\xf8\x99\x60\xb5\x3f\xd7\x8a\xbd\x6a\xca\x02\x00\x0d\x6b\x9a\x36\x00\x74\x2c\x1a\x06\xa3\xef\x0f\x96\x5a\x1d\xbb\xdd\x72\xa5\xbe\x3f\xb9\x88\xe5\xa6\x75\x3d\x13\x31\x01\xbf\xb4\xbb\x59\xc6\x6a\xbe\x4f\xaa\xea\xe7\xc2\x3e\xd0\x98\xc9\x18\x7b\x1b\x86\x2b\x50\x18\x9e\x8e\xbd\xac\x03\x8d\xff\x8b\x94\x62\x64\x4f\x29\xcd\x64\xce\x63\x95\xab\xbe\x03\x00\x00\xff\xff\xee\xc2\x94\xa4\xbc\x00\x00\x00")
|
||||||
"\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x34\x8e\xbd\xae\xc2\x30\x0c\x85\xf7\x3e\x85\x6f\xa6\xcb\x80\xba\x32\xb8" +
|
|
||||||
"\x1d\x80\xb2\xc2\x50\x06\xc6\x34\xb6\x08\x22\x3f\x08\x8c\x44\x15\xe5\xdd\x51\x08\x4c\xb6\xec\xf3\x7d\x3a\xf8\xb7" +
|
|
||||||
"\xdd\x6f\xc6\xd3\x61\x00\x2b\xde\xf5\x0d\x96\x01\x4e\x87\x73\xa7\x38\xa8\xbe\x01\x40\xcb\x9a\xca\x02\x80\x9e\x45" +
|
|
||||||
"\x83\xb1\xfa\xfe\x60\xe9\xd4\x71\xdc\x2d\x57\xea\xfb\x92\x8b\x38\xee\x07\x3f\x31\x11\x13\xf0\x4b\xfb\x9b\x63\x6c" +
|
|
||||||
"\xeb\xbd\x78\xda\x9f\x08\xa7\x48\x73\xc5\x52\x9a\x5c\x34\x57\xa0\x68\x9e\x9e\x83\xac\x23\xcd\xff\x8b\x9c\x53\xe2" +
|
|
||||||
"\x40\x39\x7f\xb0\x9a\xc6\xb6\x36\x7c\x07\x00\x00\xff\xff\x76\x86\x91\x20\xb2\x00\x00\x00")
|
|
||||||
|
|
||||||
func bindataViewslayoutsapplicationjetBytes() ([]byte, error) {
|
func viewsLayoutsApplicationJetBytes() ([]byte, error) {
|
||||||
return bindataRead(
|
return bindataRead(
|
||||||
_bindataViewslayoutsapplicationjet,
|
_viewsLayoutsApplicationJet,
|
||||||
"views/layouts/application.jet",
|
"views/layouts/application.jet",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func bindataViewslayoutsapplicationjet() (*asset, error) {
|
func viewsLayoutsApplicationJet() (*asset, error) {
|
||||||
bytes, err := bindataViewslayoutsapplicationjetBytes()
|
bytes, err := viewsLayoutsApplicationJetBytes()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
info := bindataFileInfo{
|
info := bindataFileInfo{name: "views/layouts/application.jet", size: 188, mode: os.FileMode(438), modTime: time.Unix(1565946441, 0)}
|
||||||
name: "views/layouts/application.jet",
|
|
||||||
size: 178,
|
|
||||||
md5checksum: "",
|
|
||||||
mode: os.FileMode(438),
|
|
||||||
modTime: time.Unix(1561227776, 0),
|
|
||||||
}
|
|
||||||
|
|
||||||
a := &asset{bytes: bytes, info: info}
|
a := &asset{bytes: bytes, info: info}
|
||||||
|
|
||||||
return a, nil
|
return a, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
// Asset loads and returns the asset for the given name.
|
// Asset loads and returns the asset for the given name.
|
||||||
// It returns an error if the asset could not be found or
|
// It returns an error if the asset could not be found or
|
||||||
// could not be loaded.
|
// could not be loaded.
|
||||||
//
|
|
||||||
func Asset(name string) ([]byte, error) {
|
func Asset(name string) ([]byte, error) {
|
||||||
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
||||||
if f, ok := _bindata[cannonicalName]; ok {
|
if f, ok := _bindata[cannonicalName]; ok {
|
||||||
|
@ -225,14 +161,11 @@ func Asset(name string) ([]byte, error) {
|
||||||
}
|
}
|
||||||
return a.bytes, nil
|
return a.bytes, nil
|
||||||
}
|
}
|
||||||
return nil, &os.PathError{Op: "open", Path: name, Err: os.ErrNotExist}
|
return nil, fmt.Errorf("Asset %s not found", name)
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
// MustAsset is like Asset but panics when Asset would return an error.
|
// MustAsset is like Asset but panics when Asset would return an error.
|
||||||
// It simplifies safe initialization of global variables.
|
// It simplifies safe initialization of global variables.
|
||||||
// nolint: deadcode
|
|
||||||
//
|
|
||||||
func MustAsset(name string) []byte {
|
func MustAsset(name string) []byte {
|
||||||
a, err := Asset(name)
|
a, err := Asset(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -242,10 +175,9 @@ func MustAsset(name string) []byte {
|
||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
// AssetInfo loads and returns the asset info for the given name.
|
// AssetInfo loads and returns the asset info for the given name.
|
||||||
// It returns an error if the asset could not be found or could not be loaded.
|
// It returns an error if the asset could not be found or
|
||||||
//
|
// could not be loaded.
|
||||||
func AssetInfo(name string) (os.FileInfo, error) {
|
func AssetInfo(name string) (os.FileInfo, error) {
|
||||||
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
||||||
if f, ok := _bindata[cannonicalName]; ok {
|
if f, ok := _bindata[cannonicalName]; ok {
|
||||||
|
@ -255,13 +187,10 @@ func AssetInfo(name string) (os.FileInfo, error) {
|
||||||
}
|
}
|
||||||
return a.info, nil
|
return a.info, nil
|
||||||
}
|
}
|
||||||
return nil, &os.PathError{Op: "open", Path: name, Err: os.ErrNotExist}
|
return nil, fmt.Errorf("AssetInfo %s not found", name)
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
// AssetNames returns the names of the assets.
|
// AssetNames returns the names of the assets.
|
||||||
// nolint: deadcode
|
|
||||||
//
|
|
||||||
func AssetNames() []string {
|
func AssetNames() []string {
|
||||||
names := make([]string, 0, len(_bindata))
|
names := make([]string, 0, len(_bindata))
|
||||||
for name := range _bindata {
|
for name := range _bindata {
|
||||||
|
@ -270,17 +199,14 @@ func AssetNames() []string {
|
||||||
return names
|
return names
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
// _bindata is a table, holding each asset generator, mapped to its name.
|
// _bindata is a table, holding each asset generator, mapped to its name.
|
||||||
//
|
|
||||||
var _bindata = map[string]func() (*asset, error){
|
var _bindata = map[string]func() (*asset, error){
|
||||||
"views/includes/_partial.jet": bindataViewsincludespartialjet,
|
"views/includes/_partial.jet": viewsIncludes_partialJet,
|
||||||
"views/includes/blocks.jet": bindataViewsincludesblocksjet,
|
"views/includes/blocks.jet": viewsIncludesBlocksJet,
|
||||||
"views/index.jet": bindataViewsindexjet,
|
"views/index.jet": viewsIndexJet,
|
||||||
"views/layouts/application.jet": bindataViewslayoutsapplicationjet,
|
"views/layouts/application.jet": viewsLayoutsApplicationJet,
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
// AssetDir returns the file names below a certain
|
// AssetDir returns the file names below a certain
|
||||||
// directory embedded in the file by go-bindata.
|
// directory embedded in the file by go-bindata.
|
||||||
// For example if you run go-bindata on data/... and data contains the
|
// For example if you run go-bindata on data/... and data contains the
|
||||||
|
@ -294,7 +220,6 @@ var _bindata = map[string]func() (*asset, error){
|
||||||
// AssetDir("data/img") would return []string{"a.png", "b.png"}
|
// AssetDir("data/img") would return []string{"a.png", "b.png"}
|
||||||
// AssetDir("foo.txt") and AssetDir("notexist") would return an error
|
// AssetDir("foo.txt") and AssetDir("notexist") would return an error
|
||||||
// AssetDir("") will return []string{"data"}.
|
// AssetDir("") will return []string{"data"}.
|
||||||
//
|
|
||||||
func AssetDir(name string) ([]string, error) {
|
func AssetDir(name string) ([]string, error) {
|
||||||
node := _bintree
|
node := _bintree
|
||||||
if len(name) != 0 {
|
if len(name) != 0 {
|
||||||
|
@ -303,20 +228,12 @@ func AssetDir(name string) ([]string, error) {
|
||||||
for _, p := range pathList {
|
for _, p := range pathList {
|
||||||
node = node.Children[p]
|
node = node.Children[p]
|
||||||
if node == nil {
|
if node == nil {
|
||||||
return nil, &os.PathError{
|
return nil, fmt.Errorf("Asset %s not found", name)
|
||||||
Op: "open",
|
|
||||||
Path: name,
|
|
||||||
Err: os.ErrNotExist,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if node.Func != nil {
|
if node.Func != nil {
|
||||||
return nil, &os.PathError{
|
return nil, fmt.Errorf("Asset %s not found", name)
|
||||||
Op: "open",
|
|
||||||
Path: name,
|
|
||||||
Err: os.ErrNotExist,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
rv := make([]string, 0, len(node.Children))
|
rv := make([]string, 0, len(node.Children))
|
||||||
for childName := range node.Children {
|
for childName := range node.Children {
|
||||||
|
@ -329,16 +246,15 @@ type bintree struct {
|
||||||
Func func() (*asset, error)
|
Func func() (*asset, error)
|
||||||
Children map[string]*bintree
|
Children map[string]*bintree
|
||||||
}
|
}
|
||||||
|
var _bintree = &bintree{nil, map[string]*bintree{
|
||||||
var _bintree = &bintree{Func: nil, Children: map[string]*bintree{
|
"views": &bintree{nil, map[string]*bintree{
|
||||||
"views": {Func: nil, Children: map[string]*bintree{
|
"includes": &bintree{nil, map[string]*bintree{
|
||||||
"includes": {Func: nil, Children: map[string]*bintree{
|
"_partial.jet": &bintree{viewsIncludes_partialJet, map[string]*bintree{}},
|
||||||
"_partial.jet": {Func: bindataViewsincludespartialjet, Children: map[string]*bintree{}},
|
"blocks.jet": &bintree{viewsIncludesBlocksJet, map[string]*bintree{}},
|
||||||
"blocks.jet": {Func: bindataViewsincludesblocksjet, Children: map[string]*bintree{}},
|
|
||||||
}},
|
}},
|
||||||
"index.jet": {Func: bindataViewsindexjet, Children: map[string]*bintree{}},
|
"index.jet": &bintree{viewsIndexJet, map[string]*bintree{}},
|
||||||
"layouts": {Func: nil, Children: map[string]*bintree{
|
"layouts": &bintree{nil, map[string]*bintree{
|
||||||
"application.jet": {Func: bindataViewslayoutsapplicationjet, Children: map[string]*bintree{}},
|
"application.jet": &bintree{viewsLayoutsApplicationJet, map[string]*bintree{}},
|
||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
}}
|
}}
|
||||||
|
@ -361,7 +277,11 @@ func RestoreAsset(dir, name string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime())
|
err = os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// RestoreAssets restores an asset under the given directory recursively
|
// RestoreAssets restores an asset under the given directory recursively
|
||||||
|
@ -385,3 +305,4 @@ func _filePath(dir, name string) string {
|
||||||
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
||||||
return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...)
|
return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ import (
|
||||||
|
|
||||||
// $ go get -u github.com/go-bindata/go-bindata/...
|
// $ go get -u github.com/go-bindata/go-bindata/...
|
||||||
// $ go-bindata ./views/...
|
// $ go-bindata ./views/...
|
||||||
// $ go build
|
// $ go run .
|
||||||
func main() {
|
func main() {
|
||||||
app := iris.New()
|
app := iris.New()
|
||||||
tmpl := iris.Jet("./views", ".jet").Binary(Asset, AssetNames)
|
tmpl := iris.Jet("./views", ".jet").Binary(Asset, AssetNames)
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -4,7 +4,7 @@ go 1.14
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/BurntSushi/toml v0.3.1
|
github.com/BurntSushi/toml v0.3.1
|
||||||
github.com/CloudyKit/jet/v3 v3.0.0
|
github.com/CloudyKit/jet/v4 v4.0.0
|
||||||
github.com/Shopify/goreferrer v0.0.0-20181106222321-ec9c9a553398
|
github.com/Shopify/goreferrer v0.0.0-20181106222321-ec9c9a553398
|
||||||
github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible
|
github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible
|
||||||
github.com/dgraph-io/badger/v2 v2.0.3
|
github.com/dgraph-io/badger/v2 v2.0.3
|
||||||
|
|
36
view/jet.go
36
view/jet.go
|
@ -5,12 +5,13 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/kataras/iris/v12/context"
|
"github.com/kataras/iris/v12/context"
|
||||||
|
|
||||||
"github.com/CloudyKit/jet/v3"
|
"github.com/CloudyKit/jet/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
const jetEngineName = "jet"
|
const jetEngineName = "jet"
|
||||||
|
@ -32,7 +33,7 @@ type JetEngine struct {
|
||||||
// If AddFunc or AddVar called before `Load` then these will be set here to be used via `Load` and clear.
|
// If AddFunc or AddVar called before `Load` then these will be set here to be used via `Load` and clear.
|
||||||
vars map[string]interface{}
|
vars map[string]interface{}
|
||||||
|
|
||||||
jetRangerRendererContextKey string
|
jetDataContextKey string
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ Engine = (*JetEngine)(nil)
|
var _ Engine = (*JetEngine)(nil)
|
||||||
|
@ -67,7 +68,7 @@ func Jet(directory, extension string) *JetEngine {
|
||||||
directory: directory,
|
directory: directory,
|
||||||
extension: extension,
|
extension: extension,
|
||||||
loader: jet.NewOSFileSystemLoader(directory),
|
loader: jet.NewOSFileSystemLoader(directory),
|
||||||
jetRangerRendererContextKey: "_jet",
|
jetDataContextKey: "_jet",
|
||||||
}
|
}
|
||||||
|
|
||||||
return s
|
return s
|
||||||
|
@ -269,7 +270,7 @@ func (f *embeddedFile) Read(p []byte) (int, error) {
|
||||||
|
|
||||||
// Open opens a file from OS file system.
|
// Open opens a file from OS file system.
|
||||||
func (l *embeddedLoader) Open(name string) (io.ReadCloser, error) {
|
func (l *embeddedLoader) Open(name string) (io.ReadCloser, error) {
|
||||||
// name = path.Join(l.vdir, name)
|
name = path.Join(l.vdir, filepath.ToSlash(name))
|
||||||
contents, err := l.asset(name)
|
contents, err := l.asset(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -282,9 +283,10 @@ func (l *embeddedLoader) Open(name string) (io.ReadCloser, error) {
|
||||||
// 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
|
// returns string with the full path of the template and bool true if the template file was found
|
||||||
func (l *embeddedLoader) Exists(name string) (string, bool) {
|
func (l *embeddedLoader) Exists(name string) (string, bool) {
|
||||||
fileName := path.Join(l.vdir, name)
|
name = path.Join(l.vdir, filepath.ToSlash(name))
|
||||||
if _, ok := l.names[fileName]; ok {
|
|
||||||
return fileName, true
|
if _, ok := l.names[name]; ok {
|
||||||
|
return name, true
|
||||||
}
|
}
|
||||||
|
|
||||||
return "", false
|
return "", false
|
||||||
|
@ -368,6 +370,21 @@ func (s *JetEngine) ExecuteWriter(w io.Writer, filename string, layout string, b
|
||||||
vars = jetVars
|
vars = jetVars
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if v := ctx.Values().Get(s.jetDataContextKey); v != nil {
|
||||||
|
if bindingData == nil {
|
||||||
|
// if bindingData is nil, try to fill them by context key (a middleware can set data).
|
||||||
|
bindingData = v
|
||||||
|
} else if m, ok := bindingData.(context.Map); ok {
|
||||||
|
// else if bindingData are passed to App/Context.View
|
||||||
|
// and it's map try to fill with the new values passed from a middleware.
|
||||||
|
if mv, ok := v.(context.Map); ok {
|
||||||
|
for key, value := range mv {
|
||||||
|
m[key] = value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if bindingData == nil {
|
if bindingData == nil {
|
||||||
|
@ -378,10 +395,11 @@ func (s *JetEngine) ExecuteWriter(w io.Writer, filename string, layout string, b
|
||||||
vars = make(JetRuntimeVars)
|
vars = make(JetRuntimeVars)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* fixed on jet v4.0.0, so no need of this:
|
||||||
if m, ok := bindingData.(context.Map); ok {
|
if m, ok := bindingData.(context.Map); ok {
|
||||||
var jetData interface{}
|
var jetData interface{}
|
||||||
for k, v := range m {
|
for k, v := range m {
|
||||||
if k == s.jetRangerRendererContextKey {
|
if k == s.jetDataContextKey {
|
||||||
jetData = v
|
jetData = v
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -396,7 +414,7 @@ func (s *JetEngine) ExecuteWriter(w io.Writer, filename string, layout string, b
|
||||||
if jetData != nil {
|
if jetData != nil {
|
||||||
bindingData = jetData
|
bindingData = jetData
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
return tmpl.Execute(w, vars, bindingData)
|
return tmpl.Execute(w, vars, bindingData)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user