开发者

Can you interpolate ruby variables within HAML css?

开发者 https://www.devze.com 2023-03-19 06:56 出处:网络
I need a series of classes, .module1, .module2, ... module(n). I also want to define those classes using css, ruby and HAML:

I need a series of classes, .module1, .module2, ... module(n).

I also want to define those classes using css, ruby and HAML:

:css
  .mod1 {
        b开发者_JAVA技巧ackground-image: url("#{extra.image}");
    }

Is it possible to interpolate ruby variables to save work?

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


According to the HAML_REFERENCE I used this method:

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

to interpolate variables after :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;
  }


:css
  .mod_#{extra.id}_ { 
    background-image: url("#{extra.image}");
    height: #{ruby_height}#{measure_unit_ruby_variable};
  }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号