mirror of
https://github.com/kataras/iris.git
synced 2025-03-15 17:36:29 +01:00
minor
Former-commit-id: 491a1001aff9fc63a0d79efbfee6a78ca711f07c
This commit is contained in:
parent
c55d2063e1
commit
ea589b1276
|
@ -199,6 +199,8 @@ Navigate through examples for a better understanding.
|
||||||
- [Pug (Jade) Extends`](view/template_pug_3)
|
- [Pug (Jade) Extends`](view/template_pug_3)
|
||||||
- [Jet](/view/template_jet_0)
|
- [Jet](/view/template_jet_0)
|
||||||
- [Jet Embedded](view/template_jet_1_embedded)
|
- [Jet Embedded](view/template_jet_1_embedded)
|
||||||
|
- [Jet 'urlpath' tmpl func](/view/template_jet_2)
|
||||||
|
- [Jet template funcs from structure](/view/template_jet_3)
|
||||||
|
|
||||||
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.
|
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.
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,9 @@ ENV GO111MODULE=on \
|
||||||
GOOS=linux \
|
GOOS=linux \
|
||||||
GOARCH=amd64
|
GOARCH=amd64
|
||||||
WORKDIR /go/src/app
|
WORKDIR /go/src/app
|
||||||
COPY . /go/src/app
|
COPY go.mod .
|
||||||
|
RUN go mod download
|
||||||
|
COPY . .
|
||||||
RUN go install
|
RUN go install
|
||||||
|
|
||||||
FROM scratch
|
FROM scratch
|
||||||
|
|
|
@ -4,4 +4,5 @@ go 1.13
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/kataras/iris/v12 v12.1.6
|
github.com/kataras/iris/v12 v12.1.6
|
||||||
|
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
|
||||||
)
|
)
|
||||||
|
|
55
_examples/view/template_jet_3/main.go
Normal file
55
_examples/view/template_jet_3/main.go
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"reflect"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/kataras/iris/v12"
|
||||||
|
"github.com/kataras/iris/v12/view"
|
||||||
|
)
|
||||||
|
|
||||||
|
// https://github.com/kataras/iris/issues/1443
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
|
||||||
|
tmpl := iris.Jet("./views", ".jet")
|
||||||
|
tmpl.Reload(true)
|
||||||
|
|
||||||
|
val := reflect.ValueOf(ViewBuiler{})
|
||||||
|
fns := val.Type()
|
||||||
|
for i := 0; i < fns.NumMethod(); i++ {
|
||||||
|
method := fns.Method(i)
|
||||||
|
tmpl.AddFunc(strings.ToLower(method.Name), val.Method(i).Interface())
|
||||||
|
}
|
||||||
|
|
||||||
|
app := iris.New()
|
||||||
|
app.RegisterView(tmpl)
|
||||||
|
|
||||||
|
app.Get("/", func(ctx iris.Context) {
|
||||||
|
ctx.View("index.jet")
|
||||||
|
})
|
||||||
|
|
||||||
|
app.Run(iris.Addr(":8080"))
|
||||||
|
}
|
||||||
|
|
||||||
|
type ViewBuiler struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ViewBuiler) Asset(a view.JetArguments) reflect.Value {
|
||||||
|
path := a.Get(0).String()
|
||||||
|
// fmt.Println(os.Getenv("APP_URL"))
|
||||||
|
return reflect.ValueOf(path)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ViewBuiler) Style(a view.JetArguments) reflect.Value {
|
||||||
|
path := a.Get(0).String()
|
||||||
|
s := fmt.Sprintf(`<link href="%v" rel="stylesheet"> `, path)
|
||||||
|
return reflect.ValueOf(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ViewBuiler) Script(a view.JetArguments) reflect.Value {
|
||||||
|
path := a.Get(0).String()
|
||||||
|
s := fmt.Sprintf(`<script src="%v" ></script>`, path)
|
||||||
|
return reflect.ValueOf(s)
|
||||||
|
}
|
5
_examples/view/template_jet_3/views/index.jet
Normal file
5
_examples/view/template_jet_3/views/index.jet
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
{{ asset("./myasset.mp3")}}
|
||||||
|
<br/>
|
||||||
|
{{ style("my-stle.css")}}
|
||||||
|
<br/>
|
||||||
|
{{ script("my-script.js")}}
|
Loading…
Reference in New Issue
Block a user