Class: Sass::Engine

Inherits:
Object show all
Includes:
Haml::Util
Defined in:
lib/sass/engine.rb

Overview

This class handles the parsing and compilation of the Sass template. Example usage:

template = File.load('stylesheets/sassy.sass')
sass_engine = Sass::Engine.new(template)
output = sass_engine.render
puts output

Defined Under Namespace

Classes: Line

Constant Summary collapse

DEFAULT_OPTIONS =

The default options for Sass::Engine.

{
  :style => :nested,
  :load_paths => ['.'],
  :cache => true,
  :cache_location => './.sass-cache',
}.freeze

Constants included from Haml::Util

Haml::Util::RUBY_VERSION

Instance Method Summary collapse

Methods included from Haml::Util

#assert_html_safe!, #av_template_class, #caller_info, #check_encoding, #def_static_method, #enum_with_index, #has?, #html_safe, #map_hash, #map_keys, #map_vals, #merge_adjacent_strings, #powerset, #rails_env, #rails_root, #rails_safe_buffer_class, #rails_xss_safe?, #restrict, #ruby1_8?, #scope, #silence_warnings, #static_method_name, #to_hash

Constructor Details

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

Returns a new instance of Engine.

Parameters:



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/sass/engine.rb', line 144

def initialize(template, options={})
  @options = DEFAULT_OPTIONS.merge(options.reject {|k, v| v.nil?})
  @template = template

  # Support both, because the docs said one and the other actually worked
  # for quite a long time.
  @options[:line_comments] ||= @options[:line_numbers]

  # Backwards compatibility
  @options[:property_syntax] ||= @options[:attribute_syntax]
  case @options[:property_syntax]
  when :alternate; @options[:property_syntax] = :new
  when :normal; @options[:property_syntax] = :old
  end
end

Instance Method Details

#renderString Also known as: to_css

Render the template to CSS.

Returns:

  • (String)

    The CSS

Raises:



164
165
166
# File 'lib/sass/engine.rb', line 164

def render
  to_tree.render
end

#to_treeSass::Tree::Node

Parses the document into its parse tree.

Returns:

Raises:



174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/sass/engine.rb', line 174

def to_tree
  @template = check_encoding(@template) {|msg, line| raise Sass::SyntaxError.new(msg, :line => line)}

  root = Tree::RootNode.new(@template)
  append_children(root, tree(tabulate(@template)).first, true)
  root.options = @options
  root
rescue SyntaxError => e
  e.modify_backtrace(:filename => @options[:filename], :line => @line)
  e.sass_template = @template
  raise e
end