Overview
The TemplateGenerator
provides functionality to generate files using Go's text/template and apply
formatting based on file extensions. It encapsulates the generation process and allows customization through options.
Features
- Parse text templates.
- Execute templates with provided data.
- Generate files based on templates.
- Apply formatting based on file extensions. Supported formaters:
- .go -> Go
- .tf -> Terraform
How to Use
$ go get github.com/diagram-code-generator/template@latest
Example Usage
ackage main
import (
"github.com/diagram-code-generator/template/pkg/generators"
)
func main() {
// Create a new TemplateGenerator instance
tg := generators.NewTemplateGenerator()
// Define data to be used in the template
data := struct {
Name string
}{
Name: "Joselito",
}
// Define a text template
templateContent := "Hello, {{.Name}}!"
// Build and execute the template
output, err := tg.Build(data, "example_template", templateContent)
if err != nil {
panic(err)
}
// Print the output
fmt.Println(output)
}
Contributing
Contributions are welcome! If you find any issues or have suggestions for improvements, feel free to create an
issue or submit a pull request. Your contribution is much appreciated. See Contributing.
![open - Contributing](https://img.shields.io/badge/open-contributing-blue?style=for-the-badge)
License
This project is licensed under the MIT License.