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.



53
54
55
56
57
58
59
60
# File 'lib/sass/css.rb', line 53

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.



64
65
66
67
68
69
70
71
72
73
# File 'lib/sass/css.rb', line 64

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