mirror of
https://github.com/kataras/iris.git
synced 2026-01-25 04:45:57 +00:00
20 days of unstoppable work. Waiting fo go 1.8, I didn't finish yet, some touches remains.
Former-commit-id: ed84f99c89f43fe5e980a8e6d0ee22c186f0e1b9
This commit is contained in:
48
adaptors/view/amber.go
Normal file
48
adaptors/view/amber.go
Normal file
@@ -0,0 +1,48 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user