Removes Unnecessary /render Rackage

This commit is contained in:
Brad Rydzewski 2014-06-12 14:24:06 -07:00
parent 0d340645b2
commit 316548899f
4 changed files with 8 additions and 62 deletions

View file

@ -1,4 +1,4 @@
package render package main
import ( import (
"encoding/json" "encoding/json"
@ -7,7 +7,7 @@ import (
"reflect" "reflect"
) )
var FuncMap = template.FuncMap{ var funcMap = template.FuncMap{
"__amber_add": runtime_add, "__amber_add": runtime_add,
"__amber_sub": runtime_sub, "__amber_sub": runtime_sub,
"__amber_mul": runtime_mul, "__amber_mul": runtime_mul,

View file

@ -1,10 +1,10 @@
package handler package handler
import ( import (
"io"
"net/http" "net/http"
"github.com/drone/drone/server/channel" "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/commit"
"github.com/drone/drone/server/resource/perm" "github.com/drone/drone/server/resource/perm"
"github.com/drone/drone/server/resource/repo" "github.com/drone/drone/server/resource/repo"
@ -14,16 +14,18 @@ import (
"github.com/gorilla/pat" "github.com/gorilla/pat"
) )
type Renderer func(wr io.Writer, name string, data interface{}) error
type SiteHandler struct { type SiteHandler struct {
users user.UserManager users user.UserManager
repos repo.RepoManager repos repo.RepoManager
commits commit.CommitManager commits commit.CommitManager
perms perm.PermManager perms perm.PermManager
sess session.Session 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} return &SiteHandler{users, repos, commits, perms, sess, render}
} }

View file

@ -13,7 +13,6 @@ import (
"github.com/drone/drone/server/database" "github.com/drone/drone/server/database"
"github.com/drone/drone/server/handler" "github.com/drone/drone/server/handler"
"github.com/drone/drone/server/queue" "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/commit"
"github.com/drone/drone/server/resource/config" "github.com/drone/drone/server/resource/config"
"github.com/drone/drone/server/resource/perm" "github.com/drone/drone/server/resource/perm"
@ -84,7 +83,7 @@ func main() {
templateBox := rice.MustFindBox("template/html") 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"} 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 { for _, file := range templateFiles {
templateData, _ := templateBox.String(file) templateData, _ := templateBox.String(file)
templ, _ = templ.New(file).Parse(templateData) templ, _ = templ.New(file).Parse(templateData)

View file

@ -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)
}