internal

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	T_TAG        = "w:t"
	R_TAG        = "w:r"
	P_TAG        = "w:p"
	RPR_TAG      = "w:rPr"
	TBL_TAG      = "w:tbl"
	TR_TAG       = "w:tr"
	TC_TAG       = "w:tc"
	DOCPR_TAG    = "wp:docPr"
	VSHAPE_TAG   = "v:shape"
	ALTCHUNK_TAG = "w:altChunk"
)
View Source
const (
	TEMPLATE_PATH                 = "word"
	CONTENT_TYPES_PATH            = "[Content_Types].xml"
	DEFAULT_LITERAL_XML_DELIMITER = "||"
)

Variables

View Source
var (
	IncompleteConditionalStatementError = errors.New("IncompleteConditionalStatementError")
	IgnoreError                         = errors.New("ignore")
	BUILT_IN_COMMANDS                   = []string{
		"CMD_NODE",
		"ALIAS",
		"FOR",
		"END-FOR",
		"IF",
		"END-IF",
		"INS",
		"IMAGE",
		"LINK",
		"HTML",
	}
)
View Source
var BufferKeys []string = []string{P_TAG, TR_TAG, TC_TAG}
View Source
var ImageExtensions []string = []string{
	".png",
	".gif",
	".jpg",
	".jpeg",
	".svg",
}

Functions

func BuildXml

func BuildXml(node Node, options XmlOptions, indent string) []byte

func ProcessHtmls

func ProcessHtmls(htmls Htmls, documentComponent string, zip *ZipArchive) error

func ProcessImages

func ProcessImages(images Images, documentComponent string, zip *ZipArchive) error
func ProcessLinks(links Links, documentComponent string, zip *ZipArchive) error

func ZipClone

func ZipClone(reader *zip.ReadCloser, writer *zip.Writer, except []string) error

func ZipGetText

func ZipGetText(z *zip.ReadCloser, filename string) (string, error)

func ZipSet

func ZipSet(z *zip.Writer, filename string, data []byte) error

Types

type BaseNode

type BaseNode struct {
	ParentNode Node
	ChildNodes []Node
	NodeName   string
}

func (*BaseNode) AddChild

func (n *BaseNode) AddChild(node Node)

func (*BaseNode) Children

func (n *BaseNode) Children() []Node

func (*BaseNode) Name

func (n *BaseNode) Name() string

func (*BaseNode) Parent

func (n *BaseNode) Parent() Node

func (*BaseNode) PopChild

func (n *BaseNode) PopChild()

func (*BaseNode) SetChildren

func (n *BaseNode) SetChildren(children []Node)

func (*BaseNode) SetName

func (n *BaseNode) SetName(name string)

func (*BaseNode) SetParent

func (n *BaseNode) SetParent(node Node)

type BufferStatus

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

type CommandProcessor

type CommandProcessor func(data *ReportData, node Node, ctx *Context) (string, error)

type Context

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

func NewContext

func NewContext(options CreateReportOptions, imageAndShapeIdIncrement int) Context

type CreateReportOptions

type CreateReportOptions struct {
	CmdDelimiter        *Delimiters
	LiteralXmlDelimiter string
	ProcessLineBreaks   bool
	//noSandbox          bool
	//runJs              RunJSFunc
	//additionalJsContext Object
	FailFast                   bool
	RejectNullish              bool
	ErrorHandler               ErrorHandler
	FixSmartQuotes             bool
	ProcessLineBreaksAsNewText bool
	MaximumWalkingDepth        int
	Functions                  Functions
}

type Delimiters

type Delimiters struct {
	Open  string
	Close string
}

type ErrorHandler

type ErrorHandler = func(err error, rawCode string) string

type Function

type Function func(args ...any) VarValue

type FunctionNotFoundError

type FunctionNotFoundError struct {
	FunctionName string
}

func (*FunctionNotFoundError) Error

func (e *FunctionNotFoundError) Error() string

type Functions

type Functions map[string]Function

type Htmls

type Htmls map[string]string

type Image

type Image struct {
	Extension string // [".png", ".gif", ".jpg", ".jpeg", ".svg"]
	Data      []byte
}

type ImagePars

type ImagePars struct {
	Extension string // [".png", ".gif", ".jpg", ".jpeg", ".svg"]
	Data      []byte
	Width     float32
	Height    float32
	Thumbnail *Thumbnail // optional
	Alt       string     // optional
	Rotation  int        // optional
	Caption   string     // optional
}

type Images

type Images map[string]*Image

type InvalidCommandError

type InvalidCommandError struct {
	Message string
	Command string
}

func NewInvalidCommandError

func NewInvalidCommandError(message, command string) *InvalidCommandError

func (*InvalidCommandError) Error

func (e *InvalidCommandError) Error() string

Implémenter l'interface error pour InvalidCommandError

type KeyNotFoundError

type KeyNotFoundError struct {
	Key string
}

func (*KeyNotFoundError) Error

func (e *KeyNotFoundError) Error() string
type Link struct {
	// contains filtered or unexported fields
}

type LinkPars added in v1.1.0

type LinkPars struct {
	Url   string
	Label string
}
type Links map[string]Link

type LoopStatus

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

type Node

type Node interface {
	Parent() Node
	SetParent(Node)
	Children() []Node
	SetChildren([]Node)
	PopChild()
	AddChild(Node)
	Name() string
	SetName(string)
}

func AddChild

func AddChild(parent Node, child Node) Node

func CloneNodeWithoutChildren

func CloneNodeWithoutChildren(node Node) Node

CloneNodeWithoutChildren crée une copie d'un noeud sans ses enfants

func ParseXml

func ParseXml(templateXml string) (Node, error)

func PreprocessTemplate

func PreprocessTemplate(root Node, delimiter Delimiters) (Node, error)

type NonTextNode

type NonTextNode struct {
	BaseNode
	Tag   string
	Attrs map[string]string
}

func NewNonTextNode

func NewNonTextNode(tag string, attrs map[string]string, children []Node) *NonTextNode

type ParseTemplateResult

type ParseTemplateResult struct {
	Root         Node
	MainDocument string
	Zip          *ZipArchive
	ContentTypes *NonTextNode
	Extras       map[string]Node // [path]Node
}

func ParseTemplate

func ParseTemplate(zip *ZipArchive) (*ParseTemplateResult, error)

type ReportData

type ReportData map[string]any

func (ReportData) GetArray

func (rd ReportData) GetArray(key string) ([]any, bool)

func (ReportData) GetImage

func (rd ReportData) GetImage(key string) (*ImagePars, bool)

func (ReportData) GetValue

func (rd ReportData) GetValue(key string) (VarValue, bool)

type ReportOutput

type ReportOutput struct {
	Report Node
	Images Images
	Links  Links
	Htmls  Htmls
}

func ProduceReport

func ProduceReport(data *ReportData, template Node, ctx Context) (*ReportOutput, error)

type TextNode

type TextNode struct {
	BaseNode
	Text string
}

func InsertTextSiblingAfter

func InsertTextSiblingAfter(textNode *TextNode) (*TextNode, error)

InsertTextSiblingAfter crée et insère un nouveau noeud texte après le noeud texte donné Retourne le nouveau noeud texte ou une erreur si les conditions ne sont pas remplies

func NewTextNode

func NewTextNode(text string) *TextNode

type Thumbnail

type Thumbnail struct {
	Image
	Width  int
	Height int
}

type VarValue

type VarValue = any

type XmlOptions

type XmlOptions struct {
	LiteralXmlDelimiter string
}

type ZipArchive

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

func NewZipArchive

func NewZipArchive(name string, w io.Writer) (*ZipArchive, error)

func (*ZipArchive) Close

func (za *ZipArchive) Close() error

func (*ZipArchive) GetFile

func (za *ZipArchive) GetFile(name string) ([]byte, error)

func (*ZipArchive) SetFile

func (za *ZipArchive) SetFile(name string, data []byte)

Jump to

Keyboard shortcuts

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