David Moores
David Moores

Reputation: 1145

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)

Upvotes: 6

Views: 2021

Answers (2)

sawa
sawa

Reputation: 168239

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)

Upvotes: 10

hlee
hlee

Reputation: 339

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.

Upvotes: 1

Related Questions