2020-01-10 20:41:13 -05:00
|
|
|
// +build ignore
|
|
|
|
|
2020-01-04 22:21:39 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
|
|
|
"io/ioutil"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
"text/template"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
dir := os.Args[1]
|
|
|
|
|
|
|
|
files, err := ioutil.ReadDir(dir)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
var str strings.Builder
|
|
|
|
|
|
|
|
for _, file := range files {
|
2020-01-11 22:18:22 -05:00
|
|
|
name := file.Name()
|
|
|
|
|
|
|
|
str.WriteString("\n" + `{{define "`)
|
|
|
|
str.WriteString(strings.TrimSuffix(name, filepath.Ext(name)))
|
|
|
|
str.WriteString(`"}}<script>`)
|
|
|
|
|
|
|
|
func() {
|
|
|
|
in, err := os.Open(filepath.Join(dir, name))
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
defer in.Close()
|
|
|
|
|
|
|
|
scanner := bufio.NewScanner(in)
|
|
|
|
for scanner.Scan() {
|
|
|
|
line := strings.TrimSpace(scanner.Text())
|
|
|
|
if line != "" {
|
|
|
|
str.WriteString(line)
|
|
|
|
str.WriteRune('\n')
|
2020-01-04 22:21:39 -05:00
|
|
|
}
|
2020-01-11 22:18:22 -05:00
|
|
|
}
|
|
|
|
if err := scanner.Err(); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}()
|
2020-01-04 22:21:39 -05:00
|
|
|
|
2020-01-11 22:18:22 -05:00
|
|
|
str.WriteString("</script>{{end}}")
|
2020-01-04 22:21:39 -05:00
|
|
|
}
|
|
|
|
|
2020-01-10 20:41:13 -05:00
|
|
|
out, err := os.Create("generated.go")
|
2020-01-04 22:21:39 -05:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = generator.Execute(out, str.String())
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = out.Close()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var generator = template.Must(template.New("").Parse(`// Code generated by zenity; DO NOT EDIT.
|
2020-01-10 20:41:13 -05:00
|
|
|
// +build darwin
|
2020-01-04 22:21:39 -05:00
|
|
|
|
2020-01-05 07:37:45 -05:00
|
|
|
package osa
|
2020-01-04 22:21:39 -05:00
|
|
|
|
|
|
|
import "html/template"
|
|
|
|
|
2020-01-05 07:37:45 -05:00
|
|
|
var scripts = template.Must(template.New("").Parse(` + "`{{.}}`" + `))
|
2020-01-04 22:21:39 -05:00
|
|
|
`))
|