Class | Sass::CSS |
In: |
lib/sass/css.rb
|
Parent: | Object |
This class converts CSS documents into Sass templates. It works by parsing the CSS document into a {Sass::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"
@param template [String] The CSS code @option options :old [Boolean] (false)
Whether or not to output old property syntax (`:color blue` as opposed to `color: blue`).
# File lib/sass/css.rb, line 65 65: def initialize(template, options = {}) 66: if template.is_a? IO 67: template = template.read 68: end 69: 70: @options = options.dup 71: # Backwards compatibility 72: @options[:old] = true if @options[:alternate] == false 73: @template = StringScanner.new(template) 74: end
Converts the CSS template into Sass code.
@return [String] The resulting Sass code
# File lib/sass/css.rb, line 79 79: def render 80: begin 81: build_tree.to_sass(0, @options).strip + "\n" 82: rescue Exception => err 83: line = @template.string[0...@template.pos].split("\n").size 84: 85: err.backtrace.unshift "(css):#{line}" 86: raise err 87: end 88: end