templdocx

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

README

templdocx

Simple library to generate docx files from templates

It depends on github.com/fumiama/go-docx. Allows to use go templates and control instructions (loop) for tables or body (see example for sample usage)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotInControlContext       = errors.New("not in control context")
	ErrInvalidControlContext     = errors.New("invalid control context")
	ErrNoClosingCommandFound     = errors.New("no closing command found")
	ErrUnsupportedCommandContext = errors.New("unsupported command context")
	ErrCommandResultError        = errors.New("command result error")
	ErrVarNotFound               = errors.New("variable not found")
	FuncVarNotFound              = errors.New("function not found")
)

Functions

func FSDrawableProvider

func FSDrawableProvider(ctx *Context, params []string) ([]byte, error)

Types

type Context

type Context struct {
	Processor  *DocProcessor
	ObjectType DocObject
	Parent     *Context
	Index      int
	//docx corresponding object
	Item any
	Vars any
	// contains filtered or unexported fields
}

func (*Context) SkipTillControlEnd

func (c *Context) SkipTillControlEnd() error

SkipTillControlEnd reads dic till the end of current command

type ControlContext

type ControlContext struct {
	Items         []any
	Parent        any
	FirstItemIdx  int
	LastItemIdx   int
	ControlName   string
	ControlObject ControlObject
}

type ControlObject

type ControlObject interface {
	IsTheSame(co ControlObject) bool
	IsClosing(co *ControlTypeEnd) bool
	IsClosed() bool
	AddParam(string) error
	Execute(ctx *Context) ([]any, error)
	Describe() string
}

type ControlTypeDrawing

type ControlTypeDrawing struct {
	Provider DrawableProvider
	// contains filtered or unexported fields
}

func (*ControlTypeDrawing) AddParam

func (c *ControlTypeDrawing) AddParam(s string) error

func (*ControlTypeDrawing) Describe

func (c *ControlTypeDrawing) Describe() string

func (*ControlTypeDrawing) Execute

func (c *ControlTypeDrawing) Execute(ctx *Context) ([]any, error)

func (*ControlTypeDrawing) IsClosed

func (c *ControlTypeDrawing) IsClosed() bool

func (*ControlTypeDrawing) IsClosing

func (c *ControlTypeDrawing) IsClosing(co *ControlTypeEnd) bool

func (*ControlTypeDrawing) IsTheSame

func (c *ControlTypeDrawing) IsTheSame(co ControlObject) bool

type ControlTypeEnd

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

type CustomControlProvider

type CustomControlProvider func(name string) ControlObject

type DocObject

type DocObject int
const (
	DOBody DocObject = iota
	DOParagraph
	DOTable
	DOTableRow
	DOTableCell
	DOControl
)

type DocProcessor

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

func NewDocParser

func NewDocParser(doc *docx.Docx, values any, options ...any) *DocProcessor

func (*DocProcessor) Process

func (dp *DocProcessor) Process() error

type DrawableProvider

type DrawableProvider func(ctx *Context, params []string) ([]byte, error)

type Error

type Error struct {
	TemplateError error
	Message       string
	Position      string
	Token         string
}

func (Error) Error

func (e Error) Error() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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