statping/utils.go

49 lines
1010 B
Go
Raw Normal View History

2018-06-23 05:59:29 +00:00
package main
import (
"bytes"
2018-06-29 02:24:31 +00:00
"github.com/hunterlong/statup/log"
2018-06-23 05:59:29 +00:00
"html/template"
2018-06-24 06:44:15 +00:00
"io/ioutil"
2018-06-23 05:59:29 +00:00
)
2018-06-23 08:42:50 +00:00
func ExportIndexHTML() string {
2018-06-24 06:44:15 +00:00
core.OfflineAssets = true
2018-06-23 08:42:50 +00:00
out := index{*core, services}
nav, _ := tmplBox.String("nav.html")
footer, _ := tmplBox.String("footer.html")
render, err := tmplBox.String("index.html")
if err != nil {
2018-06-29 02:24:31 +00:00
log.Send(3, err)
2018-06-23 08:42:50 +00:00
}
t := template.New("message")
t.Funcs(template.FuncMap{
2018-06-23 05:59:29 +00:00
"js": func(html string) template.JS {
return template.JS(html)
},
"safe": func(html string) template.HTML {
return template.HTML(html)
},
"VERSION": func() string {
return VERSION
},
"underscore": func(html string) string {
return UnderScoreString(html)
},
2018-06-23 08:42:50 +00:00
})
2018-06-23 05:59:29 +00:00
t, _ = t.Parse(nav)
t, _ = t.Parse(footer)
t.Parse(render)
var tpl bytes.Buffer
if err := t.Execute(&tpl, out); err != nil {
2018-06-29 02:24:31 +00:00
log.Send(3, err)
2018-06-23 05:59:29 +00:00
}
result := tpl.String()
return result
}
2018-06-24 06:44:15 +00:00
func SaveFile(filename string, data []byte) error {
err := ioutil.WriteFile(filename, data, 0644)
return err
}