Skip to content

Instantly share code, notes, and snippets.

@alexlafroscia
Last active November 22, 2017 19:14
Show Gist options
  • Save alexlafroscia/2437daf7f5d90169e1685c0170e987db to your computer and use it in GitHub Desktop.
Save alexlafroscia/2437daf7f5d90169e1685c0170e987db to your computer and use it in GitHub Desktop.
How would you pretty-print an HBS file? Here are some examples of cases that aren't quite cut-and-dry
{{! All on one line? }}
{{#some-component className='foo bar bax' foo='bar' baz='foo bar baz' somethingElse='some other really long thing'}}
{{/some-component}}
{{! One property per line? (One level of indentation) }}
{{#some-component
className='foo bar bax'
foo='bar'
baz='foo bar baz'
somethingElse='some other really long thing'
}}
{{/some-component}}
{{! One property per line? (Two levels of indentation) }}
{{! I think this is my favorite because two levels make it more clear where the component begins }}
{{#some-component
className='foo bar bax'
foo='bar'
baz='foo bar baz'
somethingElse='some other really long thing'
}}
{{/some-component}}
{{#some-component foo=(if someCondition 'some property' 'some other property') bar='baz'}}
{{/some-component}}
{{! vs }}
{{#some-component
foo=(if someCondition
'some property'
'some other property')
bar='baz'
}}
{{/some-component}}
{{! vs }}
{{#some-component
foo=(if someCondition
'some property'
'some other property'
)
bar='baz'
}}
{{/some-component}}
{{! Also, what do you do with hash helpers? }}
{{#some-component foo=(hash some='prop' other='prop') bar='baz'}}
{{/some-component}}
{{#some-component
foo=(hash
some='prop'
other='prop')
bar='baz'
}}
{{/some-component}}
{{#some-component
foo=(hash
some='prop'
other='prop'
)
bar='baz'
}}
{{/some-component}}
{{#some-component
className='foo bar bax'
foo='bar'
baz='foo bar baz'
somethingElse='some other really long thing' as |foo|
}}
{{/some-component}}
{{! vs }}
{{#some-component
className='foo bar bax'
foo='bar'
baz='foo bar baz'
somethingElse='some other really long thing'
as |foo|
}}
{{/some-component}}
@alexlafroscia
Copy link
Author

Something else to think about -- components can have positional params as well. Helpers and components may not actually be different -- they probably follow the same rules. An inline component vs. a helper aren't actually different from the HBS file perspective and would be parsed the same way. For example, is the following an inline component or helper?

{{some-component somePositionalParameter prop='value'}}

No way to know. The difference from a parsing perspective only comes into play for block components like:

{{#some-component somePositionalParameter prop='value'}}
{{/some-component}}

@alexlafroscia
Copy link
Author

Another thing to think about: the "named block RFC" will add new syntax that doesn't currently exist in Ember,, but should be accounted for (eventually)

https://github.com/emberjs/rfcs/blob/master/text/0226-named-blocks.md

@alexlafroscia
Copy link
Author

And yet another thing to think about: Ember will be switching to PascalCase for component names, a la React

<SomeComponent somePositionalParam prop='value'>
</SomeComponent>

This is (somewhat) similar to JSX but is really still Handlebars. Just another thing to think about since components in that form will also (eventually) need support. I can't find a link to anything referencing this at the moment, but I know this change was made to Glimmer and will eventually come to Ember once it can interoperate with Glimmer components.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment