templates

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package templates provides embedded templates for spec types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Available

func Available() []types.SpecType

Available returns all available template spec types.

func HasTemplate

func HasTemplate(specType types.SpecType) bool

HasTemplate returns true if a template exists for the spec type.

func NewFileLoader

func NewFileLoader(dir string) *fileLoader

NewFileLoader creates a loader that reads templates from a directory. Templates are named: {spec-type}.md (e.g., prd.md, security.md)

func RenderForProject

func RenderForProject(specType types.SpecType, projectName string) (string, error)

RenderForProject is a convenience function to render a template for a project.

Types

type Loader

type Loader interface {
	// Load returns the template for a spec type.
	Load(specType types.SpecType) (*Template, error)

	// Available returns all available spec types.
	Available() []types.SpecType
}

Loader loads templates from various sources.

func DefaultLoader

func DefaultLoader() Loader

DefaultLoader returns the default template loader (embedded templates).

func EmbeddedLoader

func EmbeddedLoader() Loader

EmbeddedLoader returns a loader that uses embedded templates.

func NewChainLoader

func NewChainLoader(loaders ...Loader) Loader

NewChainLoader creates a loader that tries multiple loaders in order. The first loader that can load a template wins.

func NewEmbedFSLoader

func NewEmbedFSLoader(fsys embed.FS, dir string) Loader

NewEmbedFSLoader creates a loader that reads templates from an embedded filesystem. This is useful for organizations that want to compile custom templates into their CLI.

Usage:

//go:embed templates/*.md
var orgTemplates embed.FS

loader := templates.NewEmbedFSLoader(orgTemplates, "templates")

func NewSubFSLoader

func NewSubFSLoader(fsys fs.FS) Loader

NewSubFSLoader creates a loader from an fs.FS interface. This is useful when working with fs.Sub() results.

type RenderOptions

type RenderOptions struct {
	ProjectName string
	Author      string
	Date        string
}

RenderOptions contains options for rendering a template.

func DefaultRenderOptions

func DefaultRenderOptions() RenderOptions

DefaultRenderOptions returns default options for rendering.

type Template

type Template struct {
	SpecType types.SpecType
	Content  string
}

Template represents a loaded template with metadata.

func Get

func Get(specType types.SpecType) (*Template, error)

Get returns the template for a spec type.

func LoadWithLoader

func LoadWithLoader(loader Loader, specType types.SpecType) (*Template, error)

LoadWithLoader loads a template using a specific loader.

func MustGet

func MustGet(specType types.SpecType) *Template

MustGet returns the template for a spec type, panicking on error.

func (*Template) Render

func (t *Template) Render(opts RenderOptions) string

Render renders the template with the given options.

Jump to

Keyboard shortcuts

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