I'm using ERB or ERUB or Tilt here outside of Rails and I want to make my HTML templates work like rails where stuff is HTML escaped by default.
e.g.
<!-- file.html.erb --><h1>Hello <%= name %></h1>
When I render this, if name
is <b>Pat</b>
, then the HTML sent to the browser is:
<h1>Hello <b>Pat</b></h1>
I'd like it to render this:
<h1>Hello <b>Pat</b></h1>
And I'd like that behavior to be the default anytime <%=
is used.
I'm trying Tilt, but when I do Tilt.new("file.html.erb",escape_html: true)
it escapes the entire file, rendering <h1>Hello <b>Pat</b></h1>
I tried reading Rails' source to figure this out, but it's highly abstracted and wondering if anyone reading this happens to know how to achieve this.