templates

package
v1.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 10, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Files embed.FS

Functions

func ClearCache

func ClearCache()

ClearCache clears cache.

func GetCachedTemplate

func GetCachedTemplate(templateName string, funcMap template.FuncMap) (*template.Template, error)

GetCachedTemplate returns cached template.

func RenderTemplateUsingGlobal

func RenderTemplateUsingGlobal(templateName string, data any) (string, error)

RenderTemplateUsingGlobal renders a template using the global service

Types

type DatabaseData

type DatabaseData struct {
	Type   string `json:"type"`
	Method string `json:"method"`
	Driver string `json:"driver"`
}

DatabaseData contains database-specific template data

type ProjectData

type ProjectData struct {
	ModulePath string `json:"module_path"`
	Name       string `json:"name"`
}

ProjectData contains project-specific template data

type ResourceData

type ResourceData struct {
	Name         string `json:"name"`
	PluralName   string `json:"plural_name"`
	Fields       any    `json:"fields"`
	ModulePath   string `json:"module_path"`
	Type         string `json:"type"`
	DatabaseType string `json:"database_type"`
}

ResourceData contains resource-specific template data

type TemplateBuilder

type TemplateBuilder struct {
	// contains filtered or unexported fields
}

TemplateBuilder provides a fluent interface for building template data

func NewTemplateBuilder

func NewTemplateBuilder(service *TemplateService) *TemplateBuilder

NewTemplateBuilder creates a new template builder

func NewTemplateBuilderUsingGlobal

func NewTemplateBuilderUsingGlobal() *TemplateBuilder

NewTemplateBuilderUsingGlobal creates a new template builder using the global service

func (*TemplateBuilder) Render

func (tb *TemplateBuilder) Render(templateName string) (string, error)

Render renders the template with the built data

func (*TemplateBuilder) WithCustom

func (tb *TemplateBuilder) WithCustom(key string, value any) *TemplateBuilder

WithCustom adds custom data

func (*TemplateBuilder) WithDatabase

func (tb *TemplateBuilder) WithDatabase(dbType, method, driver string) *TemplateBuilder

WithDatabase sets database data

func (*TemplateBuilder) WithProject

func (tb *TemplateBuilder) WithProject(modulePath, name string) *TemplateBuilder

WithProject sets project data

func (*TemplateBuilder) WithResource

func (tb *TemplateBuilder) WithResource(
	name, pluralName, modulePath, resourceType, databaseType string,
	fields any,
) *TemplateBuilder

WithResource sets resource data

type TemplateCache

type TemplateCache struct {
	// contains filtered or unexported fields
}

TemplateCache represents template cache.

func NewTemplateCache

func NewTemplateCache() *TemplateCache

NewTemplateCache creates a new template cache.

func (*TemplateCache) GetTemplate

func (tc *TemplateCache) GetTemplate(
	templateName string,
	funcMap template.FuncMap,
) (*template.Template, error)

GetTemplate returns template.

type TemplateData

type TemplateData struct {
	Resource ResourceData   `json:"resource"`
	Database DatabaseData   `json:"database"`
	Project  ProjectData    `json:"project"`
	Custom   map[string]any `json:"custom"`
}

TemplateData represents the unified data structure for all templates

type TemplateService

type TemplateService struct {
	// contains filtered or unexported fields
}

TemplateService provides unified template rendering functionality

func GetGlobalTemplateService

func GetGlobalTemplateService() *TemplateService

GetGlobalTemplateService returns the global template service instance

func NewTemplateService

func NewTemplateService() *TemplateService

NewTemplateService creates a new template service with default functions

func (*TemplateService) RenderTemplate

func (ts *TemplateService) RenderTemplate(templateName string, data any) (string, error)

RenderTemplate renders a template with the given data

func (*TemplateService) RenderTemplateWithCustomFunctions

func (ts *TemplateService) RenderTemplateWithCustomFunctions(
	templateName string,
	data any,
	funcMap template.FuncMap,
) (string, error)

RenderTemplateWithCustomFunctions renders a template with custom function map

func (*TemplateService) RenderTemplateWithCustomFunctionsAndPartials added in v1.2.2

func (ts *TemplateService) RenderTemplateWithCustomFunctionsAndPartials(
	templateName string,
	partialNames []string,
	data any,
	funcMap template.FuncMap,
) (string, error)

RenderTemplateWithCustomFunctionsAndPartials renders a primary template together with named partial template files.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL