1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-11 05:55:57 +00:00

Update vendor for Pug (Jade) Parser and add Iris + Pug examples in the _examples/view folder, relative to https://github.com/kataras/iris/issues/1003

Former-commit-id: e26a5701e00ec055f3bcf693c1980c7d22147310
This commit is contained in:
Gerasimos Maropoulos
2018-05-26 22:49:48 +03:00
parent 94b93484b5
commit beef97fd5d
14 changed files with 206 additions and 1 deletions

View File

@@ -0,0 +1,29 @@
package main
import "github.com/kataras/iris"
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)
// http://localhost:8080
app.Run(iris.Addr(":8080"))
}
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")
}

View File

@@ -0,0 +1,25 @@
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

View File

@@ -0,0 +1,42 @@
// 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"
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")
app.RegisterView(tmpl)
app.Get("/", index)
// http://localhost:8080
app.Run(iris.Addr(":8080"))
}
func index(ctx iris.Context) {
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

@@ -0,0 +1,20 @@
doctype html
html(lang="en")
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 }}

View File

@@ -0,0 +1,28 @@
package main
import (
"html/template"
"github.com/kataras/iris"
)
func main() {
app := iris.New()
tmpl := iris.Pug("./templates", ".pug")
tmpl.Reload(true) // reload templates on each request (development mode)
tmpl.AddFunc("bold", func(s string) (template.HTML, error) { // add your template func here.
return template.HTML("<b>" + s + "</b>"), nil
})
app.RegisterView(tmpl)
app.Get("/", index)
// http://localhost:8080
app.Run(iris.Addr(":8080"))
}
func index(ctx iris.Context) {
ctx.View("index.pug")
}

View File

@@ -0,0 +1,2 @@
#footer
p Copyright (c) foobar

View File

@@ -0,0 +1,4 @@
head
title My Site
<!-- script(src='/javascripts/jquery.js')
script(src='/javascripts/app.js') -->

View File

@@ -0,0 +1,7 @@
doctype html
html
include templates/header.pug
body
h1 My Site
p {{ bold "Welcome to my super lame site."}}
include templates/footer.pug

View File

@@ -0,0 +1,20 @@
package main
import "github.com/kataras/iris"
func main() {
app := iris.New()
tmpl := iris.Pug("./templates", ".pug")
app.RegisterView(tmpl)
app.Get("/", index)
// http://localhost:8080
app.Run(iris.Addr(":8080"))
}
func index(ctx iris.Context) {
ctx.View("index.pug")
}

View File

@@ -0,0 +1,7 @@
extends templates/layout.pug
block title
title Article Title
block content
h1 My Article

View File

@@ -0,0 +1,7 @@
doctype html
html
head
block title
title Default title
body
block content