Display raw HTML in Haml and Sinatra
I have a simple Sinatra app that does a HTTP call and I want to display the response header and body in the app via Haml. Here's the HTTP output I need to display
Response header
#<Net::HTTPMovedPermanently:0x00000105852158>
Response body
<html>
<head>
<title>bit.ly</title>
</head>
<body>
<a href="http://www.csmonitor.com/Science/2011/1004/N开发者_JS百科obel-Prize-for-physics-Universe-expansion-accelerating-not-slowing-down">moved here</a>
</body>
</html>
What is the proper way to do this in Haml? This is what I have currently and it is not handling the raw html output properly
@@ layout
!!! 1.1
%html
%head
%title Just do it!
%link{:rel => 'stylesheet', :href => 'http://www.w3.org/StyleSheets/Core/Modernist', :type => 'text/css'}
= yield
@@ index
Header:
%p= @resp.header
Body:
%p= @resp.body
I have tried to use html_safe
and raw
but they are not available in Sinatra.
Figured it out, it's html_escape
helper like such
@@ index
Header:
%p= html_escape(@resp.header)
Body:
%p= html_escape(@resp.body)
精彩评论