improve local UI testing and ability for pluggable UI

This commit is contained in:
Brad Rydzewski 2017-07-18 14:20:19 -04:00
parent c867bcaf3c
commit 39b74e172e
3 changed files with 67 additions and 17 deletions

View file

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

View file

@ -22,6 +22,9 @@ var files = []struct {
}, {
name: "logout.html",
data: logout,
}, {
name: "script.html",
data: script,
},
}
@ -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>
`
@ -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>
`

View file

@ -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("<!-- inject:js -->"), 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",
}
}