0
votes

I'm using JRuby to use compass for compiling sass css

I know how to compile scss file using compass:

compiler = Compass::Compiler.new(
             # Compass working directory
             '.',
             # Input directory
             'styles/scss',
             # Output directory
             'styles/css',
             # Compass options
             { :style => :scss}
           )        
compiler.compile('test.scss','test.css')

BUT I'd like to compile some compass source that I have in a String rather than in a file I've been diving into Compass::Compiler source but I've not seen any way to compile a scss string instead of a file

NOTE: Using SASS compiler directly instead of compass I can compile a scss string

engine = Sass::Engine.new(source,:syntax => :scss)
result = engine.render
1

1 Answers

0
votes

After digging a bit more in the Compass::Compiler ruby type, I found that after all it's delegating to Sass::Engine in a siple way:

The compile function is something like:

def compile(sass_filename, css_filename)
    ...
    engine(sass_filename, css_filename).render
    ...
end

which is calling the engine function:

def engine(sass_filename, css_filename)
    ...
    Sass::Engine.new(open(sass_filename).read, opts)
    ...
end

so to compile a String using compass the method is the same used to compile using raw Sass:

Sass::Engine.new(scssString,{:syntax => :scss,
                             :compass => {:css_dir => 'stylesheets',:js_dir => 'javascripts',:images_dir => 'images'}})
result = engine.render