forked from maxence-charriere/go-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhtml.go
More file actions
68 lines (56 loc) · 1.34 KB
/
Copy pathhtml.go
File metadata and controls
68 lines (56 loc) · 1.34 KB
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
package app
import (
"bytes"
"text/template"
"github.com/satori/go.uuid"
)
const (
htmlContextTmpl = `
<!DOCTYPE html>
<html lang="{{if .Lang}}{{.Lang}}{{else}}en{{end}}">
<head>
<meta charset="UTF-8">
<style media="all" type="text/css">
html {
height: 100%;
width: 100%;
margin: 0;
}
body {
height: 100%;
width: 100%;
margin: 0;
font-family: "Helvetica Neue", "Segoe UI";
}
</style>
{{range .CSS}}
<link type="text/css" rel="stylesheet" href="css/{{.}}" />{{end}}
<title>{{.Title}}</title>
</head>
<body oncontextmenu="event.preventDefault()">
<div data-murlok-root="{{.ID}}"></div>
<script>{{.MurlokJS}}</script>
{{range .JS}}
<script src="js/{{.}}"></script>{{end}}
</body>
</html>
`
)
// HTMLContext contains the data required to generate the minimum HTML to
// setup a webview based context.
// Should be used only in drivers implementations.
type HTMLContext struct {
ID uuid.UUID
Title string
Lang string
MurlokJS string
JS []string
CSS []string
}
// HTML generate the HTML based on the data of c.
func (c HTMLContext) HTML() string {
var b bytes.Buffer
t := template.Must(template.New("").Parse(htmlContextTmpl))
t.Execute(&b, c)
return b.String()
}