templateStr

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 5, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const REG_BOOL = `b/(?P<bool>[Tt]rue|[Ff]alse)`
View Source
const REG_CONDITION = `` /* 157-byte string literal not displayed */
View Source
const REG_FLOAT = `f/(?P<float>[0-9_.]+)`
View Source
const REG_FUNCTION = `(?P<match>@{(?P<functionName>[^{}\s]+)(?:; (?P<parameters>[^{}]+))?})`
View Source
const REG_INT = `i/(?P<int>[0-9_]+)`
View Source
const REG_LIST = `\((?P<list>[^\(\)]+)\)`
View Source
const REG_STR = `\"(?P<str_double>[^\"]+)\"|\'(?P<str_single>[^\']+)\'|\x60(?P<str_back>[^\x60]+)\x60`
View Source
const REG_SWITCH = `(?P<match>\?{(?:(?P<type>str|int|float)/)?` + REG_VAR + `; (?P<values>(?:[^{}]+::[^{}]+){2,}), _::(?P<defaultValue>[^{}]+)})`
View Source
const REG_VAR = `(?P<variable>[\w._-]+)(?:\[(?P<index>[\d]+)])?`
View Source
const REG_VARIABLE = `(?P<match>\${` + REG_VAR + `})`

Variables

This section is empty.

Functions

This section is empty.

Types

type Any

type Any = interface{}

type Func

type Func func([]Any) string

type FuncArray

type FuncArray []Func

type TError added in v1.0.0

type TError struct {
	Name string
	Err  error
}

func BadComparatorError added in v1.0.0

func BadComparatorError(err string) TError

func IndexError added in v1.0.0

func IndexError(err string) TError

func NotAArrayError added in v1.0.0

func NotAArrayError(err string) TError

func NotFoundFunctionError added in v1.0.0

func NotFoundFunctionError(err string) TError

func NotFoundVariableError added in v1.0.0

func NotFoundVariableError(err string) TError

func (TError) Error added in v1.0.0

func (err TError) Error() string

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

type VariableMap

type VariableMap map[string]Any

Jump to

Keyboard shortcuts

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