Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I take a string of SCSS and have it output CSS?

I have templates in my application that have their own style sheets. I'd like to let my users (and myself) take advantage of SCSS features. However, I haven't been able to find out how to send the Sass gem a string of SCSS, and have it return regular CSS.

(I also haven't been able to find it on google, nor is it easy to find in the documentation.)

So how do I do it?

like image 449
RandallB Avatar asked Dec 21 '22 01:12

RandallB


1 Answers

Just do:

# your SCSS string
str = %Q{ 
  $text-color: #555555;
  $unfocused-background-color: #f1f0ec;
  body {
    background: $unfocused-background-color;
    color: $text-color;
  }
}
se = Sass::Engine.new(str, :syntax => :scss)
se.render 
# => "body {\n  background: #f1f0ec;\n  color: #555555; }\n"

See the Sass reference docs here: http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html.

like image 183
Jacob Brown Avatar answered Jan 06 '23 00:01

Jacob Brown