diff options
Diffstat (limited to 'generate/include.go')
| -rw-r--r-- | generate/include.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/generate/include.go b/generate/include.go new file mode 100644 index 0000000..54c2ba9 --- /dev/null +++ b/generate/include.go @@ -0,0 +1,30 @@ +package main + +import ( + "io" + "io/ioutil" + "os" + "strings" +) + +// Reads all .txt files in the current folder +// and encodes them as strings literals in textfiles.go +func main() { + fs, _ := ioutil.ReadDir("templates/") + out, _ := os.Create("templates.go") + out.Write([]byte("package main \n\nconst (\n")) + for _, f := range fs { + if strings.HasSuffix(f.Name(), ".tmpl") { + out.Write([]byte(strings.TrimSuffix(f.Name(), ".tmpl") + " = `")) + f, _ := os.Open("templates/" + f.Name()) + io.Copy(out, f) + out.Write([]byte("`\n")) + } + } + out.Write([]byte(")\n")) + out.Write([]byte("func getTemplate() string {\n")) + out.Write([]byte(`return "{{define \"block_facebook.tmpl\"}}" + block_facebook + "{{end}}{{define \"cache_static.tmpl\"}}" + cache_static + "{{end}} {{define \"pagespeed.tmpl\"}}" + pagespeed + "{{end}} {{define \"robots.tmpl\"}}" + robots + "{{end}} {{define \"ssl.tmpl\"}}" + ssl + "{{end}}" + server`)) + out.Write([]byte("\n\n}\n")) + out.Write([]byte("func isGenerated() bool { return true }\n")) + +} |
