# `Braces.Handlebars.Formatter`
[🔗](https://github.com/dbernheisel/braces/blob/v0.1.0/lib/braces/handlebars/formatter.ex#L1)

A `mix format` plugin for Handlebars: `.hbs` and `.handlebars` files, and `~HBS`
sigils.

    # .formatter.exs
    [
      plugins: [Braces.Handlebars.Formatter],
      inputs: ["{lib,test}/**/*.{ex,exs,hbs}", "*.exs"]
    ]

It formats the inside of each tag, as `Braces.Handlebars.to_string/1` prints it, and leaves the
text between tags exactly as it is, since in Handlebars that text is the output: indenting
it would change what the template renders.

| Before | After |
| --- | --- |
| `{{ first_name }}` | `{{first_name}}` |
| `{{#if  vip }}` … `{{ else }}` | `{{#if vip}}` … `{{else}}` |
| `{{  money  total  currency = "EUR" }}` | `{{money total currency="EUR"}}` |
| `{{& raw}}` | `{{{raw}}}` |
| `{{#each items as \| item i \|}}` | `{{#each items as \|item i\|}}` |

Comments are kept as they're written, `{{!-- … --}}` included.

The result always parses to the same template: when it wouldn't, the source is left as it
is. A template that doesn't parse raises its `Braces.Handlebars.ParseError`, so `mix format`
reports it.

# `format`

Formats Handlebars source, as `mix format` does with this plugin.

    iex> Braces.Handlebars.Formatter.format("Hi {{ first_name }}!\n{{#if  vip }}VIP{{ else }}{{!-- not yet --}}{{/if}}", [])
    "Hi {{first_name}}!\n{{#if vip}}VIP{{else}}{{!-- not yet --}}{{/if}}"

---

*Consult [api-reference.md](api-reference.md) for complete listing*
