Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve consistency of Handlebars helpers (i18n, partial, block) #1690

Closed
brylie opened this issue Oct 5, 2016 · 4 comments
Closed

Improve consistency of Handlebars helpers (i18n, partial, block) #1690

brylie opened this issue Oct 5, 2016 · 4 comments
Assignees
Labels
Milestone

Comments

@brylie
Copy link
Contributor

brylie commented Oct 5, 2016

Our Handlebars syntax uses a mixture of elements with and without spaces separating the handlebars and the prefix. E.g.

  • {{_ vs. {{ _
  • {{# vs. {{ #
  • {{> vs. {{ >

While this does not make a difference to the Handlebars compiler, it has the following shortcomings for humans:

  • it is inconsistent
  • including spaces marginally reduces readability
  • it has caused trouble when doing a project wide search/replace when cleaning up i18n strings

Proposal

Reformat all, or most, Handlebars code to remove spaces between the handlebars ({{) and 'prefix' (_, #, and >).

Rationale

A quick search of our code found the following counts:

  • 139 results for {{>
  • 22 results for {{ >

Similarly, we tend to keep the # character next to the {{ in template block helpers:

  • 107 results for {{#
  • 41 results for {{ #

We should prefer the first version, keeping > and # close to the {{ for these reasons:

  • both cases are more common in our code, currently
  • the > and # characters are a bit noisy, since they are not English words (i.e. they are more to help the computer than the developer who is reading the sourcecode)
  • combining the {{> and {{# into single string, without space, makes them simpler (both to read and type)

Both the handlebars ({{) and prefixes (_, #, and >) are used primarily to help the computer (parser) to do its job.

Combining handlebars and prefixes makes it, slightly, easier for the human to read, and still accomplishes the same. I.e. {{_, {{> and {{# are easy for us to read and distinguish (without spaces), while the parser can still do its job just fine.

Quick summary

I am proposing we remove the space infix because:

  • handlebars spaces are unnecessary
  • handlebars spaces do not significantly increase readability (although spaces increase readability elsewhere in our code)
    • i.e. template helpers without spaces between the prefix are easy to read, since the last character is easy to distinguish
  • most template helpers in our code do not separate the handlebars ({{) from the prefix (_, >, #)
@brylie brylie added this to the Sprint 32 milestone Oct 5, 2016
@brylie brylie self-assigned this Oct 5, 2016
@brylie brylie added the Cleanup label Oct 5, 2016
@brylie
Copy link
Contributor Author

brylie commented Oct 5, 2016

Ping @bajiat @apinf/developers

@bajiat
Copy link
Contributor

bajiat commented Oct 5, 2016

I'm ok with cleaning this, but only if it does not jeopardize finishing #1623.

@brylie
Copy link
Contributor Author

brylie commented Oct 5, 2016

@bajiat this seems to be a small cleanup task, just doing a 'search and replace'.

@frenchbread
Copy link
Contributor

frenchbread commented Oct 5, 2016

If we are going to vote, I'm 👍 for {{ > something }}, {{ _ "something" }}, {{ # something }} - "with spaces" approach.

Related discussion: #1682

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants