Class: Sass::Engine

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
/var/www/sass-pages/.sass/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',
  :syntax => :sass,
  :filesystem_importer => Sass::Importers::Filesystem
}.freeze

Constants included from Util

RUBY_ENGINE, RUBY_VERSION

Instance Attribute Summary

Class Method Summary

Instance Method Summary

Methods included from Util

#abstract, #ap_geq?, #ap_geq_3?, #array_minus, #av_template_class, #caller_info, #check_encoding, #check_range, #check_sass_encoding, #destructure, #enum_cons, #enum_slice, #enum_with_index, #extract!, #extract_values, #flatten, #glob, #group_by_to_a, #has?, #hash_to_a, #inject_values, #inspect_obj, #intersperse, #ironruby?, #jruby1_6?, #jruby?, #jruby_version, #lcs, #macruby?, #map_hash, #map_keys, #map_vals, #merge_adjacent_strings, #ord, #paths, #powerset, #rails_env, #rails_root, #rbx?, #restrict, #ruby1?, #ruby1_8?, #ruby1_8_6?, #sass_warn, #scope, #set_eql?, #set_hash, #silence_sass_warnings, #silence_warnings, #strip_string_array, #subsequence?, #substitute, #to_hash, #undefined_conversion_error_char, #version_geq, #version_gt, #windows?, #with_extracted_values

Constructor Details

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

Creates a new Engine. Note that Engine should only be used directly when compiling in-memory Sass code. If you’re compiling a single Sass file from the filesystem, use Sass::Engine.for_file. If you’re compiling multiple files from the filesystem, use Sass::Plugin.

Parameters:

  • (String) template — The Sass template. This template can be encoded using any encoding that can be converted to Unicode. If the template contains an @charset declaration, that overrides the Ruby encoding (see the encoding documentation)
  • ({Symbol => Object}) options (defaults to: {}) — An options hash. See the Sass options documentation.

See Also:

  • {Sass::Engine.for_file}
  • {Sass::Plugin}


249
250
251
252
# File '/var/www/sass-pages/.sass/lib/sass/engine.rb', line 249

def initialize(template, options={})
  @options = self.class.normalize_options(options)
  @template = template
end

Instance Attribute Details

- ({Symbol => Object}) options (readonly)

The options for the Sass engine. See the Sass options documentation.

Returns:

  • ({Symbol => Object})


230
231
232
# File '/var/www/sass-pages/.sass/lib/sass/engine.rb', line 230

def options
  @options
end

Class Method Details

+ (Sass::Engine) for_file(filename, options)

Returns the Sass::Engine for the given file. This is preferable to Sass::Engine.new when reading from a file because it properly sets up the Engine’s metadata, enables parse-tree caching, and infers the syntax from the filename.

Parameters:

Returns:

  • (Sass::Engine) — The Engine for the given Sass or SCSS file.

Raises:



212
213
214
215
216
217
218
219
220
221
222
223
224
# File '/var/www/sass-pages/.sass/lib/sass/engine.rb', line 212

def self.for_file(filename, options)
  had_syntax = options[:syntax]

  if had_syntax
    # Use what was explicitly specificed
  elsif filename =~ /\.scss$/
    options.merge!(:syntax => :scss)
  elsif filename =~ /\.sass$/
    options.merge!(:syntax => :sass)
  end

  Sass::Engine.new(File.read(filename), options.merge(:filename => filename))
end

Instance Method Details

- ([Sass::Engine]) dependencies

Gets a set of all the documents that are (transitive) dependencies of this document, not including the document itself.

Returns:



294
295
296
297
# File '/var/www/sass-pages/.sass/lib/sass/engine.rb', line 294

def dependencies
  _dependencies(Set.new, engines = Set.new)
  Sass::Util.array_minus(engines, [self])
end

- (String) render Also known as: to_css

Render the template to CSS.

Returns:

  • (String) — The CSS

Raises:

  • (Sass::SyntaxError) — if there’s an error in the document
  • (Encoding::UndefinedConversionError) — if the source encoding cannot be converted to UTF-8
  • (ArgumentError) — if the document uses an unknown encoding with @charset


261
262
263
264
# File '/var/www/sass-pages/.sass/lib/sass/engine.rb', line 261

def render
  return _render unless @options[:quiet]
  Sass::Util.silence_sass_warnings {_render}
end

- (Encoding?) source_encoding

Returns the original encoding of the document, or nil under Ruby 1.8.

Returns:

  • (Encoding, nil)

Raises:

  • (Encoding::UndefinedConversionError) — if the source encoding cannot be converted to UTF-8
  • (ArgumentError) — if the document uses an unknown encoding with @charset


284
285
286
287
# File '/var/www/sass-pages/.sass/lib/sass/engine.rb', line 284

def source_encoding
  check_encoding!
  @original_encoding
end

- (Sass::Tree::Node) to_tree

Parses the document into its parse tree. Memoized.

Returns:

Raises:



271
272
273
274
275
# File '/var/www/sass-pages/.sass/lib/sass/engine.rb', line 271

def to_tree
  @tree ||= @options[:quiet] ?
    Sass::Util.silence_sass_warnings {_to_tree} :
    _to_tree
end