Beispiel #1
0
func getTemplates() []string {
	names, err := getDirContents(config.GetRepoPath())
	if err != nil {
		log.Fatalf("Could not read templates: %s", err)
	}
	var templates []string
	ignore := regexp.MustCompile("^.git$")
	for idx := 0; idx < len(names); idx++ {
		if !ignore.MatchString(names[idx]) {
			templates = append(templates, names[idx])
		}
	}
	return templates
}
Beispiel #2
0
func populateDir(dir string, template string, context map[string]string) {
	tpldir := path.Join(config.GetRepoPath(), template)
	files, err := getDirContents(tpldir)
	if err != nil {
		log.Fatalf("Could not get contents of template %s: %s", template, err)
	}
	for index := 0; index < len(files); index++ {
		fn := files[index]
		content := mustache.RenderFile(path.Join(tpldir, fn), context)
		f, err := os.Create(path.Join(dir, fn))
		if err != nil {
			log.Fatalf("Could not create %s: %s", fn, err)
		}
		f.WriteString(content)
		f.Close()
	}
}