开发者

Display raw HTML in Haml and Sinatra

开发者 https://www.devze.com 2023-04-11 12:22 出处:网络
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

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)
0

精彩评论

暂无评论...
验证码 换一张
取 消