templgofilereg

package
v0.10.7 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

templgofilereg solves a very peculiar task. It provides a comparer that keeps track of generated `_templ.go` files given to it and tells whether the recent changes to it require Templiér to recompile and restart the application server because the internal Go code has changed.

In dev mode, Templ uses `_templ.txt` files to allow for fast reloads that don't require server recompilation, but Templiér can't know when to just refresh the tab and when to actually recompile because Templ always changes the `_templ.go` file. However, when it only changes the text argument to `templruntime.WriteString` we can tell we don't need recompilation and a tab refresh is enough.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Comparer

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

Comparer compares the generated `_templ.go` that Templ generates to its previous version passed to Compare and attempts to detect whether a server recompilation is necessary.

func New

func New() *Comparer

func (*Comparer) Compare

func (c *Comparer) Compare(filePath string) (recompile bool, err error)

Compare returns recompile=true if the _templ.go file under filePath changed in a way that requires the server to be recompiled. Otherwise the file only changed the text arguments in calls to templruntime.WriteString which means that the change can be reflected by _templ.txt fast reload dev file. Compare always returns recompile=true if the file is new.

func (*Comparer) Remove

func (c *Comparer) Remove(filePath string)

Remove removes the file from the registry. No-op if the file isn't registered.

Jump to

Keyboard shortcuts

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