Class: Sass::CSS
Overview
This class converts CSS documents into Sass templates. It works by parsing the CSS document into a Tree structure, and then applying various transformations to the structure to produce more concise and idiomatic Sass.
Example usage:
Sass::CSS.new("p { color: blue }").render #=> "p\n color: blue"
Instance Method Summary collapse
-
#initialize(template, options = {}) ⇒ CSS
constructor
A new instance of CSS.
-
#render ⇒ String
Converts the CSS template into Sass code.
Constructor Details
#initialize(template, options = {}) ⇒ CSS
Returns a new instance of CSS.
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/sass/css.rb', line 65
def initialize(template, options = {})
if template.is_a? IO
template = template.read
end
@options = options.dup
# Backwards compatibility
@options[:old] = true if @options[:alternate] == false
@template = StringScanner.new(template)
end
|
Instance Method Details
#render ⇒ String
Converts the CSS template into Sass code.
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/sass/css.rb', line 79 def render begin build_tree.to_sass(0, @options).strip + "\n" rescue Exception => err line = @template.string[[email protected]].split("\n").size err.backtrace.unshift "(css):#{line}" raise err end end |