2011-07-11 12 views
10

私は一連のクラス、.module1、.module2、... module(n)が必要です。HAML CSS内でルビ変数を補間できますか?

私もCSS、RubyとHAMLを使用してこれらのクラスを定義したい

:css 
    .mod1 { 
     background-image: url("#{extra.image}"); 
    } 

それは作業を保存するためにRubyの変数を補間することは可能ですか?

.module.mod"#{extra.id}" 
    %h3 #{extra.title} 
    %p #{extra.description} 
    %a.btn-default{:href => "#", :target => "_top"} enter now 

:css 
    .mod#{extra.id} { 
     background-image: url("#{extra.image}"); 
    } 

答えて

13

私はこの方法を使用HAML_REFERENCEによると:CSS

.module.modone{:class => "#{cycle("mod_#{extra.id}_")}"} 

    %h3 #{extra.title} 
    %p #{extra.description} 
    %a.btn-default{:href => "#", :target => "_top"} enter now 

:css 
    .mod_#{extra.id}_ { 
    background-image: url("#{extra.image}"); 
    background-color: #4073DF; 
    } 
:後に変数を補間する

- flavor = "raspberry" 
#content 
    :textile 
    I *really* prefer _#{h flavor}_ jam. 

関連する問題