Documentation
¶
Index ¶
- Variables
- func AvailablePreTransforms() []string
- func ExpandTailwindVariantGroups(input string) string
- func HasGoChanged(previous, updated GeneratorOutput) bool
- func HasTextChanged(previous, updated GeneratorOutput) bool
- func TailwindVariantGroupPreTransform(tf *parser.TemplateFile) error
- type GenerateOpt
- type GeneratorOptions
- type GeneratorOutput
- type PreTransform
- type RangeWriter
Constants ¶
This section is empty.
Variables ¶
var ( // ErrUnknownPreTransform is returned when a named pre-transform does not exist. ErrUnknownPreTransform = errors.New("unknown pre-transform") )
Functions ¶
func AvailablePreTransforms ¶
func AvailablePreTransforms() []string
AvailablePreTransforms returns the names of all built-in pre-transforms.
func ExpandTailwindVariantGroups ¶
ExpandTailwindVariantGroups expands Tailwind class variant groups in a class string.
func HasGoChanged ¶
func HasGoChanged(previous, updated GeneratorOutput) bool
HasGoChanged returns true if the Go code has changed between the previous and updated GeneratorOutput.
func HasTextChanged ¶
func HasTextChanged(previous, updated GeneratorOutput) bool
HasTextChanged returns true if the text literals have changed between the previous and updated GeneratorOutput.
func TailwindVariantGroupPreTransform ¶
func TailwindVariantGroupPreTransform(tf *parser.TemplateFile) error
TailwindVariantGroupPreTransform expands class variant groups like: "hover:(underline font-bold)" => "hover:underline hover:font-bold"
Types ¶
type GenerateOpt ¶
type GenerateOpt func(g *generator) error
func WithFileName ¶
func WithFileName(name string) GenerateOpt
WithFileName sets the filename of the templ file in template rendering error messages.
func WithNamedPreTransforms ¶
func WithNamedPreTransforms(names ...string) GenerateOpt
WithNamedPreTransforms enables one or more built-in pre-transforms by name.
func WithPreTransforms ¶
func WithPreTransforms(transforms ...PreTransform) GenerateOpt
WithPreTransforms enables one or more custom pre-transforms.
func WithSkipCodeGeneratedComment ¶
func WithSkipCodeGeneratedComment() GenerateOpt
WithSkipCodeGeneratedComment skips the code generated comment at the top of the file. gopls disables edit related functionality for generated files, so the templ LSP may wish to skip generation of this comment so that gopls provides expected results.
func WithTimestamp ¶
func WithTimestamp(d time.Time) GenerateOpt
WithTimestamp enables the generated date to be included in the generated code.
func WithVersion ¶
func WithVersion(v string) GenerateOpt
WithVersion enables the version to be included in the generated code.
type GeneratorOptions ¶
type GeneratorOptions struct {
// Version of templ.
Version string
// FileName to include in error messages if string expressions return an error.
FileName string
// SkipCodeGeneratedComment skips the code generated comment at the top of the file.
SkipCodeGeneratedComment bool
// GeneratedDate to include as a comment.
GeneratedDate string
// PreTransforms are the names of enabled pre-generation transforms.
PreTransforms []string
}
type GeneratorOutput ¶
type GeneratorOutput struct {
Options GeneratorOptions `json:"meta"`
SourceMap *parser.SourceMap `json:"sourceMap"`
Literals []string `json:"literals"`
}
func Generate ¶
func Generate(template *parser.TemplateFile, w io.Writer, opts ...GenerateOpt) (op GeneratorOutput, err error)
Generate generates Go code from the input template file to w, and returns a map of the location of Go expressions in the template to the location of the generated Go code in the output.
type PreTransform ¶
type PreTransform func(tf *parser.TemplateFile) error
PreTransform mutates a parsed template before code generation.
func PreTransformByName ¶
func PreTransformByName(name string) (PreTransform, error)
PreTransformByName looks up a built-in pre-transform by name.
type RangeWriter ¶
type RangeWriter struct {
Current parser.Position
Literals []string
// contains filtered or unexported fields
}
func NewRangeWriter ¶
func NewRangeWriter(w io.Writer) *RangeWriter