templatex

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package templatex provides useful helper to compile and write template to file.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrTemplate describes error with template compilation.
	ErrTemplate = errors.New("template error")
	// ErrFormatting describes error with formatting.
	ErrFormatting = errors.New("formatting error")
)

Functions

func WithFormat

func WithFormat(o *Options)

WithFormat enables formatting after writing.

Types

type Option

type Option func(*Options)

Option describes template option.

func WithData

func WithData(data map[string]any) Option

WithData sets template data.

func WithFs

func WithFs(fs afero.Fs) Option

WithFs sets custom fs.

type Options

type Options struct {
	Fs     afero.Fs
	Format bool
	Data   map[string]any
}

Options describes options.

type Template

type Template struct {
	// contains filtered or unexported fields
}

Template describes template.

func Parse

func Parse(s string) *Template

Parse returns new Template.

func (*Template) Save

func (t *Template) Save(file string, opts ...Option) error

Save compiles template and writes result to specified file.

Jump to

Keyboard shortcuts

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