Documentation
¶
Overview ¶
Package template provides template functions and management for CronAI.
Index ¶
- func CreateExecutionContext(data Data) map[string]interface{}
- func DefaultFunction(value, defaultValue interface{}) interface{}
- func FormatGitHubContent(content string, showContentHeader bool) string
- func FormatGitHubFooter(model string) string
- func FormatGitHubHeader(data Data, title string) string
- func FormatGitHubVariables(data Data) string
- func GitHubCommentTemplate(data Data) string
- func GitHubIssueTemplate(data Data) string
- func GitHubPRTemplate(data Data) string
- func JSONFunction(v interface{}) (string, error)
- func JoinFunction(items interface{}, sep string) string
- func PreprocessBlockSyntax(content string) string
- func ReplaceFunction(s, old, newStr string) string
- type Data
- type Inheritance
- type InheritanceResult
- type Manager
- func (m *Manager) Execute(name string, data Data) (string, error)
- func (m *Manager) ExecuteTemplate(name, templateName string, data Data) (string, error)
- func (m *Manager) GetTemplate(name string) (*template.Template, error)
- func (m *Manager) Has(name string) bool
- func (m *Manager) IncludeTemplate(content string) (string, error)
- func (m *Manager) LoadLibraryTemplates() error
- func (m *Manager) LoadTemplatesFromDir(directory string) error
- func (m *Manager) ParseInheritance(_ string, content string) (*Inheritance, string, error)
- func (m *Manager) ProcessInheritance(name string) (string, error)
- func (m *Manager) RegisterTemplate(name, content string) error
- func (m *Manager) RegisterTemplateWithIncludes(name, content string) error
- func (m *Manager) SafeExecute(name string, data Data) string
- func (m *Manager) TemplateExists(name string) bool
- func (m *Manager) Validate(name, content string) error
- func (m *Manager) ValidateTemplate(filePath string) error
- func (m *Manager) ValidateTemplateContent(content string) error
- func (m *Manager) ValidateTemplatesInDir(directory string) (map[string]error, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateExecutionContext ¶
CreateExecutionContext creates a context that merges Data and Variables
func DefaultFunction ¶
func DefaultFunction(value, defaultValue interface{}) interface{}
DefaultFunction returns default value if input is empty
func FormatGitHubContent ¶
FormatGitHubContent formats the content section
func FormatGitHubFooter ¶
FormatGitHubFooter generates a standardized GitHub footer
func FormatGitHubHeader ¶
FormatGitHubHeader generates a standardized GitHub header based on template data
func FormatGitHubVariables ¶
FormatGitHubVariables formats the variables section if present
func GitHubCommentTemplate ¶
GitHubCommentTemplate returns a JSON structure for a GitHub comment
func GitHubIssueTemplate ¶
GitHubIssueTemplate returns a JSON structure for a GitHub issue
func GitHubPRTemplate ¶
GitHubPRTemplate returns a JSON structure for a GitHub pull request
func JSONFunction ¶
JSONFunction marshals data to a JSON string
func JoinFunction ¶
JoinFunction joins items with a separator
func PreprocessBlockSyntax ¶
PreprocessBlockSyntax transforms simple block syntax to Go's template syntax
func ReplaceFunction ¶
ReplaceFunction replaces old with new in a string
Types ¶
type Data ¶
type Data struct {
Content string // Model response content
Model string // Model name
Timestamp time.Time // Response timestamp
PromptName string // Name of the prompt
Variables map[string]string // Custom variables
ExecutionID string // Unique execution identifier
Metadata map[string]string // Additional metadata
Parent interface{} // Parent template data for inheritance
}
Data contains data available to templates
type Inheritance ¶
Inheritance tracks parent-child relationships between templates
type InheritanceResult ¶
type InheritanceResult struct {
Parent string // Parent template name
Blocks map[string]string // Blocks defined in the template
}
InheritanceResult represents the result of inheritance processing
func ProcessInheritance ¶
func ProcessInheritance(content string) (*InheritanceResult, error)
ProcessInheritance processes template inheritance directives
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager handles template operations
func (*Manager) ExecuteTemplate ¶
ExecuteTemplate executes a named template within a template file
func (*Manager) GetTemplate ¶
GetTemplate retrieves a template by name
func (*Manager) Has ¶
Has checks if a template with the given name exists (alias for TemplateExists)
func (*Manager) IncludeTemplate ¶
IncludeTemplate processes the template inclusion directive {{template "name" .}}
func (*Manager) LoadLibraryTemplates ¶
LoadLibraryTemplates loads all templates in the default template library
func (*Manager) LoadTemplatesFromDir ¶
LoadTemplatesFromDir loads templates from a directory
func (*Manager) ParseInheritance ¶
ParseInheritance parses template content for inheritance directives
func (*Manager) ProcessInheritance ¶
ProcessInheritance processes a template with inheritance
func (*Manager) RegisterTemplate ¶
RegisterTemplate adds or updates a template
func (*Manager) RegisterTemplateWithIncludes ¶
RegisterTemplateWithIncludes registers a template and processes any includes
func (*Manager) SafeExecute ¶
SafeExecute attempts to execute a template with fallbacks
func (*Manager) TemplateExists ¶
TemplateExists checks if a template with the given name exists
func (*Manager) ValidateTemplate ¶
ValidateTemplate validates a template file
func (*Manager) ValidateTemplateContent ¶
ValidateTemplateContent checks if template content is valid