我想使用模板Tilt和SASSin生成动态 CSS Rails 4。
假设我有以下
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} !importantmaster.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