2015-04-29 45 views
0

是否可以使用该方法时Sass.compile_file注入变量到萨斯范围是什么?设置萨斯变量纳入Sass.compile_file

目前我传递值到custom:参数,创建自定义SASS功能,然后调用从萨斯文件/脚本中。这是很尴尬的,因为我有创建相应类型的对象从函数返回,即Sass::Script::String,而不是String

回答

0

我想根据Is there a way I can overwrite LESS variable with LESS compiler in PHP?你可以自己打开文件并通过(Sass.compile)解析其内容[http://sass-lang.com/documentation/Sass.html],而不是直接使用Sass.compile_file

随着compile.rb

#!/usr/bin/ruby  
require 'sass' 
data = File.read("./colors.scss") 
puts Sass::compile('$color: white;' + data) 

colors.scss

$color: blue !default; 
p { 
color: $color; 
} 

运行./compile.rb输出:

p { 
    color: white; } 

根据the docs你应该使用Sass::Engine

在Ruby代码用无礼的话是很简单的。在安装Sass gem之后,您可以通过运行require“sass”并使用Sass :: Engine来使用它。

#!/usr/bin/ruby 
require 'sass' 
template = File.read('./colors.scss') 
sass_engine = Sass::Engine.new("$color: white;\n" + template, :syntax => :scss) 
output = sass_engine.render 
puts output