2011-07-07 24 views
1

我偶然發現HAML在Rails中處理render方法的方式看起來不一致。HAML在Rails模板中如何處理呈現方法的細微差異

實施例1中ERB

# template.html.erb 
This is the index template. 
<%= render :layout => 'form4', :partial => 'stuff2' %> 

# _layout.html.erb 
<%= form_tag do %> 
    <div class="something"> 
     <%= yield %> 
    </div> 
<% end %> 

# _partial.html.erb 
<b>meh</b> 
<%= text_field_tag 'name' %> 

實施例1中HAML

# template.html.haml 
This is the index template. 
=render :layout => 'form2', :partial => 'stuff1' 

# _layout.html.haml 
=form_tag do 
    .something 
     =yield 

# _partial.html.haml 
%b meh 
=text_field_tag 'name' 

正如預期的那樣,二者的結果在相同的渲染(以下略):

現在

這裏的其中的怪事踢當我調整render語句中使用如下塊語法:

ERB

# template.html.erb 
This is the index template. 
<%= render :layout => 'form3' do %> 
    <b>meh</b> 
    <%= text_field_tag 'name' %> 
<% end %> 

# _layout.html.erb 
<%= form_tag do %> 
    <div class="something"> 
     <%= yield %> 
    </div> 
<% end %> 

HAML

# template.html.haml 
This is the index template. 
=render :layout => 'form1' do 
    %b meh 
    =text_field_tag 'name' 

# _layout.html.haml 
=form_tag do 
    .something 
     =yield 

我得到的ERB版本相同上面呈現,但HAML代碼輸出:

This is the index template. 
<b>meh</b> 
<input id="name" name="name" type="text" /> 
<form> 
    <div class='something'></div> 
</form> 

這是因爲如果HAML不知何故不尊重傳遞給塊它。根據HAML的文檔,他們支持基於縮進自動關閉的塊,所以我不認爲這是一個問題。另外,在他們的文檔中,我看到了他們自己的render方法的定義。它有可能沒有被正確實現,以與rails的(erb's?)render方法相同的界面?

在這個註釋中,如果這在方法接口中確實是不一致的,那麼是否有理由在HAML上打開一個問題?

剛加入展示行爲的示例應用程序在https://github.com/iamvery/haml-weirdness

這也是值得注意的是,我注意到這個變化時,我升級我的Rails應用程序到3.0.9和HAML 3.1.2。留下haml在3.0.24導致Cannot modify SafeBuffer in place錯誤導軌3.0.9 ...

回答

2

是的我有同樣的問題。它也被描述在https://github.com/nex3/haml/issues/412
nex3的github帳戶有一個issue_412分支,但它不完整。 你可以試着修復haml,我決定回到rails 3.0.7。

+0

我有同樣的問題啊.. – Lichtamberg

+1

這看起來是用HAML 3.1.3修復的! – Iamvery