Documentation
¶
Overview ¶
Package templatefmt formats tinybind template sources.
It is the library entry point for requirement:template-source-formatting: the fmt subcommand is a thin wrapper over it, so an editor plugin, a build step, or a framework's own tooling needs no CLI process. Formatting is a pure function of a source and a set of options; nothing here reads or writes the filesystem except Dir, which exists because "format this package" is the request everything else is built from.
Index ¶
Constants ¶
const ( DefaultHTMLPattern = "*.tb.html" DefaultSQLPattern = "*.tb.sql" DefaultDynamoPattern = dynamobind.DefaultTemplatePattern DefaultFirestorePattern = firestorebind.DefaultTemplatePattern )
Default file patterns, matching the generator's own discovery defaults.
const DefaultWidth = syntax.DefaultWidth
DefaultWidth is the soft line width used when Options.Width is zero.
Variables ¶
var ErrUnknownFormat = errors.New("templatefmt: file name matches no template pattern")
ErrUnknownFormat reports a file name that matches no template pattern.
Functions ¶
Types ¶
type Format ¶
type Format string
Format identifies one template language.
const ( // HTML is the .tb.html component language. HTML Format = "html" // SQL is the .tb.sql statement language. SQL Format = "sql" // Dynamo is the .tb.dynamo access-pattern language. Dynamo Format = "dynamo" // Firestore is the .tb.firestore access-pattern language. Firestore Format = "firestore" )
type Options ¶
type Options struct {
// Width is the soft line width; zero uses DefaultWidth. It is soft because a
// construct that cannot break without changing meaning stays long.
Width int
// Indent is one indentation level; empty uses two spaces.
Indent string
// PreserveWhitespace mirrors the generator option of the same name. With it
// set, generation no longer collapses static whitespace, so HTML layout is
// restricted to the positions the HTML parser discards runs from.
PreserveWhitespace bool
// HTMLPattern, SQLPattern, DynamoPattern and FirestorePattern are base-name
// globs used by Dir and by Source when it identifies a file. Empty values
// use the defaults.
HTMLPattern string
SQLPattern string
DynamoPattern string
FirestorePattern string
}
Options configures formatting. The zero value is valid and uses every default, so templatefmt.Source(name, src, templatefmt.Options{}) is the whole API for the common case.
type Result ¶
type Result struct {
Path string
Format Format
// Source is the file as it was read.
Source []byte
// Formatted is the canonical form. It is nil when Err is set, because a
// source that does not parse is left exactly as it is.
Formatted []byte
// Changed reports that Formatted differs from Source.
Changed bool
// Err is the parse or print failure for this file. Other files in the same
// run are unaffected.
Err error
}
Result is the outcome for one file.