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

Constant Summary

DEFAULT_OPTIONS = The default options for Sass::Engine.
{
  :style => :nested,
  :load_paths => ['.'],
  :cache => true,
  :cache_location => './.sass-cache',
}.freeze

Constants included from Haml::Util

RUBY_VERSION

Instance Method Summary

Methods included from Haml::Util

#assert_html_safe!, #av_template_class, #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?, #ruby1_8?, #scope, #silence_warnings, #static_method_name, #to_hash

Constructor Details

- (Engine) initialize(template, options = {})

A new instance of Engine

Parameters:



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

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

- (String) render Also known as: to_css

Render the template to CSS.

Returns:

  • (String) — The CSS

Raises:



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

def render
  to_tree.render
end

- (Sass::Tree::Node) to_tree

Parses the document into its parse tree.

Returns:

Raises:



173
174
175
176
177
178
179
# File 'lib/sass/engine.rb', line 173

def to_tree
  root = Tree::Node.new
  append_children(root, tree(tabulate(@template)).first, true)
  root.options = @options
  root
rescue SyntaxError => e; e.add_metadata(@options[:filename], @line)
end