Contains the Concourse pipeline definition for building a line-server container
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.

87 lines
1.5 KiB

9 years ago
  1. package main
  2. import (
  3. "bytes"
  4. "io"
  5. "net/http"
  6. "path"
  7. "path/filepath"
  8. "strings"
  9. "github.com/GeertJohan/go.rice"
  10. "github.com/flosch/pongo2"
  11. )
  12. type Pongo2Loader struct {
  13. box *rice.Box
  14. }
  15. func NewPongo2TemplatesLoader() (*Pongo2Loader, error) {
  16. fs := &Pongo2Loader{}
  17. p2l, err := rice.FindBox("templates")
  18. if err != nil {
  19. return nil, err
  20. }
  21. fs.box = p2l
  22. return fs, nil
  23. }
  24. func (fs *Pongo2Loader) Get(path string) (io.Reader, error) {
  25. myBytes, err := fs.box.Bytes(path)
  26. if err != nil {
  27. return nil, err
  28. }
  29. return bytes.NewReader(myBytes), nil
  30. }
  31. func (fs *Pongo2Loader) Abs(base, name string) string {
  32. me := path.Join(filepath.Dir(base), name)
  33. return me
  34. }
  35. func populateTemplatesMap(tSet *pongo2.TemplateSet, tMap map[string]*pongo2.Template) error {
  36. templates := []string{
  37. "index.html",
  38. "paste.html",
  39. "API.html",
  40. "400.html",
  41. "401.html",
  42. "404.html",
  43. "oops.html",
  44. "display/audio.html",
  45. "display/image.html",
  46. "display/video.html",
  47. "display/pdf.html",
  48. "display/bin.html",
  49. "display/story.html",
  50. "display/md.html",
  51. "display/file.html",
  52. }
  53. for _, tName := range templates {
  54. tpl, err := tSet.FromFile(tName)
  55. if err != nil {
  56. return err
  57. }
  58. tMap[tName] = tpl
  59. }
  60. return nil
  61. }
  62. func renderTemplate(tpl *pongo2.Template, context pongo2.Context, r *http.Request, writer io.Writer) error {
  63. if Config.siteName == "" {
  64. parts := strings.Split(r.Host, ":")
  65. context["sitename"] = parts[0]
  66. }
  67. context["sitepath"] = Config.sitePath
  68. context["using_auth"] = Config.authFile != ""
  69. return tpl.ExecuteWriter(context, writer)
  70. }