added documentation_matchers.go generation

This commit is contained in:
Manuel Carmona
2017-04-10 11:30:23 +02:00
parent d66beade34
commit ca3ae587f3
11 changed files with 250 additions and 34 deletions

View File

@ -0,0 +1,37 @@
package generator
import (
"bytes"
"html/template"
"io"
yaml "gopkg.in/yaml.v2"
)
// Documentation reads from buf and builds documentation_matchers.go file from documentationTmplPath.
func Documentation(data []byte, documentationTmplPath, documentationTmplName, commit string) ([]byte, error) {
var regexpList []string
if err := yaml.Unmarshal(data, &regexpList); err != nil {
return nil, err
}
buf := &bytes.Buffer{}
if err := executeVendorTemplate(buf, regexpList, documentationTmplPath, documentationTmplName, commit); err != nil {
return nil, err
}
return buf.Bytes(), nil
}
func executeDocumentationTemplate(out io.Writer, regexpList []string, documentationTmplPath, documentationTmpl, commit string) error {
fmap := template.FuncMap{
"getCommit": func() string { return commit },
}
t := template.Must(template.New(documentationTmpl).Funcs(fmap).ParseFiles(documentationTmplPath))
if err := t.Execute(out, regexpList); err != nil {
return err
}
return nil
}