Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
107352787c | ||
|
|
57fa355a6f |
5
models/output.go
Normal file
5
models/output.go
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
type Outputs []Output
|
||||||
|
|
||||||
|
type Output []byte
|
||||||
@@ -4,6 +4,8 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"html/template"
|
"html/template"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"gitea.tecamino.com/paadi/template-builder/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TemplateBuilder struct {
|
type TemplateBuilder struct {
|
||||||
@@ -47,3 +49,19 @@ func (tb *TemplateBuilder) Generate(templatePath string, data any) (b []byte, er
|
|||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (tb *TemplateBuilder) GenerateMultiple(templatePath string, data ...any) (output models.Outputs, err error) {
|
||||||
|
tmpl, err := template.ParseFiles(templatePath)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for _, d := range data {
|
||||||
|
var buf bytes.Buffer
|
||||||
|
err = tmpl.Execute(&buf, d)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
output = append(output, buf.Bytes())
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|||||||
@@ -30,5 +30,5 @@ func TestTemplateBuilderData(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Log(string(data))
|
t.Log(data)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user