diff --git a/server/render/amber.go b/server/amber.go similarity index 99% rename from server/render/amber.go rename to server/amber.go index 348e90068..415d5bd46 100644 --- a/server/render/amber.go +++ b/server/amber.go @@ -1,4 +1,4 @@ -package render +package main import ( "encoding/json" @@ -7,7 +7,7 @@ import ( "reflect" ) -var FuncMap = template.FuncMap{ +var funcMap = template.FuncMap{ "__amber_add": runtime_add, "__amber_sub": runtime_sub, "__amber_mul": runtime_mul, diff --git a/server/handler/site.go b/server/handler/site.go index 393abd95d..fb6a9a091 100644 --- a/server/handler/site.go +++ b/server/handler/site.go @@ -1,10 +1,10 @@ package handler import ( + "io" "net/http" "github.com/drone/drone/server/channel" - "github.com/drone/drone/server/render" "github.com/drone/drone/server/resource/commit" "github.com/drone/drone/server/resource/perm" "github.com/drone/drone/server/resource/repo" @@ -14,16 +14,18 @@ import ( "github.com/gorilla/pat" ) +type Renderer func(wr io.Writer, name string, data interface{}) error + type SiteHandler struct { users user.UserManager repos repo.RepoManager commits commit.CommitManager perms perm.PermManager sess session.Session - render render.Render + render Renderer } -func NewSiteHandler(users user.UserManager, repos repo.RepoManager, commits commit.CommitManager, perms perm.PermManager, sess session.Session, render render.Render) *SiteHandler { +func NewSiteHandler(users user.UserManager, repos repo.RepoManager, commits commit.CommitManager, perms perm.PermManager, sess session.Session, render Renderer) *SiteHandler { return &SiteHandler{users, repos, commits, perms, sess, render} } diff --git a/server/main.go b/server/main.go index ce47b3d90..ed9a6e24e 100644 --- a/server/main.go +++ b/server/main.go @@ -13,7 +13,6 @@ import ( "github.com/drone/drone/server/database" "github.com/drone/drone/server/handler" "github.com/drone/drone/server/queue" - "github.com/drone/drone/server/render" "github.com/drone/drone/server/resource/commit" "github.com/drone/drone/server/resource/config" "github.com/drone/drone/server/resource/perm" @@ -84,7 +83,7 @@ func main() { templateBox := rice.MustFindBox("template/html") templateFiles := []string{"login.html", "repo_branch.html", "repo_commit.html", "repo_conf.html", "repo_feed.html", "user_conf.html", "user_feed.html", "user_login.html", "user_repos.html", "404.html", "400.html"} - templ := template.New("_").Funcs(render.FuncMap) + templ := template.New("_").Funcs(funcMap) for _, file := range templateFiles { templateData, _ := templateBox.String(file) templ, _ = templ.New(file).Parse(templateData) diff --git a/server/render/render.go b/server/render/render.go deleted file mode 100644 index 1ca7cb689..000000000 --- a/server/render/render.go +++ /dev/null @@ -1,55 +0,0 @@ -package render - -import ( - "html/template" - "io" - "net/http" -) - -// Render applies the template that has the given name to the specified data -// object and writes the output to wr. -type Render func(wr io.Writer, name string, data interface{}) error - -type Renderer interface { - // HTML renders the named HTML template - HTML(wr io.Writer, name string, data interface{}) error - - // NotFound renders the 404 HTML template. It also writes the - // appropriate response status if io.Writer is of type http.ResponseWriter. - NotFound(wr io.Writer, data interface{}) error - - // NotAuthorized renders the 401 HTML template. It also writes the - // appropriate response status if io.Writer is of type http.ResponseWriter. - NotAuthorized(wr io.Writer, data interface{}) error -} - -type renderer struct { - *template.Template -} - -func NewRenderer(t *template.Template) Renderer { - return &renderer{t} -} - -// HTML renders the named HTML template -func (r *renderer) HTML(w io.Writer, name string, data interface{}) error { - return r.ExecuteTemplate(w, name, data) -} - -// NotFound renders the 404 HTML template. It also writes the -// appropriate response status if io.Writer is of type http.ResponseWriter. -func (r *renderer) NotFound(w io.Writer, data interface{}) error { - if rw, ok := w.(http.ResponseWriter); !ok { - rw.WriteHeader(http.StatusNotFound) - } - return r.HTML(w, "404.html", data) -} - -// NotAuthorized renders the 401 HTML template. It also writes the -// appropriate response status if io.Writer is of type http.ResponseWriter. -func (r *renderer) NotAuthorized(w io.Writer, data interface{}) error { - if rw, ok := w.(http.ResponseWriter); !ok { - rw.WriteHeader(http.StatusUnauthorized) - } - return r.HTML(w, "401.html", data) -}