tongueroo/lono — pull request #13 by leejones (2014-11-19 01:49:57+00:00)
Title: Enable trim_mode when rendering ERB

First off, thanks for lono! We are finding it very helpful in managing our CloudFormation templates.

I wanted to propose a small change in how ERB templates are rendered. The change should be fully backwards compatible.

ERB's `trim_mode` option allows you to omit certain ERB blocks from the final output. This is mainly an aesthetic change to make it easier to read the rendered output.

One example is having a conditional in a user data file. Without `trim_mode` enabled, your template would look something like:

```yaml
packages:
<% if @env == "CI" %>
- build-essential
<% end %>
- git
output:
all: "| tee -a /var/log/cloud-init-output.log"
```

And the resulting output would have an empty line after `packages:`:

```yaml
packages:

- git
output:
all: "| tee -a /var/log/cloud-init-output.log"
```

The rendered file is is still valid syntax, but it is slightly more difficult to read. Additionally, when the user data file gets coverted to JSON it will be slightly more difficult to read with the extra newline.

If `trim_mode` is enabled, we can change the above user data file (note the addition of the `-` to the closing `%>` tag):

```diff
#cloud-config
packages:
- <% if @env == "CI" %>
+ <% if @env == "CI" -%>
- build-essential
- <% end %>
+ <% end -%>
- git
output:
all: "| tee -a /var/log/cloud-init-output.log"
```

The resulting output would be a little easier to read:

```yaml
packages:
- git
output:
all: "| tee -a /var/log/cloud-init-output.log"
```