-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathembed.go
More file actions
47 lines (37 loc) · 1.24 KB
/
embed.go
File metadata and controls
47 lines (37 loc) · 1.24 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
package main
import (
_ "embed"
"strings"
)
//go:embed ui/index.html
var indexHTML string
//go:embed ui/styles.css
var stylesCSS string
//go:embed ui/views/graph.css
var graphCSS string
//go:embed ui/app.js
var appJS string
//go:embed ui/views/plan.js
var planJS string
//go:embed ui/views/graph.js
var graphJS string
// htmlContent is the final inlined HTML served to the WebView.
// We assemble it once at startup: the source HTML uses three placeholder
// comments (/*__STYLES__*/, /*__APP_JS__*/, /*__VIEWS_JS__*/) that the
// runtime fills in with the embedded CSS and JS contents. The split keeps
// the dev experience modular while still shipping a single self-contained
// document — no file:// or http server needed.
var htmlContent string
func init() {
// To add a new view: drop ui/views/<name>.js (+ optional .css), embed
// them here, and concatenate into viewsJS / cssContent below. The view
// file must end with registerView('name', renderFn) and may also call
// registerKeyHandler / registerInfoUpdater.
cssContent := stylesCSS + "\n\n" + graphCSS
viewsJS := planJS + "\n\n" + graphJS
htmlContent = strings.NewReplacer(
"/*__STYLES__*/", cssContent,
"/*__APP_JS__*/", appJS,
"/*__VIEWS_JS__*/", viewsJS,
).Replace(indexHTML)
}