Compile a string as a Compass file

Is there an easy way to compile a line of text into a compass (sass) style sheet?

Input example: "section\n background: darken(white, 10%)"

+4
source share
2 answers

sass has:

 -s, --stdin Read input from standard input instead of an input file 

and

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

You can 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 section {\n background: #e6e6e6; }\n

+4
source

You can use the class method of Sass.compile . To use the .sass syntax (indent), you need to pass the parameter :syntax => :sass :

 require 'sass' Sass.compile "section\n background: darken(white, 10%)", syntax: :sass #=> "section {\n background: #e6e6e6; }\n" 

Note. Compass alone does not provide an equivalent function, so if you want all the useful properties of Compass you need @import 'compass' in your code.

+2
source

Source: https://habr.com/ru/post/1379304/


All Articles