Documentation
¶
Overview ¶
Package tmpl holds the template model of doc/template.md: the node tree a KDL document parses into, and the validation that runs once at load, before any data is read.
Index ¶
- Variables
- func ForEachSection(report *Report, fn func(*Section))
- type Arg
- type Barcode
- type Body
- type CalcMode
- type Color
- type Columns
- type Common
- type Content
- type Dash
- type DataBlob
- type Diagnostic
- type DiagnosticList
- type Eject
- type EjectType
- type Element
- type Embedded
- type Field
- type Font
- type Group
- type Image
- type Layout
- type Line
- type Outline
- type Parameter
- type RecordMember
- type Records
- type Rectangle
- type Report
- type ScaleMode
- type Scope
- type Section
- type SectionKind
- type Style
- type Subreport
- type TextAlign
- type ValueType
- type Variable
- type Xref
Constants ¶
This section is empty.
Variables ¶
var BarcodeTypes = map[string]bool{ "Code128": true, "Code39": true, "Code93": true, "2of5i": true, "DataMatrix": true, "Aztec": true, "QR-L": true, "QR-M": true, "QR-Q": true, "QR-H": true, }
BarcodeTypes lists the symbologies the format accepts.
Functions ¶
func ForEachSection ¶
ForEachSection visits every band in the report, including those in embedded layouts.
Types ¶
type Barcode ¶
type Barcode struct {
Common
Content
Type string
Module float64
Vertical bool
Grow bool
Ink *Color
Paper *Color
}
Barcode draws a symbol.
Ink and Paper are the barcode's own, and are deliberately not taken from the style: a style's colour falls through from every enclosing scope, so a layout that colours its text would otherwise recolour every symbol under it and change what scans.
type Body ¶
type Body struct {
Title *Section
Summary *Section
Header *Section
Columns *Columns
Group *Group
Detail *Section
}
Body is the part of a layout that band containers share: the optional bands, an optional columns block, and exactly one of group or detail.
type CalcMode ¶
type CalcMode int
CalcMode is a variable's accumulation mode.
const ( CalcFirst CalcMode = iota CalcLast CalcCount CalcList CalcSet CalcChain CalcSum CalcAvg CalcMin CalcMax CalcStd CalcVar )
Accumulation modes.
type Color ¶
type Color struct {
Red, Green, Blue uint8
}
Color is an RGB colour. The canonical form, and what a printout carries, is always "#RRGGBB".
func ParseColor ¶
ParseColor accepts "#RRGGBB", a name, three comma-separated components as integers 0-255 or floats 0-1, or a single packed integer.
type Columns ¶
type Columns struct {
Count int
Gap float64
// Balance spreads the frame's last fragment over the columns it reached,
// so that they end at similar heights instead of the last one running short.
Balance bool
Styles []*Style
Header *Section
Node *kdl.Node
}
Columns splits the enclosing frame.
type Common ¶
type Common struct {
Horiz geom.Extent
Vert geom.Extent
HAlign geom.HAlign
VAlign geom.VAlign
Float bool
PrintWhen *expr.Program
Styles []*Style
Node *kdl.Node
}
Common holds what every body element and xref carries.
type Content ¶
type Content struct {
Expr *expr.Program
Text string
HasText bool
Data string
EvalTime string
Format string
}
Content is where a field's or barcode's text comes from.
func (*Content) Deferred ¶
Deferred reports whether the element's expression is evaluated at the end of a scope rather than where the element sits.
func (*Content) HasPlaceholder ¶
HasPlaceholder reports whether a deferred element carries content to be measured from before its value is known.
type DataBlob ¶
type DataBlob struct {
Name string
Encoding string
Compress string
Expr *expr.Program
Content string
HasBody bool
Node *kdl.Node
}
DataBlob is a named literal blob.
type Diagnostic ¶
Diagnostic is one validation message.
Every one names the file, the node path, and, where the fault is in a property rather than in the node, the property.
type DiagnosticList ¶
type DiagnosticList []Diagnostic
DiagnosticList is a set of validation messages.
func (DiagnosticList) Error ¶
func (diags DiagnosticList) Error() string
Error renders every diagnostic, one per line.
type Element ¶
type Element interface {
Base() *Common
// Kind names the element for diagnostics and for the printout.
Kind() string
}
Element is a body element or an xref.
type Embedded ¶
type Embedded struct {
Name string
Params []*Parameter
Records *Records
Variables []*Variable
Styles []*Style
Body Body
Embedded []*Embedded
ParamByName map[string]*Parameter
VarByName map[string]*Variable
GroupNames []string
Node *kdl.Node
}
Embedded is a subreport layout defined inline.
type Field ¶
type Field struct {
Common
Content
Align TextAlign
// HasAlign records whether the template wrote align,
// which is what lets halign supply the alignment when it did not.
HasAlign bool
Stretch bool
}
Field is text.
type Font ¶
type Font struct {
Name string
Typeface string
File string
Data string
Size int
Bold bool
Italic bool
Underline bool
Node *kdl.Node
}
Font is a named font definition.
type Group ¶
type Group struct {
Name string
Expr *expr.Program
KeepTogether bool
MinRows int
MinTailRows int
Styles []*Style
Title *Section
Summary *Section
Columns *Columns
Group *Group
Detail *Section
Node *kdl.Node
}
Group is a data-driven grouping level.
type Image ¶
type Image struct {
Common
File string
Data string
Content string
HasContent bool
Type string
Scale ScaleMode
Proportional bool
Embed bool
}
Image draws a bitmap.
type Layout ¶
type Layout struct {
Page geom.PageSize
Landscape bool
LeftMargin float64
RightMargin float64
TopMargin float64
BottomMargin float64
Styles []*Style
Embedded []*Embedded
Body Body
Node *kdl.Node
}
Layout is page geometry and the root of the band tree.
type Outline ¶
type Outline struct {
Title *expr.Program
Level int
Name *expr.Program
When *expr.Program
Closed bool
Node *kdl.Node
}
Outline is a document outline entry.
type Parameter ¶
type Parameter struct {
Name string
Type ValueType
Default string
HasDefault bool
DefaultExpr *expr.Program
Format string
Prompt bool
Node *kdl.Node
}
Parameter is a value supplied by the caller.
type RecordMember ¶
RecordMember declares one member of the input records, from a `member` node.
Neither Column nor Field: a Column is an area on the page and a Field is a band element that prints a value, and this package holds all three.
type Records ¶
type Records struct {
Members []*RecordMember
ByName map[string]*RecordMember
Node *kdl.Node
}
Records declares the members of the input records.
type Report ¶
type Report struct {
File string
BaseDir string
Name string
Description string
Version string
Author string
Params []*Parameter
Records *Records
Variables []*Variable
Fonts []*Font
Data []*DataBlob
Layout *Layout
ParamByName map[string]*Parameter
VarByName map[string]*Variable
FontByName map[string]*Font
DataByName map[string]*DataBlob
GroupNames []string
// Warnings are load-time diagnostics that do not stop a build.
Warnings DiagnosticList
Node *kdl.Node
}
Report is the root of a template.
func Load ¶
Load reads and validates a template file.
A `subreport template=` names another template, which is read here too: one call loads the whole tree, so a build never touches the filesystem for a document it has not already validated.
func LoadString ¶
LoadString reads and validates a template from a string. The name is used in diagnostics and as the base for relative paths.
type Section ¶
type Section struct {
Kind SectionKind
Height geom.Opt // unset means height="auto"
PrintWhen *expr.Program
Split bool
Orphans int
Widows int
SwapHeader bool
Styles []*Style
Ejects []*Eject
Outlines []*Outline
Elements []Element
Subreports []*Subreport
Node *kdl.Node
}
Section is one band.
type SectionKind ¶
type SectionKind int
SectionKind names one of the five bands.
const ( BandTitle SectionKind = iota BandSummary BandHeader BandDetail )
Band kinds.
type Style ¶
type Style struct {
When *expr.Program
Font string
HasFont bool
Color *Color
BgColor *Color
Node *kdl.Node
}
Style is conditional formatting.
type Subreport ¶
type Subreport struct {
Template string
// Report is the template named by Template, loaded with this one.
// Nil for a subreport that names an embedded layout instead.
Report *Report
Embedded string
// EmbeddedLayout is the layout Embedded names, resolved at load against
// the scope this node is written in. Nil for a subreport naming a file.
//
// Resolving once, at load, is what keeps validation and the engine
// from answering one name differently.
EmbeddedLayout *Embedded
Seq int
Data *expr.Program
When *expr.Program
Inline bool
OwnPageNo bool
Args []*Arg
DocOrder int
Node *kdl.Node
}
Subreport runs another template over a nested sequence.
type ValueType ¶
type ValueType int
ValueType is a declared parameter or record member type.
const ( TypeString ValueType = iota TypeInt TypeDecimal TypeFloat TypeBool TypeDatetime TypeDate TypeObject TypeList )
Declared value types.
func (ValueType) IsTemporal ¶
IsTemporal reports whether the type is date or datetime, which are the two that accept a `format` parsing layout.