2011-07-11 18 views
10

Bir dizi sınıfa ihtiyacım var .module1, .module2, ... module (n).Ruby değişkenlerini HAML css içinde arayabilir misiniz?

Ben de css, yakut ve HAML kullanarak bu sınıfları tanımlamak istediğiniz

:

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

o işi kurtarmak için yakut değişkenleri arasına sokmak mümkün mü?

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

sonra değişkenleri sokmak için:

.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}"); 
    } 

cevap

13

HAML_REFERENCE göre bu yöntem kullanılır 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; 
    }