Documentation
¶
Overview ¶
Package config loads the ghtmx project configuration (ghtmx.json at the module root) and applies the flag > file > default precedence (FR-070, FR-071, FR-072, FR-073).
The file is optional: a conventional project works with no configuration at all. An invalid key or value produces a positioned error naming the offending key.
Index ¶
Constants ¶
const DefaultHtmxVersion = "2.0.10"
DefaultHtmxVersion is the pinned htmx version used when none is configured. It must be one of the versions embedded in the htmx surface set.
const DefaultTemplateExtension = ".ghtmx"
DefaultTemplateExtension is the canonical template file extension.
const FileName = "ghtmx.json"
FileName is the configuration file name looked up at the module root.
Variables ¶
var TemplateExtensions = []string{DefaultTemplateExtension, ".htmx"}
TemplateExtensions are the extensions a project may configure. The set is closed on purpose: the generator would consume its own output if it walked ".go", and an unrecognised extension is far more likely a typo than an intent, so it is worth rejecting by name.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// HtmxVersion is the pinned htmx version driving attribute validation
// and the script-inclusion helper.
HtmxVersion string `json:"htmxVersion"`
// SourceDirs are the template source directories, relative to the module
// root.
SourceDirs []string `json:"sourceDirs"`
// RouteScope is the list of Go package patterns scanned by route
// discovery.
RouteScope []string `json:"routeScope"`
// GeneratedPackage is where route constructors and event emitters are
// emitted.
GeneratedPackage GeneratedPackage `json:"generatedPackage"`
// GeneratedSuffix is the file-name suffix replacing the template
// extension on generated Go files. Dev-mode hot reload of text literals
// requires the default.
GeneratedSuffix string `json:"generatedSuffix"`
// TemplateExtension is the file extension templates are written with.
// A project uses exactly one: files with the other extension are not
// templates as far as the toolchain is concerned.
TemplateExtension string `json:"templateExtension"`
// Checks overrides the severity of warning-class checks by stable
// diagnostic ID: "error", "warning", or "off".
Checks map[string]diag.Severity `json:"checks"`
// StrictTargets promotes the dangling swap target warning
// (GHTMX-W0201) to an error (FR-042).
StrictTargets bool `json:"strictTargets"`
// HtmxScript controls whether the central generated package emits the
// HTMXScript() helper. Nil means true. False supports projects that use
// ghtmx purely as a server-side template engine and load no htmx at
// all; HtmxVersion keeps driving attribute validation regardless.
HtmxScript *bool `json:"htmxScript"`
}
Config is the resolved project configuration.
func Default ¶
func Default() Config
Default returns the documented defaults (FR-072): a conventional project needs no configuration file.
func Load ¶
Load reads the configuration file from dir. A missing file is not an error: the defaults are returned (FR-072). An unparseable file, unknown key, or invalid value produces a positioned error naming the offending key (FR-070).
func Parse ¶
Parse decodes configuration content, validating keys and values with positioned errors. An empty or whitespace-only file behaves like a missing file: the defaults apply.
func Resolve ¶
Resolve applies precedence flag > file > default and returns the effective configuration.
func (Config) EmitHtmxScript ¶ added in v0.1.9
EmitHtmxScript reports whether the generated central package should include the HTMXScript() helper: true unless htmxScript is explicitly false.
func (Config) Hash ¶
Hash returns a stable content hash of the configuration, used to salt the build cache key so a configuration change invalidates generated output. Semantically identical configs hash identically: a nil Checks map is canonicalized before encoding, and json.Marshal sorts map keys.
func (Config) SeverityOverrides ¶
SeverityOverrides returns the effective per-check severity overrides, folding StrictTargets into the map.
type Flags ¶
type Flags struct {
HtmxVersion *string
SourceDirs []string
RouteScope []string
GeneratedPkgDir *string
GeneratedPkgName *string
GeneratedSuffix *string
TemplateExtension *string
StrictTargets *bool
HtmxScript *bool
CheckSeverities map[string]diag.Severity
}
Flags holds CLI flag values that override file configuration (FR-073). A nil pointer means the flag was not set.
type GeneratedPackage ¶
type GeneratedPackage struct {
// Dir is the directory of the generated package, relative to the module
// root.
Dir string `json:"dir"`
// Name is the Go package name.
Name string `json:"name"`
}
GeneratedPackage identifies the central generated package that receives route constructors and event emitters (solution design D5).