template

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 24, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package template provides template functions and management for CronAI.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateExecutionContext

func CreateExecutionContext(data Data) map[string]interface{}

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

func FormatGitHubContent(content string, showContentHeader bool) string

FormatGitHubContent formats the content section

func FormatGitHubFooter

func FormatGitHubFooter(model string) string

FormatGitHubFooter generates a standardized GitHub footer

func FormatGitHubHeader

func FormatGitHubHeader(data Data, title string) string

FormatGitHubHeader generates a standardized GitHub header based on template data

func FormatGitHubVariables

func FormatGitHubVariables(data Data) string

FormatGitHubVariables formats the variables section if present

func GitHubCommentTemplate

func GitHubCommentTemplate(data Data) string

GitHubCommentTemplate returns a JSON structure for a GitHub comment

func GitHubIssueTemplate

func GitHubIssueTemplate(data Data) string

GitHubIssueTemplate returns a JSON structure for a GitHub issue

func GitHubPRTemplate

func GitHubPRTemplate(data Data) string

GitHubPRTemplate returns a JSON structure for a GitHub pull request

func JSONFunction

func JSONFunction(v interface{}) (string, error)

JSONFunction marshals data to a JSON string

func JoinFunction

func JoinFunction(items interface{}, sep string) string

JoinFunction joins items with a separator

func PreprocessBlockSyntax

func PreprocessBlockSyntax(content string) string

PreprocessBlockSyntax transforms simple block syntax to Go's template syntax

func ReplaceFunction

func ReplaceFunction(s, old, newStr string) string

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

type Inheritance struct {
	Parent string
	Blocks map[string]string
}

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 GetManager

func GetManager() *Manager

GetManager returns the singleton template manager

func (*Manager) Execute

func (m *Manager) Execute(name string, data Data) (string, error)

Execute applies a template with the given data

func (*Manager) ExecuteTemplate

func (m *Manager) ExecuteTemplate(name, templateName string, data Data) (string, error)

ExecuteTemplate executes a named template within a template file

func (*Manager) GetTemplate

func (m *Manager) GetTemplate(name string) (*template.Template, error)

GetTemplate retrieves a template by name

func (*Manager) Has

func (m *Manager) Has(name string) bool

Has checks if a template with the given name exists (alias for TemplateExists)

func (*Manager) IncludeTemplate

func (m *Manager) IncludeTemplate(content string) (string, error)

IncludeTemplate processes the template inclusion directive {{template "name" .}}

func (*Manager) LoadLibraryTemplates

func (m *Manager) LoadLibraryTemplates() error

LoadLibraryTemplates loads all templates in the default template library

func (*Manager) LoadTemplatesFromDir

func (m *Manager) LoadTemplatesFromDir(directory string) error

LoadTemplatesFromDir loads templates from a directory

func (*Manager) ParseInheritance

func (m *Manager) ParseInheritance(_ string, content string) (*Inheritance, string, error)

ParseInheritance parses template content for inheritance directives

func (*Manager) ProcessInheritance

func (m *Manager) ProcessInheritance(name string) (string, error)

ProcessInheritance processes a template with inheritance

func (*Manager) RegisterTemplate

func (m *Manager) RegisterTemplate(name, content string) error

RegisterTemplate adds or updates a template

func (*Manager) RegisterTemplateWithIncludes

func (m *Manager) RegisterTemplateWithIncludes(name, content string) error

RegisterTemplateWithIncludes registers a template and processes any includes

func (*Manager) SafeExecute

func (m *Manager) SafeExecute(name string, data Data) string

SafeExecute attempts to execute a template with fallbacks

func (*Manager) TemplateExists

func (m *Manager) TemplateExists(name string) bool

TemplateExists checks if a template with the given name exists

func (*Manager) Validate

func (m *Manager) Validate(name, content string) error

Validate checks if a template is valid with the given name

func (*Manager) ValidateTemplate

func (m *Manager) ValidateTemplate(filePath string) error

ValidateTemplate validates a template file

func (*Manager) ValidateTemplateContent

func (m *Manager) ValidateTemplateContent(content string) error

ValidateTemplateContent checks if template content is valid

func (*Manager) ValidateTemplatesInDir

func (m *Manager) ValidateTemplatesInDir(directory string) (map[string]error, error)

ValidateTemplatesInDir validates all templates in a directory

Jump to

Keyboard shortcuts

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