Documentation ¶
Index ¶
- Constants
- type Any
- type Func
- type FuncArray
- type TError
- type TemplateStr
- func (t TemplateStr) HasCondition(text string) bool
- func (t TemplateStr) HasFunction(text string) bool
- func (t TemplateStr) HasOne(text string) bool
- func (t TemplateStr) HasSwitch(text string) bool
- func (t TemplateStr) HasVariable(text string) bool
- func (t TemplateStr) Parse(text string) (string, error)
- func (t TemplateStr) ParseCondition(text string) (string, error)
- func (t TemplateStr) ParseFunction(text string) (string, error)
- func (t TemplateStr) ParseSwitch(text string) (string, error)
- func (t TemplateStr) ParseVariable(text string) (string, error)
- type VariableMap
Constants ¶
const REG_BOOL = `b/(?P<bool>[Tt]rue|[Ff]alse)`
const REG_CONDITION = `` /* 157-byte string literal not displayed */
const REG_FLOAT = `f/(?P<float>[0-9_.]+)`
const REG_FUNCTION = `(?P<match>@{(?P<functionName>[^{}\s]+)(?:; (?P<parameters>[^{}]+))?})`
const REG_INT = `i/(?P<int>[0-9_]+)`
const REG_LIST = `\((?P<list>[^\(\)]+)\)`
const REG_STR = `\"(?P<str_double>[^\"]+)\"|\'(?P<str_single>[^\']+)\'|\x60(?P<str_back>[^\x60]+)\x60`
const REG_SWITCH = `(?P<match>\?{(?:(?P<type>str|int|float)/)?` + REG_VAR + `; (?P<values>(?:[^{}]+::[^{}]+){2,}), _::(?P<defaultValue>[^{}]+)})`
const REG_VAR = `(?P<variable>[\w._-]+)(?:\[(?P<index>[\d]+)])?`
const REG_VARIABLE = `(?P<match>\${` + REG_VAR + `})`
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type TError ¶ added in v1.0.0
func BadComparatorError ¶ added in v1.0.0
func IndexError ¶ added in v1.0.0
func NotAArrayError ¶ added in v1.0.0
func NotFoundFunctionError ¶ added in v1.0.0
func NotFoundVariableError ¶ added in v1.0.0
type TemplateStr ¶
type TemplateStr struct {
// contains filtered or unexported fields
}
Construtor
func New ¶
func New(funcArray FuncArray, variableMap VariableMap) TemplateStr
`funcArray FuncArray` is a array of custom functions that can be used when you call a function with: `{{@myCustomFunction}}`
`variableMap VariableMap` is a map of the values you want to use when you call: `{{$myVar}}`
Typing:
keyVariable : is the key of the value in the dictionary pass to the constructor (return the value) <b:True> : bool (return true) <n:123> : int (return 123) <n:123.4> : float64 (return 123.4) "text" : string (return text)
func (TemplateStr) HasCondition ¶
func (t TemplateStr) HasCondition(text string) bool
Detects if there is the presence of `{{#var1 == var2: value1 || value2}}`
return -> bool
func (TemplateStr) HasFunction ¶
func (t TemplateStr) HasFunction(text string) bool
Detects if there is the presence of `{{@function param1 param2}}` or `{{@function}}`
return -> bool
func (TemplateStr) HasOne ¶
func (t TemplateStr) HasOne(text string) bool
Detects if there is the presence of min one syntaxe
return -> bool
func (TemplateStr) HasSwitch ¶
func (t TemplateStr) HasSwitch(text string) bool
Detects if there is the presence of `{{?var: value1=#0F0, value2=#00F, ..., default=#000}}` or `{{?var:int; 56=#0F0, 32=#00F, ..., default=#000}}`
return -> bool
func (TemplateStr) HasVariable ¶
func (t TemplateStr) HasVariable(text string) bool
Detects if there is the presence of `{{$variable}}`
return -> bool
func (TemplateStr) Parse ¶
func (t TemplateStr) Parse(text string) (string, error)
shortcuts to run all parsers
return -> string
func (TemplateStr) ParseCondition ¶
func (t TemplateStr) ParseCondition(text string) (string, error)
parse all the `{{#var1 == var2: value1 || value2}}` in the text give in
return -> string
func (TemplateStr) ParseFunction ¶
func (t TemplateStr) ParseFunction(text string) (string, error)
parse all the `{{@function param1 param2}}` or `{{@function}}` in the text give in
return -> string
func (TemplateStr) ParseSwitch ¶
func (t TemplateStr) ParseSwitch(text string) (string, error)
parse all the `{{?var; value1=#0F0, 56=#00F, ..., default=#000}}` or `{{?var:int; 56=#0F0, 32=#00F, ..., default=#000}}` in the text give in
return -> string
func (TemplateStr) ParseVariable ¶
func (t TemplateStr) ParseVariable(text string) (string, error)
parse all the `${variable}` in the text give in
return -> string