如何在sinatra应用程序中html_escape文本数据?

我有一个小的Sinatra应用程序,它从ERB模板为我生成html片段。

我如何html_escape输出?

Sinatra中不存在帮助器。

Rack::Utils包含一个HTML转义方法。 http://www.sinatrarb.com/faq.html#escape_html

 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 %>