Documentation
¶
Overview ¶
Package decorator provides decorators over the core.Paper interface.
It lives in its own package (rather than the root paper package) because it depends only on the core.Paper interface and pulls in pkg/metrics — keeping it here avoids coupling the root package to metrics and sidesteps the pkg/core -> pkg/metrics import direction.
Index ¶
- func NewMetrics(inner core.Paper) core.Paper
- type Metrics
- func (m *Metrics) AddAutoRow(cols ...core.Col) core.Row
- func (m *Metrics) AddHTML(ctx context.Context, htmlStr string) error
- func (m *Metrics) AddPages(pages ...core.Page)
- func (m *Metrics) AddRow(rowHeight float64, cols ...core.Col) core.Row
- func (m *Metrics) AddRows(rows ...core.Row)
- func (m *Metrics) FitInCurrentPage(heightNewLine float64) bool
- func (m *Metrics) Generate(ctx context.Context) (*core.Pdf, error)
- func (m *Metrics) GetCurrentConfig() *entity.Config
- func (m *Metrics) GetStructure() *node.Node[core.Structure]
- func (m *Metrics) RegisterFooter(rows ...core.Row) error
- func (m *Metrics) RegisterHeader(rows ...core.Row) error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewMetrics ¶
NewMetrics creates a metrics-recording decorator around the given paper instance.
Example ¶
ExampleNewMetrics demonstrates how to wrap a paper instance with the metrics decorator.
package main
import (
"context"
"fmt"
"github.com/avdoseferovic/paper"
"github.com/avdoseferovic/paper/pkg/config"
"github.com/avdoseferovic/paper/pkg/decorator"
)
func main() {
// optional
b := config.NewBuilder()
cfg := b.Build()
mrt := paper.New(cfg) // cfg is an optional
m := decorator.NewMetrics(mrt) // decorator of paper
// Do things and generate
_, _ = m.Generate(context.Background())
fmt.Println("generated")
}
Output: generated
Types ¶
type Metrics ¶
type Metrics struct {
// contains filtered or unexported fields
}
Metrics is a core.Paper decorator that records timing metrics for each decorated operation and attaches a metrics.Report to the generated document.
func (*Metrics) AddAutoRow ¶
AddAutoRow decorates the AddAutoRow method of paper instance.
func (*Metrics) FitInCurrentPage ¶
FitInCurrentPage decorates the FitInCurrentPage method of paper instance.
func (*Metrics) GetCurrentConfig ¶
GetCurrentConfig decorates the GetCurrentConfig method of paper instance.
func (*Metrics) GetStructure ¶
GetStructure decorates the GetStructure method of paper instance.
func (*Metrics) RegisterFooter ¶
RegisterFooter decorates the RegisterFooter method of paper instance.