iris/adaptors/view/amber.go
Gerasimos (Makis) Maropoulos 244a59e055 20 days of unstoppable work. Waiting fo go 1.8, I didn't finish yet, some touches remains.
Former-commit-id: ed84f99c89f43fe5e980a8e6d0ee22c186f0e1b9
2017-02-14 05:54:11 +02:00

49 lines
1.5 KiB
Go

package view
import (
"github.com/kataras/go-template/amber"
)
// AmberAdaptor is the adaptor for the Amber, simple, engine.
// Read more about the Amber Go Template at:
// https://github.com/eknkc/amber
// and https://github.com/kataras/go-template/tree/master/amber
type AmberAdaptor struct {
*Adaptor
engine *amber.Engine
}
// Amber returns a new kataras/go-template/amber template engine
// with the same features as all iris' view engines have:
// Binary assets load (templates inside your executable with .go extension)
// Layout, Funcs, {{ url }} {{ urlpath}} for reverse routing and much more.
//
// Read more: https://github.com/eknkc/amber
func Amber(directory string, extension string) *AmberAdaptor {
e := amber.New()
return &AmberAdaptor{
Adaptor: NewAdaptor(directory, extension, e),
engine: e,
}
}
// Funcs adds the elements of the argument map to the template's function map.
// It is legal to overwrite elements of the default actions:
// - url func(routeName string, args ...string) string
// - urlpath func(routeName string, args ...string) string
// - render func(fullPartialName string) (template.HTML, error).
func (a *AmberAdaptor) Funcs(funcMap map[string]interface{}) *AmberAdaptor {
if len(funcMap) == 0 {
return a
}
// configuration maps are never nil, because
// they are initialized at each of the engine's New func
// so we're just passing them inside it.
for k, v := range funcMap {
a.engine.Config.Funcs[k] = v
}
return a
}