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

Rails 5.1 outputs tag helper block with escaped #14

Open
yhatt opened this issue May 12, 2017 · 4 comments
Open

Rails 5.1 outputs tag helper block with escaped #14

yhatt opened this issue May 12, 2017 · 4 comments

Comments

@yhatt
Copy link

yhatt commented May 12, 2017

We tried upgrade my rails application from 5.0.2 to 5.1.0, it uses cells 4.1.7 and cells-slim 0.0.5. and I saw a lot of escaped strings in cells components...

I guessed it is effected by new tag syntax in rails 5.1.

Rendering slim on cells

/ Traditional syntax
= content_tag :a, href: root_path
  strong Back to root page

/ New syntax on Rails 5.1
= tag.a href: root_path
  strong Back to root page

/ URL helper
= link_to root_path
  strong Back to root page

Output in Rails 5.0.2

<a href="/"><strong>Back to root page</strong></a>
<a href="/"><strong>Back to root page</strong></a>
<a href="/"><strong>Back to root page</strong></a>

Output in Rails 5.1.0

<a href="/">&lt;strong&gt;Back to root page&lt;/strong&gt;</a>
<a href="/">&lt;strong&gt;Back to root page&lt;/strong&gt;</a>
<a href="/">&lt;strong&gt;Back to root page&lt;/strong&gt;</a>

Quick-fix

As a workaround makeshift, it seems to be able to deal this problem with overriding #tag_builder private method as below. Currently we are adding this to ApplicationCell and using it as a parent cell.

class ApplicationCell < Cell::ViewModel
  private

  def tag_builder
    super.tap { |builder| builder.class_eval { include Cell::Slim::Rails } }
  end
end

But this approach have over-included unnecessary methods (e.g. for FormTagHelper). It would be great if cells-slim supports 5.1 new methods correctly.

@lulalala
Copy link

Currently #15 fixed this issue, so if you use the master branch this should be fixed.

@yhatt
Copy link
Author

yhatt commented Apr 2, 2018

@lulalala Thanks for your information. However, it has not been fully fixed. I have tried the rendering example as mentioned above on master branch + Rails 5.1.6. The content_tag and link_to will work correctly, but a.tag tag.a will not.

<a href="/"><strong>Back to root page</strong></a>
<a href="/">&lt;strong&gt;Back to root page&lt;/strong&gt;</a>
<a href="/"><strong>Back to root page</strong></a>

We should keep using a workaround with cells-slim v0.0.5.

Unfortunately, I had decided to stop using cells and cells-slim in our new Rails project a long time ago. We want a healthy gem.

@lulalala
Copy link

lulalala commented Apr 2, 2018

@yhatt Just curious, what's a.tag? It's not Rails helper is it?

@yhatt
Copy link
Author

yhatt commented Apr 2, 2018

@lulalala Oops, I had mistaken for tag.a. Rails 5.1 has provided a new interface of the tag helper. (rails/rails#25543)

= tag.a href: root_path
  strong Back to root page

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

No branches or pull requests

2 participants