view.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package context
  2. import (
  3. "fmt"
  4. "io"
  5. )
  6. // ErrViewNotExist it's an error.
  7. // It reports whether a template was not found in the parsed templates tree.
  8. type ErrViewNotExist struct {
  9. Name string
  10. IsLayout bool
  11. Data interface{}
  12. }
  13. // Error completes the `error` interface.
  14. func (e ErrViewNotExist) Error() string {
  15. title := "template"
  16. if e.IsLayout {
  17. title = "layout"
  18. }
  19. return fmt.Sprintf("%s '%s' does not exist", title, e.Name)
  20. }
  21. // ViewEngine is the interface which all view engines should be implemented in order to be registered inside iris.
  22. type ViewEngine interface {
  23. // Name returns the name of the engine.
  24. Name() string
  25. // Load should load the templates from the given FileSystem.
  26. Load() error
  27. // ExecuteWriter should execute a template by its filename with an optional layout and bindingData.
  28. ExecuteWriter(w io.Writer, filename string, layout string, bindingData interface{}) error
  29. // Ext should return the final file extension (including the dot)
  30. // which this view engine is responsible to render.
  31. // If the filename extension on ExecuteWriter is empty then this is appended.
  32. Ext() string
  33. }
  34. // ViewEngineFuncer is an addition of a view engine,
  35. // if a view engine implements that interface
  36. // then iris can add some closed-relative iris functions
  37. // like {{ url }}, {{ urlpath }} and {{ tr }}.
  38. type ViewEngineFuncer interface {
  39. // AddFunc should adds a function to the template's function map.
  40. AddFunc(funcName string, funcBody interface{})
  41. }