How do I call a sass function from inside a ruby file?
如何在ruby文件中调用sass函数?
The following line works in the command prompt:
以下行在命令提示符下工作:
sass C:\Users\..etc..\main.scss
I need to put this into a Ruby file. So I wrote as below in a Ruby file:
我需要把它放到一个Ruby文件中。所以我在Ruby文件中写了如下:
require 'sass'
$arg1 = 'C:/Users/dmoores/Desktop/testst/main.scss'
sass $arg1
But it complains with the following:
但它抱怨如下:
undefined method `sass' for main:Object (NoMethodError)
2 个解决方案
#1
10
Set the options as you need, then use Sass::Engine#render
.
根据需要设置选项,然后使用Sass :: Engine#render。
require "sass"
options = {
cache: true,
syntax: :sass,
style: :compressed,
filename: original_file_name,
...
}
render = Sass::Engine.new(File.read(original_file_name), options).render
File.write(output_file_name, render)
#2
1
This documentation should help:
该文档应该有所帮助:
http://sass-lang.com/documentation/file.SASS_REFERENCE.html
If you've already installed the Sass gem, you can run it from the Command Line. To use Sass in your ruby script, you need to make a Sass object and then use the functions associated with it.
如果您已经安装了Sass gem,则可以从命令行运行它。要在ruby脚本中使用Sass,您需要创建一个Sass对象,然后使用与之关联的函数。
#1
10
Set the options as you need, then use Sass::Engine#render
.
根据需要设置选项,然后使用Sass :: Engine#render。
require "sass"
options = {
cache: true,
syntax: :sass,
style: :compressed,
filename: original_file_name,
...
}
render = Sass::Engine.new(File.read(original_file_name), options).render
File.write(output_file_name, render)
#2
1
This documentation should help:
该文档应该有所帮助:
http://sass-lang.com/documentation/file.SASS_REFERENCE.html
If you've already installed the Sass gem, you can run it from the Command Line. To use Sass in your ruby script, you need to make a Sass object and then use the functions associated with it.
如果您已经安装了Sass gem,则可以从命令行运行它。要在ruby脚本中使用Sass,您需要创建一个Sass对象,然后使用与之关联的函数。