Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve local UI testing and ability for pluggable UI #2120

Merged
merged 1 commit into from
Jul 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
improve local UI testing and ability for pluggable UI
  • Loading branch information
bradrydzewski committed Jul 18, 2017
commit 39b74e172e233250c8ab69db7fdb58bf46680988
9 changes: 9 additions & 0 deletions server/template/files/script.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

<script>
window.ENV = {};
window.ENV.server = window.location.protocol+"//"+window.location.host;
{{ if .csrf }}window.ENV.csrf = "{{ .csrf }}"{{ end }}
{{ if .user }}
window.USER = {{ json .user }};
{{ end }}
</script>
61 changes: 45 additions & 16 deletions server/template/template_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ var files = []struct {
}, {
name: "logout.html",
data: logout,
}, {
name: "script.html",
data: script,
},
}

Expand Down Expand Up @@ -63,25 +66,39 @@ var error = `<!DOCTYPE html>

// files/index.html
var index = `<!DOCTYPE html>
<html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta content="width=device-width, initial-scale=1" name="viewport"/>
<meta content="ie=edge" http-equiv="x-ua-compatible"/>
{{ if .csrf }}<meta name="csrf-token" content="{{ .csrf }}" />{{ end }}
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet"/>
<link href="https://fonts.googleapis.com/css?family=Roboto+Mono" rel="stylesheet"/>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"/>
<link href="/static/app.css" rel="stylesheet"/>
<link href="/static/favicon.ico" rel="icon" type="image/x-icon"/>
<meta charset="utf-8">
<meta name="author" content="bradrydzewski">
<meta name="viewport" content="width=device-width, minimum-scale=1, initial-scale=1, user-scalable=yes">

<link rel="shortcut icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="shortcut icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">

<title></title>
<script>
window.ENV = {};
window.ENV.server = window.location.protocol+"//"+window.location.host;
{{ if .csrf }}window.ENV.csrf = "{{ .csrf }}"{{ end }}
{{ if .user }}
window.USER = {{ json .user }};
{{ end }}
</script>
<script src="/bower_components/webcomponentsjs/webcomponents-loader.js"></script>

<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto+Mono">
<link rel="import" href="/src/drone/drone-app.html">

<style>
html, body {
padding:0px;
margin:0px;
}
</style>
</head>
<body>
<div id="app"></div>
<script>
window.STATE_FROM_SERVER={{ . | json }};
</script>
<script src="https://code.getmdl.io/1.1.3/material.min.js"></script>
<script src="/static/app.js"></script>
<drone-app></drone-app>
</body>
</html>
`
Expand Down Expand Up @@ -167,3 +184,15 @@ var login = `<!DOCTYPE html>
// files/logout.html
var logout = `LOGOUT
`

// files/script.html
var script = `
<script>
window.ENV = {};
window.ENV.server = window.location.protocol+"//"+window.location.host;
{{ if .csrf }}window.ENV.csrf = "{{ .csrf }}"{{ end }}
{{ if .user }}
window.USER = {{ json .user }};
{{ end }}
</script>
`
14 changes: 13 additions & 1 deletion server/ui_local.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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("<!-- inject:js -->"), buf.Bytes(), 1)
rw.Write(index)
}
}

Expand All @@ -64,5 +75,6 @@ func (w *local) Routes() []string {
"/favicon-16x16.png",
"/src/*filepath",
"/bower_components/*filepath",
"/static/*filepath",
}
}