0
是否可以使用該方法時Sass.compile_file
注入變量到薩斯範圍是什麼?設置薩斯變量納入Sass.compile_file
目前我傳遞值到custom:
參數,創建自定義SASS功能,然後調用從薩斯文件/腳本中。這是很尷尬的,因爲我有創建相應類型的對象從函數返回,即Sass::Script::String
,而不是String
。
是否可以使用該方法時Sass.compile_file
注入變量到薩斯範圍是什麼?設置薩斯變量納入Sass.compile_file
目前我傳遞值到custom:
參數,創建自定義SASS功能,然後調用從薩斯文件/腳本中。這是很尷尬的,因爲我有創建相應類型的對象從函數返回,即Sass::Script::String
,而不是String
。
我想根據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