Documentation
¶
Overview ¶
Package tmpl renders Go html/templates through Paper's HTML-to-PDF pipeline.
It provides a template input mode alongside Paper's component API and raw HTML conversion: html/template -> pkg/html rows -> generated PDF.
Index ¶
- func Render(ctx context.Context, templateStr string, data any, opts *Options) ([]core.Row, error)
- func RenderDocument(ctx context.Context, templateStr string, data any, opts *Options) (*core.Pdf, error)
- func RenderFile(ctx context.Context, templatePath string, data any, opts *Options, ...) error
- func RenderFileTo(ctx context.Context, w io.Writer, templatePath string, data any, opts *Options) error
- func RenderTo(ctx context.Context, w io.Writer, templateStr string, data any, opts *Options) error
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Render ¶
Render executes templateStr with data and converts the resulting HTML into Paper rows.
func RenderDocument ¶
func RenderDocument(ctx context.Context, templateStr string, data any, opts *Options) (*core.Pdf, error)
RenderDocument executes templateStr with data and returns a generated PDF.
func RenderFile ¶
func RenderFile(ctx context.Context, templatePath string, data any, opts *Options, outPath string) error
RenderFile reads a template from disk, executes it, and writes the PDF to outPath. Relative image and stylesheet references resolve against the template's directory unless HTMLOptions overrides those base directories.
Types ¶
type Options ¶
type Options struct {
// Funcs registers custom helpers for html/template. Custom helpers
// override built-in helpers with the same name.
Funcs htmltpl.FuncMap
// BaseTemplate is an optional pre-parsed template tree. Template strings
// are parsed into a clone of this tree so shared definitions are available
// without mutating the caller's template.
BaseTemplate *htmltpl.Template
// HTMLOptions are passed to pkg/html after template execution.
HTMLOptions []paperhtml.Option
// Config is the Paper document configuration used by RenderDocument,
// RenderTo, RenderFile, and RenderFileTo.
Config *entity.Config
}
Options configures template rendering. All fields are optional.