Skip to content

Commit

Permalink
add example.
Browse files Browse the repository at this point in the history
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
  • Loading branch information
appleboy committed Dec 20, 2016
1 parent d259e38 commit d4f3e5e
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 1 deletion.
33 changes: 33 additions & 0 deletions example/example.go
@@ -0,0 +1,33 @@
package main

import (
"github.com/gin-contrib/multitemplate"

"gopkg.in/gin-gonic/gin.v1"
)

func createMyRender() multitemplate.Render {
r := multitemplate.New()
r.AddFromFiles("index", "templates/base.html", "templates/base.html")
r.AddFromFiles("article", "templates/base.html", "templates/article.html")
// r.AddFromFiles("login", "base.html", "login.html")
// r.AddFromFiles("dashboard", "base.html", "dashboard.html")

return r
}

func main() {
router := gin.Default()
router.HTMLRender = createMyRender()
router.GET("/", func(c *gin.Context) {
c.HTML(200, "index", gin.H{
"title": "Html5 Template Engine",
})
})
router.GET("/article", func(c *gin.Context) {
c.HTML(200, "index", gin.H{
"title": "Html5 Article Engine",
})
})
router.Run(":8080")
}
27 changes: 27 additions & 0 deletions example/templates/article.html
@@ -0,0 +1,27 @@
<!doctype html>
<html class="no-js" lang="">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>{{ .title }}</title>
<meta name="description" content="Html5 Template Engine">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="favicon.ico" rel="icon" type="image/x-icon" />
<link rel="stylesheet" href="assets/css/main.css">
</head>
<body>
<h1 id="header">Welcome to {{ .title }}</h1>
<h2>Features</h2>
<ul>
<li>The latest <a href="http://html5boilerplate.com/">html5boilerplate.com</a> source code.</li>
<li>Includes <a href="https://github.com/appleboy/normalize.scss">Normalize.scss</a> v2.1.x and v1.1.x.</li>
<li>The latest <a href="http://jquery.com">jQuery</a> and <a href="http://modernizr.com/">Modernizr</a> via <a href="http://bower.io/">Bower</a> package manager.</li>
<li>Support <a href="http://coffeescript.org/">CoffeeScript</a>, <a href="http://requirejs.org/">RequireJS</a>, <a href="http://compass-style.org/">Compass</a>, html minification (via <a href="http://code.google.com/p/htmlcompressor/">htmlcompressor</a>).</li>
<li>Support <a href="http://browsersync.io">browser-sync</a> Keep multiple browsers & devices in sync when building websites.</li>
<li>Support JavaScript test framework <a href="http://visionmedia.github.io/mocha/">Mocha</a>.</li>
<li>Support streaming build system <a href="http://gulpjs.com/">Gulp</a>.</li>
<li>Support <a href="http://www.html5rocks.com/en/tutorials/developertools/devtools-terminal/">Terminal in Chrome Devtools</a>.</li>
<li>Support minify PNG and JPEG images with <a href="https://github.com/sindresorhus/gulp-imagemin">image-min</a>.</li>
</ul>
</body>
</html>
27 changes: 27 additions & 0 deletions example/templates/base.html
@@ -0,0 +1,27 @@
<!doctype html>
<html class="no-js" lang="">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>{{ .title }}</title>
<meta name="description" content="Html5 Template Engine">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="favicon.ico" rel="icon" type="image/x-icon" />
<link rel="stylesheet" href="assets/css/main.css">
</head>
<body>
<h1 id="header">Welcome to {{ .title }}</h1>
<h2>Features</h2>
<ul>
<li>The latest <a href="http://html5boilerplate.com/">html5boilerplate.com</a> source code.</li>
<li>Includes <a href="https://github.com/appleboy/normalize.scss">Normalize.scss</a> v2.1.x and v1.1.x.</li>
<li>The latest <a href="http://jquery.com">jQuery</a> and <a href="http://modernizr.com/">Modernizr</a> via <a href="http://bower.io/">Bower</a> package manager.</li>
<li>Support <a href="http://coffeescript.org/">CoffeeScript</a>, <a href="http://requirejs.org/">RequireJS</a>, <a href="http://compass-style.org/">Compass</a>, html minification (via <a href="http://code.google.com/p/htmlcompressor/">htmlcompressor</a>).</li>
<li>Support <a href="http://browsersync.io">browser-sync</a> Keep multiple browsers & devices in sync when building websites.</li>
<li>Support JavaScript test framework <a href="http://visionmedia.github.io/mocha/">Mocha</a>.</li>
<li>Support streaming build system <a href="http://gulpjs.com/">Gulp</a>.</li>
<li>Support <a href="http://www.html5rocks.com/en/tutorials/developertools/devtools-terminal/">Terminal in Chrome Devtools</a>.</li>
<li>Support minify PNG and JPEG images with <a href="https://github.com/sindresorhus/gulp-imagemin">image-min</a>.</li>
</ul>
</body>
</html>
2 changes: 1 addition & 1 deletion multitemplate.go
Expand Up @@ -3,7 +3,7 @@ package multitemplate
import (
"html/template"

"gopkg.in/gin-gonic/gin.v1/render"
"github.com/gin-gonic/gin/render"
)

type Render map[string]*template.Template
Expand Down

0 comments on commit d4f3e5e

Please sign in to comment.