Documentation
¶
Index ¶
Constants ¶
const Version = "0.9.1"
Version of the template engine.
Variables ¶
This section is empty.
Functions ¶
func NewTemplateEngine ¶
NewTemplateEngine creates and initializes a new system.Engine instance configured with the lexer rules for config, code, placeholder, and raw blocks. The engine is ready to process template text after registering commands.
func TemplateReplace ¶
func TemplateReplace( template string, flags []string, placeholders map[string]string, config map[string]string, ) (string, error)
TemplateReplace processes the given template string using the specified flags, placeholders, and configuration. It returns the final rendered string or an error.
Parameters:
- template: raw template text containing special blocks: ((?CONFIG ... )) – configuration overrides, {{?CODE ... }} – code/logic instructions, [[? ... ]] – placeholders.
- flags: list of string flags that can be tested in conditions.
- placeholders: initial key‑value map for template source variables.
- config: configuration overrides for the language behaviour (e.g. comment markers, string delimiters). May be nil to use defaults.
Returns:
- The fully processed template as a string.
- Non‑nil error if parsing, logic evaluation, or processing fails.
Example:
result, err := TemplateReplace(
"Hello [[? name if has name else World]]!",
[]string{},
map[string]string{"name": "Alice"},
nil,
)
// result == "Hello Alice!"
Types ¶
type Language ¶
Language represents the template language instance holding configuration, template sources, flags, and logical scope. Fields are unexported; use NewLanguage to create an instance.
func NewLanguage ¶
func NewLanguage( flags []string, templateSource map[string]string, config map[string]string, ) (*Language, error)
NewLanguage creates a new Language instance with the provided flags, template source map, and configuration map. If flags is nil, an empty slice is used. If templateSource is nil, an empty map is used. If config is nil, default configuration is applied. Default configuration keys: "pre_plus", "post_plus", "raw", "string_start", "string_end", "ALPHA", "comment", "documentation". Missing keys in config are filled with defaults. The templateSource map is guaranteed to have a "nil" key with empty string.
func NewTemplate ¶
func NewTemplate( flags []string, placeholders map[string]string, config map[string]string, ) (*Language, *system.Engine, error)
NewTemplate creates a new Language instance and an associated system.Engine. The engine is pre‑registered with commands for "placeholder", "code", "config", and "raw". Returns the Language instance, the Engine, or an error if language creation fails.