你可以在HAML css中内插ruby变量吗? [英] Can you interpolate ruby variables within HAML css?

查看:164
本文介绍了你可以在HAML css中内插ruby变量吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一系列类,.module1,.module2,... module(n)。

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

我也想使用css,ruby和HAML:

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

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

是否可以内插ruby变量来保存工作?

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


推荐答案

根据 HAML_REFERENCE 我使用此方法:

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

在以下插入变量:css

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;
  }

这篇关于你可以在HAML css中内插ruby变量吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆