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 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

Public Instance methods

Converts the CSS template into Sass code.

@return [String] The resulting Sass code

[Source]

    # 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

[Validate]