简体   繁体   中英

How do I run sass in ruby?

How do I call a sass function from inside a ruby file?

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:

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)

Set the options as you need, then use 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)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM