2
votes

I have a little ruby script that uses Compass to compile *.scss files, since Compass and Sass are ruby-based I am just using the compiler directly like this (based on this SO question):

require 'compass'
require 'sass'

Compass.add_configuration({
  :project_path => '.',
  :sass_path => 'css',
  :css_path => 'css',
  :output_style => :compressed
},'custom')

Compass.compiler.compile('css/index.scss', 'css/index.css')

That works as expected and does the compilation, BUT, I also get this message:

Compass.compiler is deprecated. Use Compass.sass_compiler instead.

So I tried to use:

Compass.sass_compiler.compile('css/index.scss', 'test.css')

What throws an Error, telling that the class SassCompiler (NoMethodError) is not defined.

I really would like to use the suggested method, but can I use it and what do I have to require in ahead?

Thanks for help!

1

1 Answers

4
votes

After digging a bit into the source, I finally found it!

require 'compass/sass_compiler'

is the missing line!

The final line to run the compilation looks like that:

Compass.sass_compiler.compile!

Thats it.

Btw.: the Compass.sass_compiler method accepts some options (source) which are handed over to the compiler, but using Compass.add_configuration as above does the same Job.

I hope somebody can use this Information, happy compiling!

EDIT

Due to the comments here the complete code that works for my project. It is included in a build script, the following lines are from the initialisation:

require 'compass'
require 'compass/sass_compiler'

Compass.add_configuration({
  :project_path     => _(),
  :output_style     => :expanded,
  :cache_path       => '<path to cache>',
  :http_fonts_path  => '../fonts',
  :fonts_dir        => '<relative path to fonts>',
  :sass_path        => '<path to the scss files>',
  :css_path         => '<path fot the compiled css>',
  :http_images_path => '../img',
  :images_path       => '<path to images>'
},'custom-name')

And these line run in each compilation:

compiler = Compass.sass_compiler({
  :only_sass_files => [
    '<path to scss file to compile>'
  ]})
compiler.compile!

To get an overview of all possible options I recommend a look at the source and at the official documentation of sass and compass.