Class: Sass::CSS
- Inherits:
- Object
- Object
- Sass::CSS
- Defined in:
- /Users/ceppstei/Projects/sass-lang/.sass/lib/sass/css.rb
Overview
This class converts CSS documents into Sass or SCSS 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/SCSS.
Example usage:
Sass::CSS.new("p { color: blue }").render(:sass) #=> "p\n color: blue"
Sass::CSS.new("p { color: blue }").render(:scss) #=> "p {\n color: blue; }"
Instance Method Summary (collapse)
- - (CSS) initialize(template, options = {}) constructor
A new instance of CSS.
- - (String) render(fmt = :sass)
Converts the CSS template into Sass or SCSS code.
- - (Encoding?) source_encoding
Returns the original encoding of the document, or
nil
under Ruby 1.8.
Constructor Details
- (CSS) initialize(template, options = {})
Returns a new instance of CSS
29 30 31 32 33 34 35 36 37 38 39 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/css.rb', line 29
def initialize(template, options = {})
if template.is_a? IO
template = template.read
end
@options = options.merge(:_convert => true)
# Backwards compatibility
@options[:old] = true if @options[:alternate] == false
@template = template
@checked_encoding = false
end |
Instance Method Details
- (String) render(fmt = :sass)
Converts the CSS template into Sass or SCSS code.
46 47 48 49 50 51 52 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/css.rb', line 46
def render(fmt = :sass)
check_encoding!
build_tree.send("to_#{fmt}", @options).strip + "\n"
rescue Sass::SyntaxError => err
err.modify_backtrace(:filename => @options[:filename] || '(css)')
raise err
end |
- (Encoding?) source_encoding
Returns the original encoding of the document, or nil
under Ruby 1.8.
61 62 63 64 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/css.rb', line 61
def source_encoding
check_encoding!
@original_encoding
end |