mirror of
https://github.com/kataras/iris.git
synced 2026-01-08 12:31:58 +00:00
add a simple hero template example as requested at https://github.com/kataras/iris/issues/840
Former-commit-id: 1c65190d21a5febbbbad1b2b565f82f749278d48
This commit is contained in:
11
_examples/http_responsewriter/hero/template/index.html
Normal file
11
_examples/http_responsewriter/hero/template/index.html
Normal file
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<%@ body { %>
|
||||
<% } %>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,3 @@
|
||||
// Code generated by hero.
|
||||
// DO NOT EDIT!
|
||||
package template
|
||||
3
_examples/http_responsewriter/hero/template/user.html
Normal file
3
_examples/http_responsewriter/hero/template/user.html
Normal file
@@ -0,0 +1,3 @@
|
||||
<li>
|
||||
<%= user %>
|
||||
</li>
|
||||
3
_examples/http_responsewriter/hero/template/user.html.go
Normal file
3
_examples/http_responsewriter/hero/template/user.html.go
Normal file
@@ -0,0 +1,3 @@
|
||||
// Code generated by hero.
|
||||
// DO NOT EDIT!
|
||||
package template
|
||||
11
_examples/http_responsewriter/hero/template/userlist.html
Normal file
11
_examples/http_responsewriter/hero/template/userlist.html
Normal file
@@ -0,0 +1,11 @@
|
||||
<%: func UserList(userList []string, buffer *bytes.Buffer) %>
|
||||
|
||||
<%~ "index.html" %>
|
||||
|
||||
<%@ body { %>
|
||||
<% for _, user := range userList { %>
|
||||
<ul>
|
||||
<%+ "user.html" %>
|
||||
</ul>
|
||||
<% } %>
|
||||
<% } %>
|
||||
41
_examples/http_responsewriter/hero/template/userlist.html.go
Normal file
41
_examples/http_responsewriter/hero/template/userlist.html.go
Normal file
@@ -0,0 +1,41 @@
|
||||
// Code generated by hero.
|
||||
// DO NOT EDIT!
|
||||
package template
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
"github.com/shiyanhui/hero"
|
||||
)
|
||||
|
||||
func UserList(userList []string, buffer *bytes.Buffer) {
|
||||
buffer.WriteString(`<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
`)
|
||||
for _, user := range userList {
|
||||
buffer.WriteString(`
|
||||
<ul>
|
||||
`)
|
||||
buffer.WriteString(`<li>
|
||||
`)
|
||||
hero.EscapeHTML(user, buffer)
|
||||
buffer.WriteString(`
|
||||
</li>
|
||||
`)
|
||||
|
||||
buffer.WriteString(`
|
||||
</ul>
|
||||
`)
|
||||
}
|
||||
|
||||
buffer.WriteString(`
|
||||
</body>
|
||||
</html>
|
||||
`)
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<%: func UserListToWriter(userList []string, w io.Writer) (int, error)%>
|
||||
|
||||
<%~ "index.html" %>
|
||||
|
||||
<%@ body { %>
|
||||
<% for _, user := range userList { %>
|
||||
<ul>
|
||||
<%+ "user.html" %>
|
||||
</ul>
|
||||
<% } %>
|
||||
<% } %>
|
||||
@@ -0,0 +1,44 @@
|
||||
// Code generated by hero.
|
||||
// DO NOT EDIT!
|
||||
package template
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
"github.com/shiyanhui/hero"
|
||||
)
|
||||
|
||||
func UserListToWriter(userList []string, w io.Writer) (int, error) {
|
||||
_buffer := hero.GetBuffer()
|
||||
defer hero.PutBuffer(_buffer)
|
||||
_buffer.WriteString(`<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
`)
|
||||
for _, user := range userList {
|
||||
_buffer.WriteString(`
|
||||
<ul>
|
||||
`)
|
||||
_buffer.WriteString(`<li>
|
||||
`)
|
||||
hero.EscapeHTML(user, _buffer)
|
||||
_buffer.WriteString(`
|
||||
</li>
|
||||
`)
|
||||
|
||||
_buffer.WriteString(`
|
||||
</ul>
|
||||
`)
|
||||
}
|
||||
|
||||
_buffer.WriteString(`
|
||||
</body>
|
||||
</html>
|
||||
`)
|
||||
return w.Write(_buffer.Bytes())
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user