-
Notifications
You must be signed in to change notification settings - Fork 4
/
script.go
70 lines (58 loc) · 2.33 KB
/
script.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Play with generating entire body from html/template in frontend.
package main
import (
"bytes"
"html/template"
"log"
"honnef.co/go/js/dom"
)
var document = dom.GetWindow().Document().(dom.HTMLDocument)
func main() {}
func init() {
document.AddEventListener("DOMContentLoaded", false, func(_ dom.Event) {
go setup()
})
}
func setup() {
var data = struct {
Packages [10]string // Index 0 is the top (most recently viewed Go package).
Production bool
}{
Packages: [10]string{"package 1", "package 2", "package 3", 9: "package 10"},
Production: false,
}
var buf bytes.Buffer
err := t.Execute(&buf, data)
if err != nil {
log.Println("executing template:", err)
}
document.Body().SetInnerHTML(buf.String())
//document.Head().SetInnerHTML("<title>Title</title>") // Doing this gets rid of this script.
}
var t = template.Must(template.New("").Funcs(template.FuncMap{}).Parse(`{{define "GA"}}{{end}}
{{define "header"}}
<div class="header" style="width: 100%; background-color: hsl(209, 51%, 92%); font-size: 14px;">
<span style="margin-left: 30px; padding: 15px; display: inline-block;"><strong><a class="black" href="/">Go Tools</a></strong></span>
</div>
{{end}}
{{define "footer"}}
<div style="position: absolute; bottom: 0; left: 0; width: 100%; text-align: right; background-color: hsl(209, 51%, 92%);">
<span style="margin-right: 15px; padding: 15px; display: inline-block;"><a href="https://github.com/shurcooL/gtdo/issues" target="_blank">Report an issue</a></span>
</div>
{{end}}
<div style="position: relative; min-height: 100%;">
{{template "header"}}
<div style="padding-bottom: 50px;">
<article style="padding: 30px;">
<p>There's one tool. It lets you view the source code of any Go package.</p>
<span class="import-path-container" style="background-color: #f2f2f2; padding: 20px; display: inline-block;">
<input id="import-path" placeholder="import/path" autofocus onkeydown="if (event.keyCode != 13) { return; }; window.location = "/" + document.getElementById("import-path").value;">
<button onclick="window.location = "/" + document.getElementById("import-path").value;">Go</button>
</span>
<h3>Recently Viewed Packages</h3>
<ul>{{range .Packages}}<li><a href="/{{.}}"><code>{{.}}</code></a></li>{{end}}</ul>
</article>
</div>
{{template "footer"}}
</div>
`))