Skip to content

Commit

Permalink
Merge pull request #68 from skx/67-inline-media
Browse files Browse the repository at this point in the history
67 inline media
  • Loading branch information
skx authored Feb 15, 2020
2 parents b11eebd + 4ea6787 commit 9eb306d
Show file tree
Hide file tree
Showing 14 changed files with 220 additions and 159 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
on: release
on:
release:
types: [created]
name: Handle Release
jobs:
upload:
name: Upload
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Upload
- name: Generate the artifacts
uses: skx/github-action-build@master
- name: Upload the artifacts
uses: skx/github-action-publish-binaries@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
92 changes: 50 additions & 42 deletions cmd_serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -831,68 +831,74 @@ func NodeHandler(res http.ResponseWriter, req *http.Request) {
// It will server an embedded binary resource.
//
func IconHandler(res http.ResponseWriter, req *http.Request) {
var (
status int
err error
)
defer func() {
if nil != err {
http.Error(res, err.Error(), status)

// Don't spam stdout when running test-cases.
if flag.Lookup("test.v") == nil {
fmt.Printf("Error: %s\n", err.Error())
}
}
}()
serveStatic(res, req, "data/favicon.ico", "image/vnd.microsoft.icon")
}

// CSSPath is the handler for all the CSS files beneath /css.
func CSSPath(res http.ResponseWriter, req *http.Request) {

//
// Get the path we're going to serve.
//
// Load the binary-asset.
vars := mux.Vars(req)
path := vars["path"]

//
data, err := getResource("data/favicon.ico")
// Ensure we received a path.
//
if len(path) < 1 {
res.WriteHeader(http.StatusNotFound)
fmt.Fprint(res, "The request you made pointed to a missing resource")
return
}

//
// Serve it
//
serveStatic(res, req, "data/css/"+path, "text/css")
}

// serveStatic serves a static path, with the given MIME type.
func serveStatic(res http.ResponseWriter, req *http.Request, path string, mime string) {

// Load the asset.
data, err := getResource(path)
if err != nil {
fmt.Fprint(res, err.Error())
res.WriteHeader(http.StatusNotFound)
fmt.Fprintf(res, "Error loading the resource you requested: %s", err.Error())
return
}

res.Header().Set("Content-Type", "image/vnd.microsoft.icon")
res.Header().Set("Content-Type", mime)
res.Write(data)
}

//
// SorterHandler is the handler for the HTTP end-point
//
// GET /jquery.tablesorter.min.js
//
// JavascriptPath is the handler for all the javascript files beneath /js.
// It will serve an embedded javascript resource.
//
func SorterHandler(res http.ResponseWriter, req *http.Request) {
var (
status int
err error
)
defer func() {
if nil != err {
http.Error(res, err.Error(), status)
func JavascriptPath(res http.ResponseWriter, req *http.Request) {

// Don't spam stdout when running test-cases.
if flag.Lookup("test.v") == nil {
fmt.Printf("Error: %s\n", err.Error())
}
}
}()
//
// Get the path we're going to serve.
//
vars := mux.Vars(req)
path := vars["path"]

//
// Load the asset.
// Ensure we received a path.
//
data, err := getResource("data/jquery.tablesorter.min.js")
if err != nil {
fmt.Fprint(res, err.Error())
if len(path) < 1 {
res.WriteHeader(http.StatusNotFound)
fmt.Fprint(res, "The request you made pointed to a missing resource")
return
}

res.Header().Set("Content-Type", "application/javascript")
res.Write(data)
//
// Serve it
//
serveStatic(res, req, "data/js/"+path, "application/javascript")
}

//
Expand Down Expand Up @@ -1082,7 +1088,9 @@ func serve(settings serveCmd) {
// Static-Files
//
router.HandleFunc("/favicon.ico", IconHandler).Methods("GET")
router.HandleFunc("/jquery.tablesorter.min.js", SorterHandler).Methods("GET")
router.HandleFunc("/js/{path}", JavascriptPath).Methods("GET")
router.HandleFunc("/css/{path}", CSSPath).Methods("GET")

//
// Bind the router.
//
Expand Down
6 changes: 6 additions & 0 deletions data/css/bootstrap.min.css

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions data/index.template
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
<meta charset="utf-8">
<link href="{{.Urlprefix }}/favicon.ico" rel="shortcut icon" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
<script src="https://code.jquery.com/jquery-1.12.4.min.js" integrity="sha384-nvAa0+6Qg9clwYCGGPpDQLVpLNn0fRaROjHqs13t4Ggj3Ez50XnGQqc/r8MhnRDZ" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.6.0/Chart.bundle.min.js"></script>
<script src="{{.Urlprefix }}/jquery.tablesorter.min.js"></script>
<link href="{{.Urlprefix }}/css/bootstrap.min.css" rel="stylesheet">
<script src="{{.Urlprefix }}/js/jquery-1.12.4.min.js"></script>
<script src="{{.Urlprefix }}/js/bootstrap.min.js"></script>
<script src="{{.Urlprefix }}/js/Chart.bundle.min.js"></script>
<script src="{{.Urlprefix }}/js/jquery.tablesorter.min.js"></script>
<script type="text/javascript">
window.onload = function () {
//
Expand Down
16 changes: 16 additions & 0 deletions data/js/Chart.bundle.min.js

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions data/js/bootstrap.min.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions data/js/jquery-1.12.4.min.js

Large diffs are not rendered by default.

File renamed without changes.
9 changes: 5 additions & 4 deletions data/node.template
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
<meta charset="utf-8">
<link href="{{.Urlprefix }}/favicon.ico" rel="shortcut icon" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
<script src="https://code.jquery.com/jquery-1.12.4.min.js" integrity="sha384-nvAa0+6Qg9clwYCGGPpDQLVpLNn0fRaROjHqs13t4Ggj3Ez50XnGQqc/r8MhnRDZ" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.6.0/Chart.bundle.min.js"></script>
<link href="{{.Urlprefix }}/css/bootstrap.min.css" rel="stylesheet">
<script src="{{.Urlprefix }}/js/jquery-1.12.4.min.js"></script>
<script src="{{.Urlprefix }}/js/bootstrap.min.js"></script>
<script src="{{.Urlprefix }}/js/Chart.bundle.min.js"></script>
<script src="{{.Urlprefix }}/js/jquery.tablesorter.min.js"></script>
<script type="text/javascript">

window.onload = function () {
Expand Down
4 changes: 2 additions & 2 deletions data/radiator.template
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<head>
<title>Radiator View</title>
<meta charset="utf-8">
<link href="{{.Urlprefix}}/favicon.ico" rel="shortcut icon" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://code.jquery.com/jquery-1.12.4.min.js" integrity="sha384-nvAa0+6Qg9clwYCGGPpDQLVpLNn0fRaROjHqs13t4Ggj3Ez50XnGQqc/r8MhnRDZ" crossorigin="anonymous"></script>
<link href="{{.Urlprefix}}/favicon.ico" rel="shortcut icon" />
<script src="{{.Urlprefix }}/js/jquery-1.12.4.min.js"></script>
<meta http-equiv="refresh" content="30; url={{.Urlprefix}}/radiator/">
<style>
html,
Expand Down
6 changes: 3 additions & 3 deletions data/report.template
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<meta charset="utf-8">
<link href="{{.Urlprefix}}/favicon.ico" rel="shortcut icon" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
<script src="https://code.jquery.com/jquery-1.12.4.min.js" integrity="sha384-nvAa0+6Qg9clwYCGGPpDQLVpLNn0fRaROjHqs13t4Ggj3Ez50XnGQqc/r8MhnRDZ" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<link href="{{.Urlprefix }}/css/bootstrap.min.css" rel="stylesheet">
<script src="{{.Urlprefix }}/js/jquery-1.12.4.min.js"></script>
<script src="{{.Urlprefix }}/js/bootstrap.min.js"></script>
</head>
<body>
<nav class="navbar navbar-default">
Expand Down
6 changes: 3 additions & 3 deletions data/results.template
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<meta charset="utf-8">
<link href="{{.Urlprefix}}/favicon.ico" rel="shortcut icon" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
<script src="https://code.jquery.com/jquery-1.12.4.min.js" integrity="sha384-nvAa0+6Qg9clwYCGGPpDQLVpLNn0fRaROjHqs13t4Ggj3Ez50XnGQqc/r8MhnRDZ" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<link href="{{.Urlprefix }}/css/bootstrap.min.css" rel="stylesheet">
<script src="{{.Urlprefix }}/js/jquery-1.12.4.min.js"></script>
<script src="{{.Urlprefix }}/js/bootstrap.min.js"></script>
</head>
<body>
<nav class="navbar navbar-default">
Expand Down
195 changes: 110 additions & 85 deletions static.go

Large diffs are not rendered by default.

15 changes: 2 additions & 13 deletions static_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
//
func TestResourceCount(t *testing.T) {
out := getResources()
if len(out) != 8 {
t.Errorf("We expected seven resources but found %d.", len(out))
if len(out) != 12 {
t.Errorf("We expected 12 resources but found %d.", len(out))
}
}

Expand Down Expand Up @@ -56,17 +56,6 @@ func TestResourceMatches(t *testing.T) {
t.Errorf("Embedded and real resources have different sizes.")
}

//
// Now test the length is the same as generated in the file.
//
for i, o := range all {
if o.Filename == entry.Filename {
if len(master) != getResources()[i].Length {
t.Errorf("Data length didn't match the generated size")
}
}
}

//
// Test the data-matches
//
Expand Down

0 comments on commit 9eb306d

Please sign in to comment.