2011-10-06 55 views
2

我有一個簡單的Sinatra應用程序,它執行HTTP調用,我想通過Haml在應用程序中顯示響應標題和正文。這裏是我需要顯示的HTTP輸出在Haml和Sinatra中顯示原始HTML

Response header 
    #<Net::HTTPMovedPermanently:0x00000105852158> 

Response body 
    <html> 
    <head> 
    <title>bit.ly</title> 
    </head> 
    <body> 
    <a href="http://www.csmonitor.com/Science/2011/1004/Nobel-Prize-for-physics-Universe-expansion-accelerating-not-slowing-down">moved here</a> 
    </body> 
    </html> 

在Haml中這樣做的正確方法是什麼?這是我目前有,它不處理原始HTML輸出正確

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

我曾嘗試使用html_saferaw但他們沒有提供西納特拉。

回答

1

想通了,這是html_escape幫手像這樣

@@ index 
Header: 
%p= html_escape(@resp.header) 
Body: 
%p= html_escape(@resp.body)