push all
This commit is contained in:
12
README.md
Normal file
12
README.md
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
# 🛠️ Go Template Builder
|
||||||
|
|
||||||
|
A lightweight, no-nonsense Go library to parse and render templates directly from files. Stop writing boilerplate for `text/template` and `html/template`—just point to a file, pass your data, and you're done.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📦 Installation
|
||||||
|
|
||||||
|
To use this package in your project, run:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
go get [gitea.tecamino.com//paadi/template-builder](https://gitea.tecamino.com/paadi/template-builder)
|
||||||
3
go.mod
Normal file
3
go.mod
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
module gitea.tecamino.com/paadi/template-builder.git
|
||||||
|
|
||||||
|
go 1.25.4
|
||||||
32
templateBuilder.go
Normal file
32
templateBuilder.go
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
package templatebuilder
|
||||||
|
|
||||||
|
import (
|
||||||
|
"html/template"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
type TemplateBuilder struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewTemplateBuilder() *TemplateBuilder {
|
||||||
|
return &TemplateBuilder{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (tb *TemplateBuilder) Generate(templatePath, outputFile string, data any) error {
|
||||||
|
tmpl, err := template.ParseFiles(templatePath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
f, err := os.Create(outputFile)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
err = tmpl.Execute(f, data)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user