Utilities for Lotus {{variable}} template syntax.
Variables use the {{name}} placeholder format and can appear in SQL
queries, templates, or any other Lotus content type.
Summary
Functions
Extracts variable names from a string containing {{variable}} placeholders.
Replaces all {{variable}} placeholders with the given replacement value.
Returns the compiled regex for matching {{variable}} placeholders.
Functions
Extracts variable names from a string containing {{variable}} placeholders.
Returns names in the order they appear, with duplicates preserved.
Examples
iex> Lotus.Variables.extract_names("WHERE id = {{user_id}} AND status = {{status}}")
["user_id", "status"]
iex> Lotus.Variables.extract_names("no variables here")
[]
Replaces all {{variable}} placeholders with the given replacement value.
Useful for neutralizing variables before validation (e.g. replacing with
"NULL" for SQL syntax checking) or for any context where placeholders
need to be substituted with a static value.
Examples
iex> Lotus.Variables.neutralize("SELECT * FROM users WHERE id = {{user_id}}", "NULL")
"SELECT * FROM users WHERE id = NULL"
iex> Lotus.Variables.neutralize("Hello {{name}}", "")
"Hello "
@spec regex() :: Regex.t()
Returns the compiled regex for matching {{variable}} placeholders.
Captures the variable name (without braces) in group 1.
Examples
iex> Regex.scan(Lotus.Variables.regex(), "WHERE id = {{user_id}}")
[["{{user_id}}", "user_id"]]