render

package
v1.6.0-beta.12 Latest Latest
Warning

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

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

Documentation

Overview

Package templ provides a content-hash cache for .templ files so that `templ generate` is only invoked for files whose contents (or generated counterparts) have changed since the last run.

Cache layout: a flat {<relative-path>: sha256-hex} JSON map persisted at templCachePath. The format mirrors pkg/helpers/wasm/wasm_cache.go so both caches behave consistently and remain easy to inspect by hand.

Index

Constants

View Source
const TemplCachePath = ".gothicCli/templ-cache.json"

TemplCachePath is the on-disk location of the templ hash cache. Exported so callers (and tests) can override behavior if needed.

Variables

This section is empty.

Functions

func DirtyFiles

func DirtyFiles(c *Cache, files []string) []string

DirtyFiles returns the subset of files whose hash differs from the cache or whose generated _templ.go counterpart is missing. Files that hash to "" (unreadable) are also returned so the caller surfaces the error via templ.

func HashFile

func HashFile(path string) string

HashFile computes the SHA-256 hex digest of a file's contents. Returns "" if the file cannot be read so callers can treat the file as dirty.

func NewLogger

func NewLogger(logLevel string, verbose bool, stderr io.Writer) *slog.Logger

func ScanTemplFiles

func ScanTemplFiles(root string) ([]string, error)

ScanTemplFiles walks root and returns the relative paths of every .templ file found. Hidden directories (".git", "node_modules", ".gothicCli") are skipped to avoid touching generated or vendored trees.

Types

type Cache

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

Cache holds per-file content hashes of .templ files. It is safe for concurrent use; callers typically Load, mutate via Update, then Save in a single hot-reload cycle.

func Load

func Load() *Cache

Load reads the cache at TemplCachePath. Missing or malformed files yield an empty cache rather than an error — the cache is an optimization, never a correctness boundary.

func LoadAt

func LoadAt(path string) *Cache

LoadAt is Load with an explicit path; useful for tests that need isolation.

func (*Cache) Invalidate

func (c *Cache) Invalidate(key string)

Invalidate removes key from the cache (e.g., when the generated _templ.go counterpart is missing and we want to force regeneration).

func (*Cache) Save

func (c *Cache) Save() error

Save atomically writes the cache to disk (write to .tmp then rename). Failures are silent — the cache is best-effort.

func (*Cache) UpToDate

func (c *Cache) UpToDate(key, hash string) bool

UpToDate reports whether the cached hash for key matches hash and is non-empty.

func (*Cache) Update

func (c *Cache) Update(key, hash string)

Update records hash for key in memory. Call Save to persist.

type EnvValueInfo

type EnvValueInfo struct {
	Value        interface{}
	Key          string // Lambda env var name (spaces replaced with underscores)
	SanitizedKey string // Alphanumeric-only key for CloudFormation Mappings lookups
}

type InitCmdTemplateInfo

type InitCmdTemplateInfo struct {
	ProjectName            string
	GoModName              string
	MainServerPackageName  string
	MainServerFunctionName string
	PageName               string
	RouteName              string
	ComponentName          string
}

type RouteTemplateInfo

type RouteTemplateInfo struct {
	PageName      string
	RouteName     string
	ComponentName string
	GoModName     string
}

type SamTomlTemplateInfo

type SamTomlTemplateInfo struct {
	StackName string
	AwsRegion string
}

type SamYamlTemplateInfo

type SamYamlTemplateInfo struct {
	Timeout           int
	MemorySize        int
	UsedTemplateName  string
	ProjectName       string
	StageTemplateInfo StageTemplateInfo
}

type StageTemplateInfo

type StageTemplateInfo struct {
	Name                  string
	BucketName            string
	LambdaName            string
	CustomDomain          string
	HostedZone            string
	CertificateArn        string
	IsCustomDomainWithArn bool
	IsCustomDomain        bool
	WafArn                string
	Env                   []EnvValueInfo
}

type TemplateHelper

type TemplateHelper struct {
	InitCmdTemplateInfo InitCmdTemplateInfo
	RouteTemplateInfo   RouteTemplateInfo
}

func NewTemplateHelper

func NewTemplateHelper() TemplateHelper

func (*TemplateHelper) CopyFile

func (helper *TemplateHelper) CopyFile(filePath string, destinationPath string) error

func (*TemplateHelper) CopyFromFs

func (helper *TemplateHelper) CopyFromFs(fileTemplate embed.FS, templateFilePath string, outputFilePath string) error

func (*TemplateHelper) CreateFromTemplate

func (helper *TemplateHelper) CreateFromTemplate(fileTemplate embed.FS, templateFilePath string, outputFilePath string, templateStruct interface{}) error

func (*TemplateHelper) DeleteFile

func (helper *TemplateHelper) DeleteFile(filePath string) error

func (*TemplateHelper) RenderToString

func (helper *TemplateHelper) RenderToString(fileTemplate embed.FS, templateFilePath string, templateStruct interface{}) (string, error)

func (*TemplateHelper) UpdateFromTemplate

func (helper *TemplateHelper) UpdateFromTemplate(templateFilePath string, outputFilePath string, templateStruct interface{}) error

func (*TemplateHelper) UpdateFromTemplateFS

func (helper *TemplateHelper) UpdateFromTemplateFS(fileTemplate embed.FS, templateFilePath string, outputFilePath string, templateStruct interface{}) error

UpdateFromTemplateFS renders a template stored in an embed.FS to a destination file on disk. It mirrors UpdateFromTemplate but reads the template source from the provided embed.FS rather than the user's project tree. This is the path used for templates the CLI considers an implementation detail (WASM glue, generated route registration) and no longer seeds onto user disk.

Jump to

Keyboard shortcuts

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