Awesome
Martini Acerender
Overview
Martini Acerender is a Martini middleware/handler for parsing Ace templates and rendering HTML.
Example
main.go
package main
import (
"github.com/go-martini/martini"
"github.com/yosssi/martini-acerender"
)
func main() {
m := martini.Classic()
m.Use(acerender.Renderer(nil))
m.Get("/", func(r acerender.Render) {
r.HTML(200, "base:inner", map[string]string{"Msg": "Hello Acerender"}, nil)
})
m.Run()
}
base.ace
= doctype html
html lang=en
head
meta charset=utf-8
meta http-equiv=Content-Type content="text/html;charset=UTF-8"
meta name=viewport content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"
title Ace example
= css
h1 { color: blue; }
body
h1 Base Template : {{.Msg}}
#container.wrapper
= yield main
= yield sub
= javascript
alert('{{.Msg}}');
inner.ace
= content main
h2 Inner Template - Main : {{.Msg}}
= content sub
h3 Inner Template - Sub : {{.Msg}}
Ace Options
You can pass the options for Ace template engine to Martini Acerender.
Options per application
You can set the Ace options per application.
package main
import (
"github.com/go-martini/martini"
"github.com/yosssi/ace"
"github.com/yosssi/martini-acerender"
)
func main() {
m := martini.Classic()
m.Use(acerender.Renderer(&acerender.Options{
AceOptions: &ace.Options{
BaseDir: "views",
},
}))
m.Get("/", func(r acerender.Render) {
r.HTML(200, "base:inner", map[string]string{"Msg": "Hello Acerender"}, nil)
})
m.Run()
}
Options per request
You can set the Ace options per request or you can override the Ace options per application with ones per request.
package main
import (
"github.com/go-martini/martini"
"github.com/yosssi/ace"
"github.com/yosssi/martini-acerender"
)
func main() {
m := martini.Classic()
m.Use(acerender.Renderer(&acerender.Options{
AceOptions: &ace.Options{
BaseDir: "views",
},
}))
m.Get("/", func(r acerender.Render) {
r.HTML(200, "base:inner", map[string]string{"Msg": "Hello Acerender"}, &ace.Options{
BaseDir: "templates",
})
})
m.Run()
}