zestia / ember-wrap-urls

:link: Automatically turns URLs into Hyperlinks for user-generated-content
MIT License
7 stars 4 forks source link

Helper version #1

Closed mschinis closed 5 years ago

mschinis commented 8 years ago

Hello,

It would be very interesting to see this addon in a helper format, so that you could use something like the following:

(some-other-helper (wrap-urls "hey check this cool product http://somethingcool.com"))

amk221 commented 8 years ago

Interestingly, my first attempt at this was a helper.

However, there were a couple of issues...

1) wrap-urls is (usually) a dead-end. Therefore, being able to call it as a helper isn't useful. Consider:

ok

{{wrap-urls text=(truncate 'visit http://example.com' 19)}}

Which results in: visit <span class="ember-view url">http://exampl</span>

not ok

{{truncate (wrap-urls 'visit http://example.com') 19}}

Which could result in: visit <span class=" (However, it won't because span is not an HTML string)

2) The result of calling wrap-urls needs to contain components (not just plain HTML strings). Helpers don't have HTMLBars templates, so I opted for a Component. It's probably possible to achieve using streams, which would be more performant - but I am unfamiliar with them.

I'd appreciate any help on the matter

mschinis commented 8 years ago
  1. Truncating example If you were to use the hyperlink component, I imagine that even the first ok example wouldn't work either. It will link to http://exampl, right?.
  2. Containing components I think you can return components from a helper by doing the following:
import hbs from 'htmlbars-inline-precompile';
export function someHelper([component]) {
    return hbs`{{${component}}}{{/${component}}}`;
}
export default Ember.Helper.helper(someHelper);

I haven't tried the above yet, but that should work.

I'll have a crack at it, later in the weekend and let you know how it goes :)

amk221 commented 8 years ago

@mschinis

  1. Example 1 does work, as there is a test (but bare in mind it is not testing what we are talking about)
  2. I don't think many people include the template compiler in production so that would be no use
  3. Can you explain any benefit to making it a helper? (Other than streams, like I mentioned)