-
Notifications
You must be signed in to change notification settings - Fork 0
Expressions
[[ <expression> ]]
Mend allows you to insert variables and do basic operations on those variables.
The root. context is taken from the CLI --input attributes and is the same for all files.
The this. context is relative to the file (for the file provided in mend CLI it's the same as root.). You can set it by providing :-prefixed attributes to the block:
<pkg:example :attr1="Hello World!" :attr2="{a:'Hello' b:'World!' c:{0:'69' 1:'420'}}" />You can query nested context using <this/root>.path.to.attr. Suffix the value with ? if it's optional.
You can chain any number of modificators to the variable: this.attr.modifier1().modifier2().modifier3().
-
to_lower()β Converts the string to all lower case. -
to_upper()β Converts the string to all UPPER CASE. -
to_pascal_case()β Converts the string to PascalCase. -
to_camel_case()β Converts the string to camelCase. -
to_snake_case()β Converts the string to snake_case. -
to_kebab_case()β Converts the string to kebab-case. -
capitalize()β Makes the first character of the string upper case. -
length()β Returns the string representation of the length of the string. -
filename()β Assuming the input is a path (e.g./some/path/to/file) returns the filename (e.g.file). -
dir()β Assuming the input is a path (e.g./some/path/to/file) returns the dir (e.g./some/path/to). -
extension()β Assuming the input is a filename (e.g./path/to/file.html) returns the extension (e.g..html). -
trim_extension()β Assuming the input is a filename (e.g./path/to/file.html) returns the path without extension (e.g./path/to/file).
You can perform operations on a variable this.path.to.attr <operator> 'my value'.
Use single quotes if your value contains spaces.
-
==,!=β Returnstrueorfalsewhether the statement is truthfull. -
hasβ Whether the value contains the substring to the right. -
lacksβ Opposite ofhas -
||β Defined a fallback. If value on the left is undefined returns the value on the right.
Note
You can only perform an operation once (e.g. this.value == 'Hello World', but not this.value == 'Hello World' == true).
The only exception is you can append || fallback (e.g. this.value == 'Hello World' || Fallback is valid).