decorator

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 11, 2026 License: MIT Imports: 6 Imported by: 0

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

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMetrics

func NewMetrics(inner core.Paper) core.Paper

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

func (m *Metrics) AddAutoRow(cols ...core.Col) core.Row

AddAutoRow decorates the AddAutoRow method of paper instance.

func (*Metrics) AddHTML

func (m *Metrics) AddHTML(ctx context.Context, htmlStr string) error

AddHTML decorates the AddHTML method of paper instance.

func (*Metrics) AddPages

func (m *Metrics) AddPages(pages ...core.Page)

AddPages decorates the AddPages method of paper instance.

func (*Metrics) AddRow

func (m *Metrics) AddRow(rowHeight float64, cols ...core.Col) core.Row

AddRow decorates the AddRow method of paper instance.

func (*Metrics) AddRows

func (m *Metrics) AddRows(rows ...core.Row)

AddRows decorates the AddRows method of paper instance.

func (*Metrics) FitInCurrentPage

func (m *Metrics) FitInCurrentPage(heightNewLine float64) bool

FitInCurrentPage decorates the FitInCurrentPage method of paper instance.

func (*Metrics) Generate

func (m *Metrics) Generate(ctx context.Context) (*core.Pdf, error)

Generate decorates the Generate method of paper instance.

func (*Metrics) GetCurrentConfig

func (m *Metrics) GetCurrentConfig() *entity.Config

GetCurrentConfig decorates the GetCurrentConfig method of paper instance.

func (*Metrics) GetStructure

func (m *Metrics) GetStructure() *node.Node[core.Structure]

GetStructure decorates the GetStructure method of paper instance.

func (*Metrics) RegisterFooter

func (m *Metrics) RegisterFooter(rows ...core.Row) error

RegisterFooter decorates the RegisterFooter method of paper instance.

func (*Metrics) RegisterHeader

func (m *Metrics) RegisterHeader(rows ...core.Row) error

RegisterHeader decorates the RegisterHeader method of paper instance.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL