Documentation
¶
Overview ¶
Package template provides Mustache template rendering functionality.
Index ¶
- func ConvertSliceToMaps(slice any) []map[string]any
- func PreprocessModelData(modelMaps []map[string]any) []map[string]any
- func PreprocessOperationData(opMaps []map[string]any) []map[string]any
- func ToTemplateData(data any) map[string]any
- type Engine
- func (e *Engine) LoadPartials() error
- func (e *Engine) LoadPartialsFromFS() error
- func (e *Engine) RegisterDefaultLambdas()
- func (e *Engine) RegisterLambda(name string, fn func(text string, render mustache.RenderFunc) (string, error))
- func (e *Engine) Render(templateName string, data any) (string, error)
- func (e *Engine) RenderString(template string, data any) (string, error)
- func (e *Engine) RenderToFile(templateName string, data any, outputPath string) error
- type RenderFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertSliceToMaps ¶
ConvertSliceToMaps converts a slice of structs to a slice of maps.
func PreprocessModelData ¶
PreprocessModelData adds synthetic fields for Mustache template compatibility.
func PreprocessOperationData ¶
PreprocessOperationData adds synthetic fields for Mustache template compatibility. The Java Mustache library supports ".0" syntax for checking if an array has elements, but the Go cbroglie/mustache library does not. This function adds boolean "has*" fields.
func ToTemplateData ¶
ToTemplateData converts any struct or data to a map suitable for template rendering.
Types ¶
type Engine ¶
type Engine struct {
// TemplateDir is the directory containing templates
TemplateDir string
// Custom lambdas for templates
Lambdas map[string]func(text string, render mustache.RenderFunc) (string, error)
// Verbose enables debug logging of template execution
Verbose bool
// contains filtered or unexported fields
}
Engine handles Mustache template rendering.
func NewEngineFromFS ¶
NewEngineFromFS creates a new template engine from an embedded filesystem. The subdir parameter specifies the subdirectory within the fs.FS to use as the template root (e.g., "typescript-fetch").
func (*Engine) LoadPartials ¶
LoadPartials loads all partial templates from the template directory.
func (*Engine) LoadPartialsFromFS ¶
LoadPartialsFromFS loads all partial templates from the embedded filesystem.
func (*Engine) RegisterDefaultLambdas ¶
func (e *Engine) RegisterDefaultLambdas()
RegisterDefaultLambdas registers the default set of lambdas used by openapi-generator.
func (*Engine) RegisterLambda ¶
func (e *Engine) RegisterLambda(name string, fn func(text string, render mustache.RenderFunc) (string, error))
RegisterLambda registers a custom lambda function.
func (*Engine) Render ¶
Render renders a template with the given data. If the engine was created with NewEngineFromFS, it reads from the embedded filesystem.
func (*Engine) RenderString ¶
RenderString renders a template string with the given data.
type RenderFunc ¶
type RenderFunc = mustache.RenderFunc
RenderFunc is the function signature for mustache rendering.