【发布时间】:2014-06-20 20:40:37
【问题描述】:
我想使用模板和Rails 4 中的Tilt 和SASS 生成动态CSS。
-
假设我有以下
css.sass模板:$class_name: test $width: 329 $height: 425 .view-#{$class_name} width: #{$width}px height: #{$height}px 我需要
master.css.sass.erb(我不确定格式),我将使用不同的参数尽可能多次地渲染我的模板。-
在
application.css,我会有这样的东西*= require master.css.sass.erb
每次我使用具有不同参数的模板时,我都会在我的master.css.sass.erb 文件中添加一行。我不知道如何使用Tilt 将参数传递给css.sass 模板。谁能帮忙看看这是否可行?
这是我到现在为止的:
-
模板
test.css.sass.erb:$color: <%= color %> body background: #{$color} !important -
master.css.sass.erb文件:<% require 'erb' config_path = File.expand_path("../test.css.sass.erb", __FILE__) template = Tilt.new(config_path) template.render(self, :color => 'yellow') %> .thisisrendered color: red
注意这两个文件在一个文件夹中。问题是只有以下 css 被重新渲染:
.thisisrendered
color: red
【问题讨论】:
标签: ruby ruby-on-rails-4 sass tilt