2013-06-25 100 views
2

我搜索了,找不到任何東西,也許我正在尋找錯誤的信息,因爲它似乎應該在某處提及。基本上我有一個關於Slim Template Engine的問題。Rails + Slim Source Output

當使用Slim時,當我查看瀏覽器輸出的源代碼時,它沒有正確嵌套,看起來不專業,與HAML不同,它正確嵌套標籤。我不確定自己是否做錯了或者不正確,如果是的話,請指出正確的方向,因爲我真的很喜歡Slim,但不幸的是源代碼輸出對我來說是一個難題。對於Slim和HAML,我都有我的示例代碼和輸出。

我不能確定它是否是相關的,因爲我仍然很新的Rails的,但我的機器的規格如下:

*Fedora 18 x86_64 
*Apache 2.4.4 
*Ruby 2.0.0p195 
*Rails 3.2.13 

The Gem Versions for HAML and Slim: 
haml (4.0.3) 
haml-rails (0.4) 
slim (2.0.0) 
slim-rails (2.0.1) 

*Apache configuration is set to: RailsEnv development 

修身

應用程序/視圖/佈局/ application.html.slim:

doctype html 
html 

    head 
     title Test Website 
     = stylesheet_link_tag "application", :media => "all" 
     = javascript_include_tag "application" 
     = csrf_meta_tags 

    body 
     = yield 

源輸出:

<!DOCTYPE html><html><head><title>Test Website</title><link href="/assets/application.css?body=1" media="all" rel="stylesheet" type="text/css" /> 
<link href="/assets/home.css?body=1" media="all" rel="stylesheet" type="text/css" /><script src="/assets/jquery.js?body=1" type="text/javascript"></script> 
<script src="/assets/jquery_ujs.js?body=1" type="text/javascript"></script> 
<script src="/assets/home.js?body=1" type="text/javascript"></script> 
<script src="/assets/application.js?body=1" type="text/javascript"></script><meta content="authenticity_token" name="csrf-param" /> 
<meta content="EFA1Dzi1D1DY4GVBlAJ+IIyhm7ZvYch8t5v2a6cj42k=" name="csrf-token" /></head><body><h1>Home#index</h1><p>Find me in app/views/home/index.html.slim</p></body></html> 

HAML

應用程序/視圖/佈局/ application.html.haml:

!!! 
%html 

    %head 
     %title Test Website 
     = stylesheet_link_tag "application", :media => "all" 
     = javascript_include_tag "application" 
     = csrf_meta_tags 

    %body 
     =yield 

源輸出:

<!DOCTYPE html> 
<html> 
    <head> 
    <title>Test Website</title> 
    <link href="/assets/application.css?body=1" media="all" rel="stylesheet" type="text/css" /> 
    <link href="/assets/home.css?body=1" media="all" rel="stylesheet" type="text/css" /> 
    <script src="/assets/jquery.js?body=1" type="text/javascript"></script> 
    <script src="/assets/jquery_ujs.js?body=1" type="text/javascript"></script> 
    <script src="/assets/home.js?body=1" type="text/javascript"></script> 
    <script src="/assets/application.js?body=1" type="text/javascript"></script> 
    <meta content="authenticity_token" name="csrf-param" /> 
    <meta content="RmxaPGwJapEf16Uw8ApQG0CpCHtr4My4aD8UO9w80dY=" name="csrf-token" /> 
    </head> 
    <body> 
    <h1>Home#index</h1> 
    <p>Find me in app/views/home/index.html.haml</p> 
    </body> 
</html> 

回答

2

沒有什麼真的錯了與輸出,斯利姆只是壓縮它以獲得最佳性能。瀏覽器不關心它的外觀,只要它有效。

但是在開發過程中,您可能需要更易讀的版本來進行調試。

可以configure Slim產生漂亮的輸出,像這樣:

# Indent html for pretty debugging and do not sort attributes 
Slim::Engine.set_default_options :pretty => true, :sort_attrs => false 

只是把它放在config/environments/development.rb例如和你設置。

+0

非常感謝!正是我在找什麼! – RPelham