revel/revel — pull request #602 by mcspring (2014-05-07 09:04:53+00:00)
Title: Support template engine

This pull request introduces a `TemplateEnginer` interface for easing 3d-party template parser usage. The interface defined as following:
```go
type TemplateEnginer interface {
Parse(s string) (*template.Template, error)
SetOptions(options *config.Config)
SetHelpers(helpers template.FuncMap)
WatchDir(dir os.FileInfo) bool
WatchFile(file string) bool
}
```

It adds a new config option of template, named `template.engine`, which used to define current template parser engine.

It also includes a helper `RegisterTemplateEngine(name string, engine TemplateEnginer)`. You *MUST* register your engine before using it.

Now you can develop your template engine as below:
```go
package slim

import (
"os"
"html/template"

"github.com/revel/config"
"github.com/revel/revel"
"github.com/mcspring/slim"
)

func init() {
revel.RegisterTemplateEngine("slim", NewSlimTemplateEngine())
}

type SlimTemplateEngine struct {
driver *slim.Slim
options *config.Config
}

func (engine *SlimTemplateEngine) Parse(s string) (*template.Template, error) {
// do some slim staff
return engine.driver.Parse(s)
}

func (engine *SlimTemplateEngine) SetOptions(options *config.Config) {
engine.options = options
}

func (engine *SlimTemplateEngine) SetHelpers(helpers template.FuncMap) {
engine.driver.SetHelpers(helpers)
}

func (engine *SlimTemplateEngine) WatchDir(dir os.FileInfo) bool {
return !strings.HasPrefix(dir.Name(), ".")
}

func (engine GoTemplateEngine) WatchFile(file string) bool {
return !strings.HasPrefix(file, ".") && strings.HasSuffix(strings.ToLower(file), ".html.slim")
}
```

Then import the engine in your app and update `app.conf` by adding:
```ini
template.engine = slim
```

Enjoy yourself!