Search code examples
rubysasscompass-sass

Compile a string as a Compass file


Is there a simple way to compile a string of text as a compass (sass) stylesheet?

Example input: "section\n background: darken(white, 10%)"


Solution

  • sass has:

    -s, --stdin   Read input from standard input instead of a n input file
    

    and

    --compass  Make Compass imports available and load project configuration.
    

    You could use popen with something like this:

    output = IO.popen("sass -s --compass", "w+") do |pipe|
      pipe.puts "section\n background: darken(white, 10%)"
      pipe.close_write
      pipe.read
    end
    

    and output: section {\n background: #e6e6e6; }\n