Skip to content

Commit ea589b1

Browse files
committed
minor
Former-commit-id: 491a1001aff9fc63a0d79efbfee6a78ca711f07c
1 parent c55d206 commit ea589b1

File tree

5 files changed

+66
-1
lines changed

5 files changed

+66
-1
lines changed

_examples/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ Navigate through examples for a better understanding.
199199
- [Pug (Jade) Extends`](view/template_pug_3)
200200
- [Jet](/view/template_jet_0)
201201
- [Jet Embedded](view/template_jet_1_embedded)
202+
- [Jet 'urlpath' tmpl func](/view/template_jet_2)
203+
- [Jet template funcs from structure](/view/template_jet_3)
202204

203205
You can serve [quicktemplate](https://github.com/valyala/quicktemplate) and [hero templates](https://github.com/shiyanhui/hero/hero) files too, simply by using the `context#ResponseWriter`, take a look at the [http_responsewriter/quicktemplate](http_responsewriter/quicktemplate) and [http_responsewriter/herotemplate](http_responsewriter/herotemplate) examples.
204206

_examples/docker/Dockerfile

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ ENV GO111MODULE=on \
77
GOOS=linux \
88
GOARCH=amd64
99
WORKDIR /go/src/app
10-
COPY . /go/src/app
10+
COPY go.mod .
11+
RUN go mod download
12+
COPY . .
1113
RUN go install
1214

1315
FROM scratch

_examples/docker/go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ go 1.13
44

55
require (
66
github.com/kataras/iris/v12 v12.1.6
7+
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
78
)

_examples/view/template_jet_3/main.go

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"reflect"
6+
"strings"
7+
8+
"github.com/kataras/iris/v12"
9+
"github.com/kataras/iris/v12/view"
10+
)
11+
12+
// https://github.com/kataras/iris/issues/1443
13+
14+
func main() {
15+
16+
tmpl := iris.Jet("./views", ".jet")
17+
tmpl.Reload(true)
18+
19+
val := reflect.ValueOf(ViewBuiler{})
20+
fns := val.Type()
21+
for i := 0; i < fns.NumMethod(); i++ {
22+
method := fns.Method(i)
23+
tmpl.AddFunc(strings.ToLower(method.Name), val.Method(i).Interface())
24+
}
25+
26+
app := iris.New()
27+
app.RegisterView(tmpl)
28+
29+
app.Get("/", func(ctx iris.Context) {
30+
ctx.View("index.jet")
31+
})
32+
33+
app.Run(iris.Addr(":8080"))
34+
}
35+
36+
type ViewBuiler struct {
37+
}
38+
39+
func (ViewBuiler) Asset(a view.JetArguments) reflect.Value {
40+
path := a.Get(0).String()
41+
// fmt.Println(os.Getenv("APP_URL"))
42+
return reflect.ValueOf(path)
43+
}
44+
45+
func (ViewBuiler) Style(a view.JetArguments) reflect.Value {
46+
path := a.Get(0).String()
47+
s := fmt.Sprintf(`<link href="%v" rel="stylesheet"> `, path)
48+
return reflect.ValueOf(s)
49+
}
50+
51+
func (ViewBuiler) Script(a view.JetArguments) reflect.Value {
52+
path := a.Get(0).String()
53+
s := fmt.Sprintf(`<script src="%v" ></script>`, path)
54+
return reflect.ValueOf(s)
55+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{{ asset("./myasset.mp3")}}
2+
<br/>
3+
{{ style("my-stle.css")}}
4+
<br/>
5+
{{ script("my-script.js")}}

0 commit comments

Comments
 (0)