Class: Sass::CSS
Overview
This class converts CSS documents into Sass templates. It works by parsing the CSS document into a 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"
Instance Method Summary collapse
-
#initialize(template, options = {}) ⇒ CSS
constructor
A new instance of CSS.
-
#render ⇒ String
Converts the CSS template into Sass code.
Constructor Details
#initialize(template, options = {}) ⇒ CSS
Returns a new instance of CSS.
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/sass/css.rb', line 68
def initialize(template, options = {})
if template.is_a? IO
template = template.read
end
@line = 1
@options = options.dup
# Backwards compatibility
@options[:old] = true if @options[:alternate] == false
@template = StringScanner.new(template)
end
|
Instance Method Details
#render ⇒ String
Converts the CSS template into Sass code.
84 85 86 87 88 89 90 91 92 93 |
# File 'lib/sass/css.rb', line 84
def render
Haml::Util.check_encoding(@template.string) do |msg, line|
raise Sass::SyntaxError.new(msg, :line => line)
end
build_tree.to_sass(0, @options).strip + "\n"
rescue Sass::SyntaxError => err
err.modify_backtrace(:filename => @options[:filename] || '(css)', :line => @line)
raise err
end
|