tartrazine/internal/code-generator/generator/documentation.go

33 lines
845 B
Go
Raw Normal View History

package generator
import (
"bytes"
"gopkg.in/yaml.v2"
"io"
2017-06-13 11:56:07 +00:00
"io/ioutil"
)
// Documentation reads from fileToParse and builds source file from tmplPath. It complies with type File signature.
2017-06-13 11:56:07 +00:00
func Documentation(fileToParse, samplesDir, outPath, tmplPath, tmplName, commit string) error {
data, err := ioutil.ReadFile(fileToParse)
if err != nil {
return err
}
var regexpList []string
if err := yaml.Unmarshal(data, &regexpList); err != nil {
2017-06-13 11:56:07 +00:00
return err
}
buf := &bytes.Buffer{}
2017-06-13 11:56:07 +00:00
if err := executeDocumentationTemplate(buf, regexpList, tmplPath, tmplName, commit); err != nil {
return err
}
2017-06-13 11:56:07 +00:00
return formatedWrite(outPath, buf.Bytes())
}
2017-06-13 11:56:07 +00:00
func executeDocumentationTemplate(out io.Writer, regexpList []string, tmplPath, tmplName, commit string) error {
return executeTemplate(out, tmplName, tmplPath, commit, nil, regexpList)
}