You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

39 lines
898 B

  1. package amber
  2. import (
  3. "github.com/PuerkitoBio/ghost/templates"
  4. "github.com/eknkc/amber"
  5. )
  6. // The template compiler for Amber templates.
  7. type AmberCompiler struct {
  8. Options amber.Options
  9. c *amber.Compiler
  10. }
  11. // Create a new Amber compiler with the specified Amber-specific options.
  12. func NewAmberCompiler(opts amber.Options) *AmberCompiler {
  13. return &AmberCompiler{
  14. opts,
  15. nil,
  16. }
  17. }
  18. // Implementation of the TemplateCompiler interface.
  19. func (this *AmberCompiler) Compile(f string) (templates.Templater, error) {
  20. // amber.CompileFile creates a new compiler each time. To limit the number
  21. // of allocations, reuse a compiler.
  22. if this.c == nil {
  23. this.c = amber.New()
  24. }
  25. this.c.Options = this.Options
  26. if err := this.c.ParseFile(f); err != nil {
  27. return nil, err
  28. }
  29. return this.c.Compile()
  30. }
  31. func init() {
  32. templates.Register(".amber", NewAmberCompiler(amber.DefaultOptions))
  33. }