goblhtml

package module
v0.17.1 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

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

During development, it can help massive to have hot reload to be able to make changes and see 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 obvously also wouldn't work for PDF reloads.

Templ Watcher

Templ comes with a watch flag that can also be useful. It has the disadvantage however that it uses .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 is as expected. To update the output test data run:

go test ./... --update

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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, dateTime string, loc *time.Location) Option

WithCalFormatter prepares simple date and datetime formatting.

func WithEmbeddedStylesheets added in v0.6.0

func WithEmbeddedStylesheets() Option

WithEmbeddedStylesheets indicates that the stylesheets should be embedded inside the HTML document as opposed to links.

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 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.

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
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/invoice
templ: version: v0.2.747
templ: version: v0.2.747
images
templ: version: v0.2.747
templ: version: v0.2.747
notes
templ: version: v0.2.747
templ: version: v0.2.747
org
templ: version: v0.2.747
templ: version: v0.2.747
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/mx
templ: version: v0.2.747
templ: version: v0.2.747
regimes/pl
templ: version: v0.2.747
templ: version: v0.2.747
regimes/pt
templ: version: v0.2.747
templ: version: v0.2.747
t
templ: version: v0.2.747
templ: version: v0.2.747
Package internal is used for internal option configuration.
Package internal is used for internal option configuration.
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