Class: Sass::CSS

Inherits:
Object show all
Defined in:
lib/gems/haml-2.0.4/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.



114
115
116
117
118
119
120
121
# File 'lib/gems/haml-2.0.4/lib/sass/css.rb', line 114

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.



125
126
127
128
129
130
131
132
133
134
# File 'lib/gems/haml-2.0.4/lib/sass/css.rb', line 125

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