Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var TemplateFS embed.FS
TemplateFS embeds the *.tpl files in this directory using an embed.FS. Templates should be named `{name}.{format}.tpl` according to the naming convention. The `go:embed` directive includes all template files matching the pattern.
Functions ¶
func ListTemplates ¶
func ListTemplates() (map[string]*ParsedTemplateFile, error)
ListTemplates reads all embedded template files and returns a map where keys are template file paths and values are parsed template specifications. The parsed templates contain metadata and content for each file.
Types ¶
type DocumentFormat ¶
type DocumentFormat string
DocumentFormat is a supported document format. it provides methods for validation and retrieving file extensions.
const ( // DocumentFormatMarkdown represents a markdown document format. DocumentFormatMarkdown DocumentFormat = "markdown" )
Available DocumentFormat constants for supported document types.
func (DocumentFormat) Extension ¶
func (df DocumentFormat) Extension() string
Extension returns the file extension associated with the DocumentFormat. If the format is unsupported, it returns "txt" as a safe default.
func (DocumentFormat) Validate ¶
func (df DocumentFormat) Validate() error
Validate checks if the DocumentFormat is supported. It returns an error if the format is not recognized.
type ParsedTemplateFile ¶
type ParsedTemplateFile struct { // ID is the template id. // This is the sluggified version of the human name, used primarily to create the physical filename. ID string // Name is the human name of the document Name string // Format is the DocumentFormat for this template. Format DocumentFormat // Content holds the templated content bytes, ready for writing Content []byte }
ParsedTemplateFile unpacks the name and format from the template filename and joins with its content. once constructed, downstream business logic is entirely decoupled from the filesystem.
func DefaultTemplateForFormat ¶
func DefaultTemplateForFormat(format DocumentFormat) (*ParsedTemplateFile, error)
DefaultTemplateForFormat retrieves the default template for a given DocumentFormat. Default templates are expected to follow the naming pattern "default.{format}.tpl". Returns an error if no template matching the default pattern is found.
func (*ParsedTemplateFile) Validate ¶
func (t *ParsedTemplateFile) Validate() error
Validate validates the object, returning any error.
type TemplateNotFoundError ¶
type TemplateNotFoundError struct {
TemplateName string
}
func (TemplateNotFoundError) Error ¶
func (e TemplateNotFoundError) Error() string