goblhtml

package module
v0.146.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: Apache-2.0 Imports: 16 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

gobl.html

Generate HTML files from GOBL documents.

Released under the Apache 2.0 LICENSE, Copyright 2024 Invopop Ltd..

Development

Generate Templates

GOBL HTML uses templ to define a set of components in Go. To generate the templates, run:

templ generate

Hot reload is very convenient to make changes and preview them quickly. There are two mechanisms we're currently using:

Air

Air is a great tool to auto reload potentially any project, but works great with Go. Install with:

go install github.com/air-verse/air@latest

The .toml is already configured and ready in this repository, so simply run:

air

Air is a bit more reliable at detecting file changes, especially for stylesheets. You'll always need to wait a few seconds before page reloads to give the system chance to recompile. A proxy is available with Air, but we didn't find it to be very reliable and was breaking with query parameters, it obviously also wouldn't work for PDF reloads.

Templ Watcher

Templ comes with a watch flag that can also be useful. However, it has the disadvantage of using .txt files for comparisons and the generated code should not be uploaded to git directly. Start the process with:

templ generate --watch --cmd="go run ./cmd/gobl.html serve --pdf prince"

Before uploading changes to git, be sure to re-run the regular templ generate command, as the live version makes temporary modifications to files that need to be replaced.

Testing

Tests are currently pretty limited. To ensure the basics are covered, the contents of the examples directory are converted to HTML, pretty printed, and output to the examples/out directory. The tests will ensure the output matches what's expected. To update the output test data run:

go test ./... --update

When adding new examples make sure to run:

go test examples_test.go --update

This will ensure the test file for that example is updated.

Documentation

Overview

Package goblhtml provides a simple way to render HTML documents from GOBL envelopes.

Index

Constants

This section is empty.

Variables

View Source
var EnableAdjustmentMode = func(o *internal.Opts) {
	o.AdjustmentMode = true
}

EnableAdjustmentMode indicates that invoice types credit-note and debit-note or similar should be rendered as adjustments to the original invoice, as required in certain jurisdictions. By default, this mode is disabled.

Functions

func HideKeys added in v0.138.0

func HideKeys() []string

HideKeys provides the list of section keys supported by WithHide.

func Render

func Render(ctx context.Context, env *gobl.Envelope, opts ...Option) ([]byte, error)

Render takes the GOBL envelope and attempts to render an HTML document from it.

Types

type Option

type Option func(*internal.Opts)

Option defines a configuration option to use for rendering.

func WithCalFormatter

func WithCalFormatter(date, timeFormat string, loc *time.Location) Option

WithCalFormatter prepares simple date and time formatting. The date and time formats are configured independently; date-time values render as "<date><sep><time>" using the provided formats. Pass an empty string to keep the ISO default for a given field.

func WithCurrencyTemplate added in v0.59.0

func WithCurrencyTemplate(val string) Option

WithCurrencyTemplate sets a custom template for determining the position of currency units in the formatted amounts. This will modify the currency's default formatter.

func WithDecimalMark added in v0.59.0

func WithDecimalMark(val string) Option

WithDecimalMark sets a custom decimal mark for formatting currency amounts. This will modify the currency's default formatter.

func WithEmbeddedAssets added in v0.38.0

func WithEmbeddedAssets() Option

WithEmbeddedAssets indicates that the stylesheets and scripts should be embedded inside the HTML document as opposed to links.

func WithHide added in v0.138.0

func WithHide(keys ...string) Option

WithHide hides the document sections identified by the provided keys using CSS. Hiding a key also hides all of its descendants, so hiding "payment" also hides "payment.terms". Unknown keys are ignored. See HideKeys for the complete list.

func WithLabel added in v0.52.0

func WithLabel(label string) Option

WithLabel indicates that the document should be rendered with the provided label

func WithLayout added in v0.26.0

func WithLayout(l layout.Code) Option

WithLayout indicates that the document should be rendered acording to the given Layout.

func WithLocale

func WithLocale(locale i18n.Code) Option

WithLocale sets the locale to use for rendering.

func WithLogo(logo *org.Image) Option

WithLogo overrides whatever logo was defined in the original envelope, if at all, using the provided logo according to the document type.

func WithNegativeTemplate added in v0.59.0

func WithNegativeTemplate(val string) Option

WithNegativeTemplate sets a custom negative template for formatting currency amounts. This will modify the currency's default formatter.

func WithNotes

func WithNotes(txt string) Option

WithNotes adds the provided string to the envelope notes.

func WithNumFormatter

func WithNumFormatter(nf num.Formatter) Option

WithNumFormatter defines a customer number formatter to use instead of that provided by default for the currency.

func WithSandbox added in v0.52.0

func WithSandbox(sandbox bool) Option

WithSandbox indicates that the document should be rendered in sandbox mode

func WithThousandsSeparator added in v0.59.0

func WithThousandsSeparator(val string) Option

WithThousandsSeparator sets a custom thousands separator for formatting currency amounts. This will modify the currency's default formatter.

func WithVoid added in v0.35.0

func WithVoid(void bool) Option

WithVoid indicates that the document is marked as void and should be rendered accordingly.

func WithWatermark added in v0.52.0

func WithWatermark(watermark string) Option

WithWatermark indicates that the document should be rendered with the provided watermark

type Warning added in v0.142.0

type Warning = internal.Warning

Warning flags information that a tax authority requires on the rendered document but which the source document does not provide, such as the recipient's identity on an Australian tax invoice of 1,000 AUD or more. Rendering still goes ahead; warnings are advisory.

func Warnings added in v0.142.0

func Warnings(env *gobl.Envelope) []Warning

Warnings reports the information missing from the envelope's document that a tax authority requires on the rendered output. Nothing is printed on the document itself: callers decide how to surface them, e.g. by logging or attaching them to the rendering job.

Directories

Path Synopsis
Package assets contains the static resources for things like styles.
Package assets contains the static resources for things like styles.
cmd
gobl.html command
Package main provides the entry point for the gobl.html command-line tool.
Package main provides the entry point for the gobl.html command-line tool.
Package components defines all the templ components that will be used to render GOBL envelopes.
Package components defines all the templ components that will be used to render GOBL envelopes.
bill
Package bill provides templates for rendering objects from GOBL's `bill` package.
Package bill provides templates for rendering objects from GOBL's `bill` package.
images
templ: version: v0.3.1001
templ: version: v0.3.1001
note
templ: version: v0.3.1001
templ: version: v0.3.1001
org
templ: version: v0.3.1001
templ: version: v0.3.1001
regimes/ar
Package ar provides additional templates and helper methods for the Argentine tax regime.
Package ar provides additional templates and helper methods for the Argentine tax regime.
regimes/au
Package au defines extra output for Australian invoices so that the rendered document meets the ATO's information requirements for tax invoices (s 29-70 GST Act, GSTR 2013/1) and adjustment notes (Adjustment Note Information Requirements Determination 2022).
Package au defines extra output for Australian invoices so that the rendered document meets the ATO's information requirements for tax invoices (s 29-70 GST Act, GSTR 2013/1) and adjustment notes (Adjustment Note Information Requirements Determination 2022).
regimes/co
Package co provides additional output for Colombian invoices.
Package co provides additional output for Colombian invoices.
regimes/es
Package es provides additional templates and helper methods for the Spanish tax regime.
Package es provides additional templates and helper methods for the Spanish tax regime.
regimes/gr
Package gr provides additional templates and helper methods for the Greek tax regime.
Package gr provides additional templates and helper methods for the Greek tax regime.
regimes/it
Package it provides additional output for Italian invoices.
Package it provides additional output for Italian invoices.
regimes/mx
templ: version: v0.3.1001
templ: version: v0.3.1001
regimes/pl
templ: version: v0.3.1001
templ: version: v0.3.1001
regimes/pt
templ: version: v0.3.1001
templ: version: v0.3.1001
regimes/ro
templ: version: v0.3.1001
templ: version: v0.3.1001
regimes/sa
Package sa defines extra output for Saudi Arabian invoices.
Package sa defines extra output for Saudi Arabian invoices.
regimes/sg
Package sg provides additional output for Singaporean invoices.
Package sg provides additional output for Singaporean invoices.
t
templ: version: v0.3.1001
templ: version: v0.3.1001
taxid
Package taxid formats tax identities according to the way each country officially presents them on invoices.
Package taxid formats tax identities according to the way each country officially presents them on invoices.
utils
Package utils provides utility functions for the components package.
Package utils provides utility functions for the components package.
Package internal is used for internal option configuration.
Package internal is used for internal option configuration.
gallery
Package gallery builds examples/index.html: scan examples/*.json, locale hints, embed catalog.html.
Package gallery builds examples/index.html: scan examples/*.json, locale hints, embed catalog.html.
Package layout provides all the possible layouts for a document.
Package layout provides all the possible layouts for a document.
Package locales provides all the content for translations.
Package locales provides all the content for translations.
pkg
pdf
Package pdf provides a wrapper around different PDF generation tools to provide single conversion process regardless of implementation.
Package pdf provides a wrapper around different PDF generation tools to provide single conversion process regardless of implementation.

Jump to

Keyboard shortcuts

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