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
- func DirtyFiles(c *Cache, files []string) []string
- func HashFile(path string) string
- func NewLogger(logLevel string, verbose bool, stderr io.Writer) *slog.Logger
- func ScanTemplFiles(root string) ([]string, error)
- type Cache
- type EnvValueInfo
- type InitCmdTemplateInfo
- type RouteTemplateInfo
- type SamTomlTemplateInfo
- type SamYamlTemplateInfo
- type StageTemplateInfo
- type TemplateHelper
- func (helper *TemplateHelper) CopyFile(filePath string, destinationPath string) error
- func (helper *TemplateHelper) CopyFromFs(fileTemplate embed.FS, templateFilePath string, outputFilePath string) error
- func (helper *TemplateHelper) CreateFromTemplate(fileTemplate embed.FS, templateFilePath string, outputFilePath string, ...) error
- func (helper *TemplateHelper) DeleteFile(filePath string) error
- func (helper *TemplateHelper) RenderToString(fileTemplate embed.FS, templateFilePath string, templateStruct interface{}) (string, error)
- func (helper *TemplateHelper) UpdateFromTemplate(templateFilePath string, outputFilePath string, templateStruct interface{}) error
- func (helper *TemplateHelper) UpdateFromTemplateFS(fileTemplate embed.FS, templateFilePath string, outputFilePath string, ...) error
Constants ¶
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 ¶
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 ¶
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 ScanTemplFiles ¶
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 (*Cache) Invalidate ¶
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 ¶
Save atomically writes the cache to disk (write to .tmp then rename). Failures are silent — the cache is best-effort.
type EnvValueInfo ¶
type InitCmdTemplateInfo ¶
type RouteTemplateInfo ¶
type SamTomlTemplateInfo ¶
type SamYamlTemplateInfo ¶
type SamYamlTemplateInfo struct {
Timeout int
MemorySize int
UsedTemplateName string
ProjectName string
StageTemplateInfo StageTemplateInfo
}
type StageTemplateInfo ¶
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 (*TemplateHelper) CreateFromTemplate ¶
func (*TemplateHelper) DeleteFile ¶
func (helper *TemplateHelper) DeleteFile(filePath string) error
func (*TemplateHelper) RenderToString ¶
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.