2020-02-08 12:41:09 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"reflect"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/kataras/iris/v12"
|
|
|
|
"github.com/kataras/iris/v12/view"
|
|
|
|
)
|
|
|
|
|
|
|
|
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) {
|
2022-12-13 00:37:15 +01:00
|
|
|
if err := ctx.View("index.jet"); err != nil {
|
|
|
|
ctx.HTML("<h3>%s</h3>", err.Error())
|
|
|
|
return
|
|
|
|
}
|
2020-02-08 12:41:09 +01:00
|
|
|
})
|
|
|
|
|
2020-03-05 21:41:27 +01:00
|
|
|
app.Listen(":8080")
|
2020-02-08 12:41:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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()
|
2020-09-05 07:34:09 +02:00
|
|
|
s := fmt.Sprintf(`<link href="%v" rel="stylesheet">`, path)
|
2020-02-08 12:41:09 +01:00
|
|
|
return reflect.ValueOf(s)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ViewBuiler) Script(a view.JetArguments) reflect.Value {
|
|
|
|
path := a.Get(0).String()
|
2020-09-05 07:34:09 +02:00
|
|
|
s := fmt.Sprintf(`<script src="%v"></script>`, path)
|
2020-02-08 12:41:09 +01:00
|
|
|
return reflect.ValueOf(s)
|
|
|
|
}
|