templdocx

package module
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2025 License: Apache-2.0 Imports: 11 Imported by: ? modules, 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

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) GetVar added in v0.0.3

func (c *Context) GetVar(name string) (any, error)

func (*Context) ParseVar added in v0.0.3

func (c *Context) ParseVar(name string, params ...string) (any, error)

func (*Context) SkipTillControlEnd

func (c *Context) SkipTillControlEnd() error

SkipTillControlEnd reads doc till the end of the 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
⌂ 换网址