2011-07-11 13 views
10

Potrzebuję serii klas, .module1, .module2, ... module (n).Czy możesz interpolować zmienne ruby ​​w obrębie css HAML?

Chcę również definiować tych klas za pomocą CSS, Ruby i haml:

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

Czy można interpolować zmiennych rubinowe, aby zapisać pracę?

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

Odpowiedz

13

Według HAML_REFERENCE kiedyś tej metody:

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

interpolacji po zmiennych: 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; 
    }