kzkn / gretel

Flexible Ruby on Rails breadcrumbs plugin.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Incompatible with slim, with their `pretty` option disabled

dkniffin opened this issue · comments

I just started working on improving the breadcrumbs in my project, and I really like the approach Gretel has taken. However, I ran into an issue when I deployed it. Essentially, what was happening is on my local machine, Gretel would render fine, but when deployed, it would escape all the HTML returned by breadcrumbs.

After some digging, I found this issue: slim-template/slim#822 which is nearly identical to what I was experiencing, and the reason it was only happening when deployed was we had this Slim::Engine.set_options pretty: Rails.env.development?

Since this is IMO an issue with slim (or really it's dependency, temple), I've created an issue over there: judofyr/temple#126 I'm creating this issue mostly as documentation for any other unfortunate soul debugging something like this in the future. However, if you wanted to, you could add an html_safe? method in Gretel somewhere (in Gretel::Renderer::LinkCollection, I think?) that simply returns true, and that would resolve the issue as well.

Oh! I forgot to include the most important part 🤦 haha. Here's the really easy workaround until it gets fixed in either here or temple:

Instead of

= breadcrumbs ...

use

== breadcrumbs ...

The == will avoid html escaping: https://github.com/slim-template/slim#output-without-html-escaping-

@dkniffin
Thanks for feedback.
The return value of LinkCollection#to_s is already html_safe, so I will add the below code to LinkCollection.

def html_safe?
  true
end

This will solve your problem.

@dkniffin
I have pushed the fix to fix-22 branch.
Could you test it?

@kzkn Confirmed. That fixed it. Thanks!

@dkniffin Thanks. I will release the fix on the next version.

4.0.2 has shipped.