Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I run sass in ruby?

Tags:

sass

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)
like image 368
David Moores Avatar asked Feb 26 '14 13:02

David Moores


2 Answers

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)
like image 105
sawa Avatar answered Nov 15 '22 01:11

sawa


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.

like image 45
hlee Avatar answered Nov 14 '22 23:11

hlee