app.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Package complete uses all of the modules: feed, news, profile
  2. // /feed - package feed
  3. // /news - package news
  4. // /profile - package profile
  5. // /assets - static http files from bindata
  6. package complete
  7. import (
  8. "html/template"
  9. "net/http"
  10. "github.com/cryptix/go/http/render"
  11. "github.com/gorilla/mux"
  12. "gopkg.in/errgo.v1"
  13. "github.com/cryptix/exp/multiModulePage"
  14. "github.com/cryptix/exp/multiModulePage/feed"
  15. "github.com/cryptix/exp/multiModulePage/router"
  16. )
  17. // Handler creates a full fledged http handler for the TIS Daemon app
  18. func Handler(m *mux.Router) (http.Handler, error) {
  19. if m == nil {
  20. m = router.CompleteApp()
  21. }
  22. r, err := render.New(multiModulePage.Assets,
  23. render.BaseTemplates("/complete/base.tmpl"),
  24. render.AddTemplates(append(feed.HTMLTemplates,
  25. "/complete/index.tmpl",
  26. "/complete/about.tmpl",
  27. "/error.tmpl")...),
  28. render.FuncMap(template.FuncMap{
  29. "urlTo": multiModulePage.NewURLTo(m),
  30. }),
  31. )
  32. if err != nil {
  33. return nil, errgo.Notef(err, "complete.Handler: failed to create renderer")
  34. }
  35. // javascript, images, ...
  36. // m.PathPrefix("/assets/").Handler(http.StripPrefix("/assets/", http.FileServer(assets)))
  37. m.PathPrefix("/feed").Handler(http.StripPrefix("/feed", feed.Handler(m, r)))
  38. // m.PathPrefix("/news").Handler(http.StripPrefix("/news", news.Handler(m)))
  39. // m.PathPrefix("/profile").Handler(http.StripPrefix("/profile", profile.Handler(m)))
  40. m.Get(router.CompleteIndex).Handler(r.StaticHTML("/complete/index.tmpl"))
  41. m.Get(router.CompleteAbout).Handler(r.StaticHTML("/complete/about.tmpl"))
  42. return m, nil
  43. }