mirror of
https://github.com/ralsina/tartrazine.git
synced 2025-06-19 14:43:05 -03:00
added documentation_matchers.go generation
This commit is contained in:
37
internal/code-generator/generator/documentation.go
Normal file
37
internal/code-generator/generator/documentation.go
Normal 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, ®expList); 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
|
||||
}
|
Reference in New Issue
Block a user