Skip to content

Commit

Permalink
Add minimal styling
Browse files Browse the repository at this point in the history
  • Loading branch information
abhinav committed Jan 3, 2019
1 parent fa1cf19 commit 086cdf8
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 27 deletions.
1 change: 1 addition & 0 deletions Dockerfile.scratch
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ FROM scratch
EXPOSE 8080
ADD sally.yaml /
ADD _tmp/sally /
ADD templates /templates
ENTRYPOINT ["/sally"]
39 changes: 12 additions & 27 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ import (
"github.com/julienschmidt/httprouter"
)

var indexTemplate, packageTemplate *template.Template

func init() {
tmpls := template.Must(template.ParseGlob("templates/*.html"))
if indexTemplate = tmpls.Lookup("index.html"); indexTemplate == nil {
panic("Missing index.html template")
}
if packageTemplate = tmpls.Lookup("package.html"); packageTemplate == nil {
panic("Missing package.html template")
}
}

// CreateHandler creates a Sally http.Handler
func CreateHandler(config *Config) http.Handler {
router := httprouter.New()
Expand Down Expand Up @@ -38,19 +50,6 @@ func (h indexHandler) Handle(w http.ResponseWriter, r *http.Request, _ httproute
}
}

var indexTemplate = template.Must(template.New("index").Parse(`
<!DOCTYPE html>
<html>
<body>
<ul>
{{ range $key, $value := .Packages }}
<li>{{ $key }} - {{ $value.Repo }}</li>
{{ end }}
</ul>
</body>
</html>
`))

type packageHandler struct {
pkgName string
pkg Package
Expand All @@ -72,17 +71,3 @@ func (h packageHandler) Handle(w http.ResponseWriter, r *http.Request, ps httpro
http.Error(w, err.Error(), 500)
}
}

var packageTemplate = template.Must(template.New("package").Parse(`
<!DOCTYPE html>
<html>
<head>
<meta name="go-import" content="{{ .CanonicalURL }} git https://{{ .Repo }}">
<meta name="go-source" content="{{ .CanonicalURL }} https://{{ .Repo }} https://{{ .Repo }}/tree/master{/dir} https://{{ .Repo }}/tree/master{/dir}/{file}#L{line}">
<meta http-equiv="refresh" content="0; url={{ .GodocURL }}">
</head>
<body>
Nothing to see here. Please <a href="{{ .GodocURL }}">move along</a>.
</body>
</html>
`))
37 changes: 37 additions & 0 deletions templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/skeleton/2.0.4/skeleton.min.css" />
</head>
<body>
<div class="container">
<div class="row">
<table class="u-full-width">
<thead>
<tr>
<th>Package</th>
<th>Source</th>
<th>Documentation</th>
</tr>
</thead>
<tbody>
{{ range $key, $value := .Packages }}
{{ $importPath := printf "%v/%v" $.URL $key }}
<tr>
<td>{{ $importPath }}</td>
<td>
<a href="//{{ $value.Repo }}">{{ $value.Repo }}</a>
</td>
<td>
<a href="//godoc.org/{{ $importPath }}">
<img src="//godoc.org/{{ $importPath }}?status.svg" alt="GoDoc" />
</a>
</td>
</tr>
{{ end }}
</tbody>
</table>
</div>
</div>
</body>
</html>
11 changes: 11 additions & 0 deletions templates/package.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<meta name="go-import" content="{{ .CanonicalURL }} git https://{{ .Repo }}">
<meta name="go-source" content="{{ .CanonicalURL }} https://{{ .Repo }} https://{{ .Repo }}/tree/master{/dir} https://{{ .Repo }}/tree/master{/dir}/{file}#L{line}">
<meta http-equiv="refresh" content="0; url={{ .GodocURL }}">
</head>
<body>
Nothing to see here. Please <a href="{{ .GodocURL }}">move along</a>.
</body>
</html>

0 comments on commit 086cdf8

Please sign in to comment.