Commit 04912c04 authored by Eric Chiang's avatar Eric Chiang

server: generate string literals instead of escaped strings

When compiling the default templates into the source code, use
string literals instead of escaped strings to reduce merge
conflicts.
parent 058de90d
......@@ -27,6 +27,10 @@ var requiredTmpls = []string{
// TemplateConfig describes.
type TemplateConfig struct {
// TODO(ericchiang): Asking for a directory with a set of templates doesn't indicate
// what the templates should look like and doesn't allow consumers of this package to
// provide their own templates in memory. In the future clean this up.
// Directory of the templates. If empty, these will be loaded from memory.
Dir string `yaml:"dir"`
......
This diff is collapsed.
......@@ -32,12 +32,15 @@ func ignoreFile(p string) (ok bool, err error) {
return false, err
}
// Maps aren't deterministic, use a struct instead.
type fileData struct {
name string
data string
}
func main() {
// ReadDir guarentees result in sorted order.
dir, err := ioutil.ReadDir("web/templates")
if err != nil {
log.Fatal(err)
......@@ -57,6 +60,9 @@ func main() {
if err != nil {
log.Fatal(err)
}
if bytes.Contains(data, []byte{'`'}) {
log.Fatalf("file %s contains escape character '`' and cannot be compiled into go source", p)
}
files = append(files, fileData{file.Name(), string(data)})
}
......@@ -69,7 +75,7 @@ func main() {
fmt.Fprintln(f, "// defaultTemplates is a key for file name to file data of the files in web/templates.")
fmt.Fprintln(f, "var defaultTemplates = map[string]string{")
for _, file := range files {
fmt.Fprintf(f, "\t%q: %q,\n", file.name, file.data)
fmt.Fprintf(f, "\t%q: `%s`,\n", file.name, file.data)
}
fmt.Fprintln(f, "}")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment