ember-cli / ember-cli-htmlbars

MIT License
77 stars 66 forks source link

dedent version of `hbs`? #622

Open samselikoff opened 5 years ago

samselikoff commented 5 years ago

Is there appetite for a version of hbs that dedents the template string?

I find myself often doing things like

layout: hbs(dedent`
  greeting: <span>{{greeting}}</span>
`)

with an npm package, but it always feels like extra work & is most of the time (always?) what I want.

You can see in Ember Animated's codebase Ed's forced to manually dedent the strings because he never got around to installing dedent, which kinda sucks.

Wondering if we could export an hbsd or hbsDedent tag that does this automatically.

layout: hbsDedent`
  greeting: <span>{{greeting}}</span>
`)

Watcha think?

rwjblue commented 5 years ago

Unsure. I don't really like the idea that we'd have to provide a bunch of different hbsFoo style exports, but I am sensitive to the specific issue.

Specifically,dedent isn't really "good enough" here (also I much prefer stripIndent which I commonly use from common-tags npm package over dedent) since sometimes you want to effectively trim each line (leading and trailing spaces).

samselikoff commented 5 years ago

I wish there was a way to customize tag functions. Not sure what it would look like.

Or maybe hbs could have some different properties that are different tags

hbs.stripIndent(`
  <p>Hello, foo</p>
`
rwjblue commented 5 years ago

Ya, hbs.stripIndent "feels" vaguely better to me.