Reputation: 3567
I have a small Sinatra app which generates html fragments for me from an ERB template.
How do I html_escape the output?
The <%=h somestring %> helper does not exist in Sinatra.
Upvotes: 7
Views: 5563
Reputation: 438
require 'CGI'
get '/html' do
erb :view
end
def h(html)
CGI.escapeHTML html
end
__END__
@@view
<% File.open('my.html') do |f| %>
<%=h f.read() %>
<% end %>
Upvotes: 3
Reputation: 509
Rack::Utils
includes a HTML escape method. http://www.sinatrarb.com/faq.html#escape_html
Upvotes: 15