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

ATTRIBUTE_CHAR =

The character that begins a CSS attribute.

?:
SCRIPT_CHAR =

The character that designates that an attribute should be assigned to a SassScript expression.

?=
COMMENT_CHAR =

The character that designates the beginning of a comment, either Sass or CSS.

?/
SASS_COMMENT_CHAR =

The character that follows the general COMMENT_CHAR and designates a Sass comment, which is not output as a CSS comment.

?/
CSS_COMMENT_CHAR =

The character that follows the general COMMENT_CHAR and designates a CSS comment, which is embedded in the CSS document.

?*
DIRECTIVE_CHAR =

The character used to denote a compiler directive.

?@
ESCAPE_CHAR =

Designates a non-parsed rule.

?\\
MIXIN_DEFINITION_CHAR =

Designates block as mixin definition rather than CSS rules to output

?=
MIXIN_INCLUDE_CHAR =

Includes named mixin declared using MIXIN_DEFINITION_CHAR

?+
ATTRIBUTE =

The regex that matches and extracts data from attributes of the form :name attr.

/^:([^\s=:"]+)\s*(=?)(?:\s+|$)(.*)/
ATTRIBUTE_ALTERNATE_MATCHER =

The regex that matches attributes of the form name: attr.

/^[^\s:"]+\s*[=:](\s|$)/
ATTRIBUTE_ALTERNATE =

The regex that matches and extracts data from attributes of the form name: attr.

/^([^\s=:"]+)(\s*=|:)(?:\s+|$)(.*)/
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

#def_static_method, #enum_with_index, #has?, #map_hash, #map_keys, #map_vals, #merge_adjacent_strings, #powerset, #ruby1_8?, #scope, #static_method_name, #to_hash

Constructor Details

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

Returns a new instance of Engine.

Parameters:

  • template (String)

    The Sass template.

  • options (Hash<Symbol, Object>) (defaults to: {})

    An options hash; see [the Sass options documentation](../Sass.html#sass_options)



127
128
129
130
# File 'lib/sass/engine.rb', line 127

def initialize(template, options={})
  @options = DEFAULT_OPTIONS.merge(options)
  @template = template
end

Instance Method Details

#renderString Also known as: to_css

Render the template to CSS.

Returns:

  • (String)

    The CSS

Raises:



136
137
138
# File 'lib/sass/engine.rb', line 136

def render
  to_tree.render
end

#to_treeSass::Tree::Node

Parses the document into its parse tree.

Returns:

Raises:



146
147
148
149
150
151
152
# File 'lib/sass/engine.rb', line 146

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