Class: Sass::CSS

Inherits:
Object show all
Defined in:
lib/sass/css.rb

Overview

This class contains the functionality used in the css2sass utility, namely converting CSS documents to Sass templates.

Instance Method Summary collapse

Constructor Details

#initialize(template, options = {}) ⇒ CSS

Creates a new instance of Sass::CSS that will compile the given document to a Sass string when render is called.



108
109
110
111
112
113
114
115
# File 'lib/sass/css.rb', line 108

def initialize(template, options = {})
  if template.is_a? IO
    template = template.read
  end

  @options = options
  @template = StringScanner.new(template)
end

Instance Method Details

#renderObject

Processes the document and returns the result as a string containing the CSS template.



119
120
121
122
123
124
125
126
127
128
# File 'lib/sass/css.rb', line 119

def render
  begin
    build_tree.to_sass(@options).strip + "\n"
  rescue Exception => err
    line = @template.string[0...@template.pos].split("\n").size

    err.backtrace.unshift "(css):#{line}"
    raise err
  end
end