1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-07 12:07:28 +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:
Gerasimos (Makis) Maropoulos
2020-09-05 08:34:09 +03:00
parent 7e6d453dad
commit e1f25eb098
50 changed files with 1613 additions and 1226 deletions

View File

@@ -1,16 +1,24 @@
// Package main shows an example of pug actions based on https://github.com/Joker/jade/tree/master/example/actions
package main
import "github.com/kataras/iris/v12"
type Person struct {
Name string
Age int
Emails []string
Jobs []*Job
}
type Job struct {
Employer string
Role string
}
func main() {
app := iris.New()
tmpl := iris.Pug("./templates", ".pug")
tmpl.Reload(true) // reload templates on each request (development mode)
tmpl.AddFunc("greet", func(s string) string { // add your template func here.
return "Greetings " + s + "!"
})
app.RegisterView(tmpl)
app.Get("/", index)
@@ -20,9 +28,15 @@ func main() {
}
func index(ctx iris.Context) {
ctx.ViewData("pageTitle", "My Index Page")
ctx.ViewData("youAreUsingJade", true)
// Q: why need extension .pug?
// A: Because you can register more than one view engine per Iris application.
ctx.View("index.pug")
job1 := Job{Employer: "Monash B", Role: "Honorary"}
job2 := Job{Employer: "Box Hill", Role: "Head of HE"}
person := Person{
Name: "jan",
Age: 50,
Emails: []string{"jan@newmarch.name", "jan.newmarch@gmail.com"},
Jobs: []*Job{&job1, &job2},
}
ctx.View("index.pug", person)
}

View File

@@ -1,25 +1,20 @@
mixin withGo
| Generating Go html/template output.
doctype html
html(lang="en")
head
title= .pageTitle
script(type='text/javascript').
if (foo) {
bar(1 + 5)
}
body
h1 Jade - template engine
#container.col
if .youAreUsingJade
p {{ greet "iris user" }} <!-- execute template funcs -->
p You are amazing!
else
p Get on it!
p.
Jade is #[a(terse)] and simple
templating language with a
#[strong focus] on performance
and powerful features.
+ withGo
head
meta(charset="utf-8")
title Title
body
p ads
ul
li The name is {{.Name}}.
li The age is {{.Age}}.
each _,_ in .Emails
div An email is {{.}}
| {{ with .Jobs }}
each _,_ in .
div
An employer is {{.Employer}}
and the role is {{.Role}}
| {{ end }}