tests-always-included / mo

Mustache templates in pure bash
Other
563 stars 67 forks source link

Suggestion: Control delimiter with option #41

Closed sascha-wolf closed 1 year ago

sascha-wolf commented 4 years ago

As the title suggests, it would be useful to control the delimiter by providing an option.

Use-case

We have a number of YAML Kubernetes descriptors where parts get interpolated using mo. Using {{ in plain YAML leads to syntax errors in various editors, as { is also the delimiter for an object. Furthermore the formatters in these editors tend to format {{ to { { which breaks interpolation. In the case of a string value this can be avoided by wrapping the variable with quotes ("{{MY_VAR}}") but it's impossible for boolean or numerical values.

While none of this is critical it's fairly annoying, as one has to be careful not to accidentally break the variables when updating the template due to formatters breaking the delimiters.

Implementation

From what I can tell from the source code, the logic mostly already relies on moSplit (with a few exceptions) which already receives the delimiters as argument. Based on this the amount of changes necessary to change the delimiters from an option should be manageable.

Usage might look like this:

mo --opening-delimiter='<%=' --closing-delimiter='%>' my-file

# Potential short options
mo -o='<%=' -c='%>' my-file

Assuming you agree with the proposal I would be happy to open a PR with an implementation.

fidian commented 1 year ago

Implemented in version 3.0.0, released today.