Repository navigation
Expression language
Expressions are used for parameterization of the templates. Expression can be
used in any file, that has its action in makeit.json (template config) set to
Make.
Expressions are enclosed in {{ and }} and can contain variables, literals
or operators. You can also use parenthesis (( and )) for changing the
presedence of the operators.
Variable names must start with alphabetic character or underscore and can be followed by any alphanumeric character or underscore.
Variables can be defined in template config (makeit.json in template folder)
or they can be supplied by command-line arguments. Variables in the expressions
are then expanded to the set values.
There are also some internal variables in the expression language and more might be added in the future:
-
_PNAME: project name based on project directory -
_PDIR: project directory -
_OS: operating system
Let's say we have variable with name greet and value of "hello" (more about
variable definitions later). Then this code:
{{ greet }}
would expand to:
hello
Literals are enclosed in double quotes ("). They support escape sequences as
well, starting with backslash (\):
-
\n: newline -
\r: carriage return -
\t: tabulator -
\\: backslash -
\": double quotes - Other sequences are expanded to character following backslash
When we have this code:
{{ "Hello makeit!" }}
it would get expanded to:
Hello makeit!
The plus operator (+) is used for literal and variable concatenation. It
allows you to combine two literals/variables into a single literal.
The syntax is:
{{ EXPR1 + EXPR2 }}
where EXPR1 and EXPR2 are the values to be concatenated.
When we have this code:
{{ "Hello " + _OS }}
it would get expanded to (in case of using linux):
Hello linux
The equality operator (==) is used to compare two values for equality. It
evaluates to true if the values on either side of the operator are equal,
and false otherwise.
The syntax is:
{{ EXPR1 == EXPR2 }}
where EXPR1 and EXPR2 are the values or expressions to be compared.
When we have this code:
{{ "equals" == "equals" }}
{{ "not equals" == "negative" }}
it would get expanded to:
true
false
The ternary conditional operator (?:) is a shorthand for an if-else
statement. It evaluates a condition and returns one of the two values depending
on whether the condition is true or false.
The syntax is:
{{ EXPR1 ? EXPR2 : EXPR3 }}
where EXPR1 is the condition to evaluate, EXPR2 is the value returned if
the condition is true, and EXPR3 is the value returned if the condition is
false.
When we have this code:
{{ "cond" == "cond" ? "equals" : "not equals" }}
{{ "cond1" == "cond2" ? "equals" : "not equals" }}
it would be expanded to:
equals
not equals
The null coalescing operator (??) is used to provide a default value when an
expression evaluates to null. It returns value of the first operand if it is
not null. Otherwise, it returns the value of the second operand.
The syntax is:
{{ EXPR1 ?? EXPR2 }}
where EXPR1 is the expression to evaluate and EXPR2 is the default value to
return if EXPR1 is null
Let's say we have variable valuable set to "diamond" and this code:
{{ valuable ?? "default valuable" }}
{{ ore ?? "default ore" }}
it would be expanded to:
diamond
default ore