// GetRenderCtx returns a RenderCtx wrapper around the current raw renderer // The wrapper automatically adds the current request ContextData to the // renderer's Render method call. func GetRenderCtx(c context.Context, r *http.Request) renderer.RenderCtx { rnd := GetRenderer(c) return renderer.RenderCtx(func(w io.Writer, data renderer.RenderData, names ...string) error { return rnd.Render(w, data, c.GetAll(r), names...) }) }
func (con App) Handler(c context.Context) http.Handler { cfg := readeef.GetConfig(c) rnd := webfw.GetRenderer(c) if cfg.Logger.Level == "debug" { rnd.SkipCache(true) } return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { action := webfw.GetMultiPatternIdentifier(c, r) data := renderer.RenderData{} if action == "history" { params := webfw.GetParams(c, r) data["history"] = "/web/" + params["history"] } if r.Method != "HEAD" { err := rnd.Render(w, data, c.GetAll(r), "app.tmpl") if err != nil { webfw.GetLogger(c).Print(err) } } w.Header().Set("X-Readeef", "1") }) }
func (con Component) Handler(c context.Context) http.Handler { mw, i18nFound := con.dispatcher.Middleware("I18N") logger := webfw.GetLogger(c) rnd := renderer.NewRenderer(con.dispatcher.Config.Renderer.Dir, "raw.tmpl") rnd.Delims("{%", "%}") if i18nFound { if i18n, ok := mw.(middleware.I18N); ok { rnd.Funcs(i18n.TemplateFuncMap()) } } else { logger.Infoln("I18N middleware not found") } return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { params := webfw.GetParams(c, r) err := rnd.Render(w, renderer.RenderData{"apiPattern": con.apiPattern}, c.GetAll(r), "components/"+params["name"]+".tmpl") if err != nil { webfw.GetLogger(c).Print(err) } }) }
func (con App) Handler(c context.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { rnd := webfw.GetRenderer(c) err := rnd.Render(w, nil, c.GetAll(r), "app.tmpl") if err != nil { webfw.GetLogger(c).Print(err) } } }
func (con Component) Handler(c context.Context) http.HandlerFunc { rnd := renderer.NewRenderer(con.dir, "raw.tmpl") rnd.Delims("{%", "%}") return func(w http.ResponseWriter, r *http.Request) { params := webfw.GetParams(c, r) err := rnd.Render(w, renderer.RenderData{"apiPattern": con.apiPattern}, c.GetAll(r), "components/"+params["name"]+".tmpl") if err != nil { webfw.GetLogger(c).Print(err) } } }
func (con App) Handler(c context.Context) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { rnd := webfw.GetRenderer(c) action := webfw.GetMultiPatternIdentifier(c, r) data := renderer.RenderData{} if action == "history" { params := webfw.GetParams(c, r) data["history"] = "/web/" + params["history"] } err := rnd.Render(w, data, c.GetAll(r), "app.tmpl") if err != nil { webfw.GetLogger(c).Print(err) } }) }
func (con Component) Handler(c context.Context) http.Handler { i18nmw, i18nFound := con.dispatcher.Middleware("I18N") urlmw, urlFound := con.dispatcher.Middleware("Url") logger := webfw.GetLogger(c) cfg := readeef.GetConfig(c) rnd := renderer.NewRenderer(con.dispatcher.Config.Renderer.Dir, "raw.tmpl") rnd.Delims("{%", "%}") if cfg.Logger.Level == "debug" { rnd.SkipCache(true) } if i18nFound { if i18n, ok := i18nmw.(middleware.I18N); ok { rnd.Funcs(i18n.TemplateFuncMap()) } } else { logger.Infoln("I18N middleware not found") } if urlFound { if url, ok := urlmw.(middleware.Url); ok { rnd.Funcs(url.TemplateFuncMap(c)) } } else { logger.Infoln("Url middleware not found") } return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { params := webfw.GetParams(c, r) if r.Method != "HEAD" { err := rnd.Render(w, renderer.RenderData{"apiPattern": con.apiPattern, "config": cfg}, c.GetAll(r), "components/"+params["name"]+".tmpl") if err != nil { webfw.GetLogger(c).Print(err) } } }) }