How to convert slim to erb without wrapping code with escape_html?
Asked Answered
S

1

6

I'm converting multiple html.slim files to html.erb. After following plenty of brilliant advice and tips on stack overflow, I'm pretty much done, but I'm not happy with the html.erb code that is generated. I understand that it's not going to be perfect, but I'm getting an additional Temple::Utils.escape_html((...)) around my links, as in:

<%= ::Temple::Utils.escape_html((link_to "Jobs", jobs_path)) %>

I finally came across Dimitry_N's (Stack Overflow) answer here, but even when I pass the --rails flag as he suggests, I still get the superfluous code.

I've come across one or two Regex options to delete the additional code after file is created, but I'm hoping to find something that expands on Dimitry's answer so that they're not inserted in the first place.

Has anyone experienced this or know of a solution?

Scroop answered 19/7, 2016 at 7:38 Comment(0)
T
2

escape_html is coming from Temple, which is part of the Slim engine configuration:

filter :Escapable

Temple::Filters::Escapable has a disable_escape option. I made this while figuring it out:

class ERBConverter < Slim::Engine
  replace :StaticMerger, Temple::Filters::CodeMerger
  replace :Generator, Temple::Generators::ERB
  replace(:Escapable, :Escapable) { Temple::Filters::Escapable.new(disable_escape: true) }
end
puts ERBConverter.new.call(File.read("test.html.slim"))

<div class="flex bg-red-500">
<%= link_to "link", link_path, class: "a" %>
</div>

But later noticed --option flag, and you can just pass it to slimrb:

$ slimrb -e -o disable_escape=true test.html.slim

<div class="flex bg-red-500">
<%= link_to "link", link_path, class: "a" %>
</div>

https://rubydoc.info/gems/slim/frames#available-options

Tugman answered 11/1, 2023 at 3:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.