From 39b74e172e233250c8ab69db7fdb58bf46680988 Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Tue, 18 Jul 2017 14:20:19 -0400 Subject: [PATCH] improve local UI testing and ability for pluggable UI --- server/template/files/script.html | 9 +++++ server/template/template_gen.go | 61 +++++++++++++++++++++++-------- server/ui_local.go | 14 ++++++- 3 files changed, 67 insertions(+), 17 deletions(-) create mode 100644 server/template/files/script.html diff --git a/server/template/files/script.html b/server/template/files/script.html new file mode 100644 index 00000000..f8f2f765 --- /dev/null +++ b/server/template/files/script.html @@ -0,0 +1,9 @@ + + diff --git a/server/template/template_gen.go b/server/template/template_gen.go index 7c5d459c..33e00672 100644 --- a/server/template/template_gen.go +++ b/server/template/template_gen.go @@ -22,6 +22,9 @@ var files = []struct { }, { name: "logout.html", data: logout, + }, { + name: "script.html", + data: script, }, } @@ -63,25 +66,39 @@ var error = ` // files/index.html var index = ` - + - - - - {{ if .csrf }}{{ end }} - - - - - + + + + + + + + + + + + + + + + -
- - - + ` @@ -167,3 +184,15 @@ var login = ` // files/logout.html var logout = `LOGOUT ` + +// files/script.html +var script = ` + +` diff --git a/server/ui_local.go b/server/ui_local.go index c9eca265..9b79a69e 100644 --- a/server/ui_local.go +++ b/server/ui_local.go @@ -1,7 +1,10 @@ package server import ( + "bytes" + "io/ioutil" "net/http" + "path/filepath" "github.com/drone/drone/model" "github.com/drone/drone/server/template" @@ -49,7 +52,15 @@ func (w *local) Page(rw http.ResponseWriter, r *http.Request, u *model.User) { "csrf": csrf, } - template.T.ExecuteTemplate(rw, "index_polymer.html", params) + index, err := ioutil.ReadFile(filepath.Join(w.dir, "index.html")) + if err != nil { + rw.WriteHeader(404) + return + } + var buf bytes.Buffer + template.T.ExecuteTemplate(&buf, "script.html", params) + index = bytes.Replace(index, []byte(""), buf.Bytes(), 1) + rw.Write(index) } } @@ -64,5 +75,6 @@ func (w *local) Routes() []string { "/favicon-16x16.png", "/src/*filepath", "/bower_components/*filepath", + "/static/*filepath", } }