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"

Methods

new   render  

Public Class methods

@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`).

[Source]

    # File lib/sass/css.rb, line 67
67:     def initialize(template, options = {})
68:       if template.is_a? IO
69:         template = template.read
70:       end
71: 
72:       @options = options.dup
73:       # Backwards compatibility
74:       @options[:old] = true if @options[:alternate] == false
75:       @template = StringScanner.new(template)
76:     end

Public Instance methods

Converts the CSS template into Sass code.

@return [String] The resulting Sass code

[Source]

    # File lib/sass/css.rb, line 81
81:     def render
82:       begin
83:         build_tree.to_sass(0, @options).strip + "\n"
84:       rescue Exception => err
85:         line = @template.string[0...@template.pos].split("\n").size
86: 
87:         err.backtrace.unshift "(css):#{line}"
88:         raise err
89:       end
90:     end

[Validate]