Skip to content

Commit b363492

Browse files
committed
add 'iris.Blocks' template engine
read more about its features at: https://github.com/kataras/blocks
1 parent 6844be5 commit b363492

File tree

24 files changed

+631
-40
lines changed

24 files changed

+631
-40
lines changed

HISTORY.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,9 @@ Response:
359359

360360
Other Improvements:
361361

362-
- Add [Ace](_examples/view/template_ace_0) template parser to the view engine and other minor improvements. <!-- a new html/template-based engine, with a different layout-page syntax but better performance, follows this week. -->
362+
- Add [Blocks](_examples/view/template_blocks_0) template engine. <!-- Reminder for @kataras: follow https://github.com/flosch/pongo2/pull/236#issuecomment-668950566 discussion so we can get back on using the original pongo2 repository as they fixed the issue about an incompatible 3rd party package (although they need more fixes, that's why I commented there) -->
363+
364+
- Add [Ace](_examples/view/template_ace_0) template parser to the view engine and other minor improvements.
363365

364366
- Fix huge repo size of 55.7MB, which slows down the overall Iris installation experience. Now, go-get performs ~3 times faster. I 've managed it using the [bfg-repo-cleaner](https://github.com/rtyley/bfg-repo-cleaner) tool - an alternative to git-filter-branch command. Watch the small gif below to learn how:
365367

NOTICE

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
The following 3rd-party software packages may be used by or distributed with iris. This document was automatically generated by FOSSA on 2020-5-8; any information relevant to third-party vendors listed below are collected using common, reasonable means.
88

9-
Revision ID: d1c07411df0bb21f6b21f5b5d9325fac6f29c911
9+
Revision ID: 6844be57ea3a098ef28fce3468959bf5bb6f735a
1010

1111
----------------- ----------------- ------------------------------------------
1212
Package Version Website
@@ -20,12 +20,15 @@ Revision ID: d1c07411df0bb21f6b21f5b5d9325fac6f29c911
2020
bbolt a8af23b57f672fe https://github.com/etcd-io/bbolt
2121
f05637de531bba5
2222
aa00013364
23-
blackfriday 48b3da6a6f3865c https://github.com/iris-contrib/
24-
7eb1eba96d74cf0 blackfriday
25-
a16f63faca
26-
bluemonday 0a75d7616912ab9 https://github.com/microcosm-cc/
27-
beb9cc6f7283ec1 bluemonday
23+
blackfriday d3b5b032dc8e892 https://github.com/russross/blackfriday
24+
7d31a5071b56e14
25+
c89f045135
26+
bluemonday 0a75d7616912ab9 https://github.com/microcosm-cc/bluemonday
27+
beb9cc6f7283ec1
2828
917c61b135
29+
blocks 39dac49c58634f7 https://github.com/kataras/blocks
30+
9bc54fcd5c299da
31+
fe08dbd738
2932
brotli c3da72aa01ed78f https://github.com/andybalholm/brotli
3033
164593b9624fd91
3134
d25082d2d2
@@ -71,9 +74,9 @@ Revision ID: d1c07411df0bb21f6b21f5b5d9325fac6f29c911
7174
pio 2e3d576cc65913a https://github.com/kataras/pio
7275
dd6106f1ce02837
7376
2c7e6d943c
74-
pongo2 0738cc45f23da6a https://github.com/iris-contrib/pongo2
75-
8c14959779a75d3
76-
37b7944fb6
77+
pongo2 5abacdfa4915f8a https://github.com/flosch/pongo2
78+
fb6de6231455488
79+
066273bea6
7780
protobuf 6c66de79d66478d https://github.com/golang/protobuf
7881
166c7ea05f5d2cc
7982
af016fbd6b

_examples/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@
103103
* [Inject Data Between Handlers](view/context-view-data/main.go)
104104
* [Embedding Templates Into App Executable File](view/embedding-templates-into-app/main.go)
105105
* [Write to a custom `io.Writer`](view/write-to)
106+
* [Blocks](view/template_blocks_0)
107+
* [Blocks Embedded](view/template_blocks_1_embedded)
106108
* [Pug: Greeting](view/template_pug_0)
107109
* [Pug: `Actions`](view/template_pug_1)
108110
* [Pug: `Includes`](view/template_pug_2)

_examples/view/embedding-templates-into-app/main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ func main() {
1515

1616
// $ go get -u github.com/go-bindata/go-bindata/v3/go-bindata
1717
// $ go-bindata ./templates/...
18-
// $ go build
19-
// $ ./embedding-templates-into-app
18+
// $ go run .
2019
// html files are not used, you can delete the folder and run the example.
2120
tmpl.Binary(Asset, AssetNames) // <-- IMPORTANT
2221

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package main
2+
3+
import "github.com/kataras/iris/v12"
4+
5+
func main() {
6+
app := iris.New()
7+
// Read about its syntax at: https://github.com/kataras/blocks
8+
app.RegisterView(iris.Blocks("./views", ".html").Reload(true))
9+
10+
app.Get("/", index)
11+
app.Get("/500", internalServerError)
12+
13+
app.Listen(":8080")
14+
}
15+
16+
func index(ctx iris.Context) {
17+
data := iris.Map{
18+
"Title": "Page Title",
19+
}
20+
21+
ctx.ViewLayout("main")
22+
ctx.View("index", data)
23+
}
24+
25+
func internalServerError(ctx iris.Context) {
26+
ctx.StatusCode(iris.StatusInternalServerError)
27+
28+
data := iris.Map{
29+
"Code": iris.StatusInternalServerError,
30+
"Message": "Internal Server Error",
31+
}
32+
33+
ctx.ViewLayout("error")
34+
ctx.View("500", data)
35+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!-- You can define more than one block.
2+
The default one is "content" which should be the main template's body.
3+
So, even if it's missing (see index.html), it's added automatically by the view engine.
4+
When you need to define more than one block, you have to be more specific:
5+
-->
6+
{{ define "content" }}
7+
<h1>Internal Server Error</h1>
8+
{{ end }}
9+
10+
{{ define "message" }}
11+
<p style="color:red;">{{.Message}}</p>
12+
{{ end }}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<h1>Index Body</h1>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>{{.Code}}</title>
7+
</head>
8+
<body>
9+
{{ template "content" .}}
10+
11+
{{block "message" .}}{{end}}
12+
</body>
13+
</html>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>{{ if .Title }}{{ .Title }}{{ else }}Default Main Title{{ end }}</title>
7+
</head>
8+
<body>
9+
{{ template "content" . }}
10+
11+
<footer>{{ partial "partials/footer" .}}</footer>
12+
</body>
13+
</html>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<h3>Footer Partial</h3>

0 commit comments

Comments
 (0)