Documentation ¶
Index ¶
- Constants
- Variables
- type Image
- type Param
- func (p *Param) Depth() int
- func (p *Param) Placeholder() string
- func (p *Param) PlaceholderInline() string
- func (p *Param) PlaceholderKey() string
- func (p *Param) PlaceholderKeyInline() string
- func (p *Param) PlaceholderKeyPrefix() string
- func (p *Param) PlaceholderPrefix() string
- func (p *Param) RunTrigger(xnode *xmlNode)
- func (p *Param) SetValue(val interface{})
- func (p *Param) String() string
- func (p *Param) ToCompact(placeholder string) string
- func (p *Param) Walk(fn func(*Param), level int)
- func (p *Param) WalkFunc(fn func(*Param))
- type ParamList
- type ParamTrigger
- type ParamType
- type Template
Constants ¶
const ( TriggerOnUnknown string = ":unknown" TriggerOnEmpty string = ":empty" TriggerOnValue string = ":=" )
On - trigger events when command to aply
const ( TriggerCommandRemove = ":remove" TriggerCommandClear = ":clear" )
Command - what to do when triggered
const ( TriggerScopePlaceholder = ":placeholder" TriggerScopeCell = ":cell" TriggerScopeRow = ":row" TriggerScopeList = ":list" TriggerScopeTable = ":table" TriggerScopeSection = ":section" // table, list.. )
Scope - scope of affected elements by command
const ParamPattern = `{{(#|)([\w\.]+?)(| .*?)(| [:a-z]+?)}}`
ParamPattern - regex pattern to identify params
Variables ¶
var NodeCellTypes = []string{"w-tc"}
NodeCellTypes - NB! sequence is important
var NodeRowTypes = []string{"w-tr", "w-p"}
NodeRowTypes - NB! sequence is important
var NodeSectionTypes = []string{"w-tbl", "w-p"}
NodeSectionTypes - NB! sequence is important
var NodeSingleTypes = []string{"w-r", "w-t"}
NodeSingleTypes - NB! sequence is important
Functions ¶
This section is empty.
Types ¶
type Param ¶
type Param struct { Key string Value string Type ParamType Level int Params ParamList AbsoluteKey string // Users.1.Name CompactKey string // Users.Name Separator string // {{Usernames SEPERATOR}} Trigger *ParamTrigger RowPlaceholder string // contains filtered or unexported fields }
Param ..
func (*Param) PlaceholderInline ¶
PlaceholderInline .. {{Key ,}}
func (*Param) PlaceholderKeyInline ¶
PlaceholderKeyInline .. {{#Key ,}}
func (*Param) PlaceholderKeyPrefix ¶
PlaceholderKeyPrefix .. {{#Key
func (*Param) PlaceholderPrefix ¶
PlaceholderPrefix .. {{Key
type ParamList ¶
type ParamList []*Param
ParamList ..
func StructParams ¶
func StructParams(v interface{}) ParamList
StructParams - load params from given any struct 1) Convert struct to JSON 2) Now convert JSON to map[string]interface{} 3) Clear params from nil
func StructToParams ¶
func StructToParams(paramStruct interface{}) ParamList
StructToParams - walk struct and collect valid params
type ParamTrigger ¶
type ParamTrigger struct { On string Command string Scope string // contains filtered or unexported fields }
ParamTrigger - param trigger command {{Key :On:Command:Scope}} {{MyParam :empty:remove:list}} -- Read as: "`remove` `list` on `empty` value"
func NewParamTrigger ¶
func NewParamTrigger(raw []byte) *ParamTrigger
NewParamTrigger - take raw ":empty:remove:list" and make trigger and it's fields from it
func (*ParamTrigger) String ¶
func (tr *ParamTrigger) String() string
String - return rebuilt trigger string
type Template ¶
type Template struct {
// contains filtered or unexported fields
}
Template ..
func OpenTemplate ¶
OpenTemplate - docpath local file
func OpenTemplateWithBytes ¶ added in v1.2.3
OpenTemplateWithBytes - template from bytes Credits to @dreamph for implementing this function
func OpenTemplateWithURL ¶
OpenTemplateWithURL .. docpath is remote url
func (*Template) Bytes ¶
Bytes - create docx archive but return only bytes of it do not save it anywhere
func (*Template) ExportDocx ¶
ExportDocx - save new/modified docx based on template
func (*Template) Params ¶
func (t *Template) Params(v interface{})
Params - replace template placeholders with params "Hello {{ Name }}!"" --> "Hello World!""
func (*Template) Placeholders ¶
Placeholders - get list of used params placeholders in template If you already replaced params with values then you will not get all placeholders. Or use it after replace and see how many placeholders left.