### Home Classes Methods

### In Files

- lib/sass/engine.rb

### Parent

Object

### Namespace

- CLASS Sass::Engine::Line

### Methods

- ::for_file
- ::new
- ::normalize_options
- #_dependencies
- #dependencies
- #render
- #render_with_sourcemap
- #source_encoding
- #to_css
- #to_tree

### Class/Module Index

Quicksearch

- Sass
- Sass::BaseEnvironment
- Sass::CSS
- Sass::CacheStores
- Sass::CacheStores::Base
- Sass::CacheStores::Chain
- Sass::CacheStores::Filesystem
- Sass::CacheStores::Memory
- Sass::CacheStores::Null
- Sass::Callbacks
- Sass::Callbacks::InstanceMethods
- Sass::Engine
- Sass::Engine::Line
- Sass::Environment
- Sass::Exec
- Sass::Exec::Base
- Sass::Exec::SassConvert
- Sass::Exec::SassScss
- Sass::Exec::SassScss::Sass::Plugin.compiler
- Sass::Features
- Sass::Importers
- Sass::Importers::Base
- Sass::Importers::Filesystem
- Sass::Logger
- Sass::Logger::Base
- Sass::Logger::LogLevel
- Sass::Logger::LogLevel::ClassMethods
- Sass::Media
- Sass::Media::Query
- Sass::Media::QueryList
- Sass::Plugin
- Sass::Plugin::Compiler
- Sass::Plugin::Configuration
- Sass::Plugin::MerbBootLoader
- Sass::Plugin::Rack
- Sass::Plugin::StalenessChecker
- Sass::ReadOnlyEnvironment
- Sass::Repl
- Sass::SCSS
- Sass::SCSS::CssParser
- Sass::SCSS::Parser
- Sass::SCSS::RX
- Sass::SCSS::ScriptLexer
- Sass::SCSS::ScriptParser
- Sass::SCSS::StaticParser
- Sass::Script
- Sass::Script::CssLexer
- Sass::Script::CssParser
- Sass::Script::Functions
- Sass::Script::Functions::EvaluationContext
- Sass::Script::Lexer
- Sass::Script::Parser
- Sass::Script::Tree
- Sass::Script::Tree::Funcall
- Sass::Script::Tree::Interpolation
- Sass::Script::Tree::ListLiteral
- Sass::Script::Tree::Literal
- Sass::Script::Tree::MapLiteral
- Sass::Script::Tree::Node
- Sass::Script::Tree::Operation
- Sass::Script::Tree::Selector
- Sass::Script::Tree::StringInterpolation
- Sass::Script::Tree::UnaryOperation
- Sass::Script::Tree::Variable
- Sass::Script::Value
- Sass::Script::Value::ArgList
- Sass::Script::Value::Base
- Sass::Script::Value::Bool
- Sass::Script::Value::Color
- Sass::Script::Value::Helpers
- Sass::Script::Value::List
- Sass::Script::Value::Map
- Sass::Script::Value::Null
- Sass::Script::Value::Number
- Sass::Script::Value::String
- Sass::Selector
- Sass::Selector::AbstractSequence
- Sass::Selector::Attribute
- Sass::Selector::Class
- Sass::Selector::CommaSequence
- Sass::Selector::Element
- Sass::Selector::Id
- Sass::Selector::Parent
- Sass::Selector::Placeholder
- Sass::Selector::Pseudo
- Sass::Selector::Sequence
- Sass::Selector::Simple
- Sass::Selector::SimpleSequence
- Sass::Selector::Universal
- Sass::SemiGlobalEnvironment
- Sass::Shared
- Sass::Source
- Sass::Source::Map
- Sass::Source::Map::Mapping
- Sass::Source::Position
- Sass::Source::Range
- Sass::Stack
- Sass::Stack::Frame
- Sass::Supports
- Sass::Supports::Condition
- Sass::Supports::Declaration
- Sass::Supports::Interpolation
- Sass::Supports::Negation
- Sass::Supports::Operator
- Sass::SyntaxError
- Sass::Tree
- Sass::Tree::AtRootNode
- Sass::Tree::CharsetNode
- Sass::Tree::CommentNode
- Sass::Tree::ContentNode
- Sass::Tree::CssImportNode
- Sass::Tree::DebugNode
- Sass::Tree::DirectiveNode
- Sass::Tree::EachNode
- Sass::Tree::ErrorNode
- Sass::Tree::ExtendNode
- Sass::Tree::ForNode
- Sass::Tree::FunctionNode
- Sass::Tree::IfNode
- Sass::Tree::ImportNode
- Sass::Tree::KeyframeRuleNode
- Sass::Tree::MediaNode
- Sass::Tree::MixinDefNode
- Sass::Tree::MixinNode
- Sass::Tree::Node
- Sass::Tree::PropNode
- Sass::Tree::ReturnNode
- Sass::Tree::RootNode
- Sass::Tree::RuleNode
- Sass::Tree::SupportsNode
- Sass::Tree::TraceNode
- Sass::Tree::VariableNode
- Sass::Tree::Visitors
- Sass::Tree::Visitors::Base
- Sass::Tree::Visitors::CheckNesting
- Sass::Tree::Visitors::Convert
- Sass::Tree::Visitors::Cssize
- Sass::Tree::Visitors::Cssize::Bubble
- Sass::Tree::Visitors::DeepCopy
- Sass::Tree::Visitors::Extend
- Sass::Tree::Visitors::Perform
- Sass::Tree::Visitors::SetOptions
- Sass::Tree::Visitors::ToCss
- Sass::Tree::WarnNode
- Sass::Tree::WhileNode
- Sass::UnitConversionError
- Sass::Util
- Sass::Util::CrossPlatformRandom
- Sass::Util::MultibyteStringScanner
- Sass::Util::NormalizedMap
- Sass::Util::StaticConditionalContext
- Sass::Util::SubsetMap
- Sass::Util::Test
- Sass::Version
- ActionController
- ActionController::Base
- Object
- OrderedHash

No matching classes.

# Sass::Engine

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

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

### Constants

COMMENT_CHAR

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

CONTENT_RE
CSS_COMMENT_CHAR

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

DEFAULT_OPTIONS

  The default options for Sass::Engine. @api public

DIRECTIVES
DIRECTIVE_CHAR

  The character used to denote a compiler directive.

ESCAPE_CHAR

  Designates a non-parsed rule.

FUNCTION_RE
MIXIN_DEFINITION_CHAR

  Designates block as mixin definition rather than CSS rules to output

MIXIN_DEF_RE
MIXIN_INCLUDE_CHAR

  Includes named mixin declared using MIXIN_DEFINITION_CHAR

MIXIN_INCLUDE_RE
PROPERTY_CHAR

  The character that begins a CSS property.

PROPERTY_OLD

  The regex that matches and extracts data from properties of the form `:name prop`.

SASS_COMMENT_CHAR

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

SASS_LOUD_COMMENT_CHAR

  The character that indicates that a comment allows interpolation and should be preserved even in `:compressed` mode.

### Attributes

options[R]

The options for the Sass engine. See {file:SASS_REFERENCE.md#sass_options the Sass options documentation}.

@return [{Symbol => Object}]

### Public Class Methods

for_file(filename, options) click to toggle source

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.

@param filename [String] The path to the Sass or SCSS file @param options [{Symbol => Object}] The options hash;

    See {file:SASS_REFERENCE.md#sass_options the Sass options documentation}.

@return [Sass::Engine] The Engine for the given Sass or SCSS file. @raise [Sass::SyntaxError] if there’s an error in the document.

    # File lib/sass/engine.rb, line 218
    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

new(template, options = {}) click to toggle source

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}.

@param template [String] 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 {file:SASS_REFERENCE.md#encodings the encoding documentation})

@param options [{Symbol => Object}] An options hash.

    See {file:SASS_REFERENCE.md#sass_options the Sass options documentation}.

@see {Sass::Engine.for_file} @see {Sass::Plugin}

    # File lib/sass/engine.rb, line 255
    def initialize(template, options = {})
      @options = self.class.normalize_options(options)
      @template = template
    end

normalize_options(options) click to toggle source

Converts a Sass options hash into a standard form, filling in default values and resolving aliases.

@param options [{Symbol => Object}] The options hash;

    see {file:SASS_REFERENCE.md#sass_options the Sass options documentation}

@return [{Symbol => Object}] The normalized options hash. @private

    # File lib/sass/engine.rb, line 174
    def self.normalize_options(options)
      options = DEFAULT_OPTIONS.merge(options.reject {|k, v| v.nil?})

      # If the `:filename` option is passed in without an importer,
      # assume it's using the default filesystem importer.
      options[:importer] ||= options[:filesystem_importer].new(".") if options[:filename]

      # Tracks the original filename of the top-level Sass file
      options[:original_filename] ||= options[:filename]

      options[:cache_store] ||= Sass::CacheStores::Chain.new(
        Sass::CacheStores::Memory.new, Sass::CacheStores::Filesystem.new(options[:cache_location]))
      # Support both, because the docs said one and the other actually worked
      # for quite a long time.
      options[:line_comments] ||= options[:line_numbers]

      options[:load_paths] = (options[:load_paths] + Sass.load_paths).map do |p|
        next p unless p.is_a?(String) || (defined?(Pathname) && p.is_a?(Pathname))
        options[:filesystem_importer].new(p.to_s)
      end

      # 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
      options[:sourcemap] = :auto if options[:sourcemap] == true
      options[:sourcemap] = :none if options[:sourcemap] == false

      options
    end

### Public Instance Methods

_dependencies(seen, engines) click to toggle source

Helper for {#dependencies}.

@private

    # File lib/sass/engine.rb, line 328
    def _dependencies(seen, engines)
      key = [@options[:filename], @options[:importer]]
      return if seen.include?(key)
      seen << key
      engines << self
      to_tree.grep(Tree::ImportNode) do |n|
        next if n.css_import?
        n.imported_file._dependencies(seen, engines)
      end
    end

dependencies() click to toggle source

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

@return [[Sass::Engine]] The dependency documents.

    # File lib/sass/engine.rb, line 320
    def dependencies
      _dependencies(Set.new, engines = Set.new)
      Sass::Util.array_minus(engines, [self])
    end

render() click to toggle source

Render the template to CSS.

@return [String] The CSS @raise [Sass::SyntaxError] if there’s an error in the document @raise [Encoding::UndefinedConversionError] if the source encoding

    cannot be converted to UTF-8

@raise [ArgumentError] if the document uses an unknown encoding with `@charset`

    # File lib/sass/engine.rb, line 267
    def render
      return _to_tree.render unless @options[:quiet]
      Sass::Util.silence_sass_warnings {_to_tree.render}
    end

Also aliased as: to_css
render_with_sourcemap(sourcemap_uri) click to toggle source

Render the template to CSS and return the source map.

@param sourcemap_uri [String] The sourcemap URI to use in the

    `@sourceMappingURL` comment. If this is relative, it should be relative
    to the location of the CSS file.

@return [(String, Sass::Source::Map)] The rendered CSS and the associated

    source map

@raise [Sass::SyntaxError] if there’s an error in the document, or if the

    public URL for this document couldn't be determined.

@raise [Encoding::UndefinedConversionError] if the source encoding

    cannot be converted to UTF-8

@raise [ArgumentError] if the document uses an unknown encoding with `@charset`

    # File lib/sass/engine.rb, line 284
    def render_with_sourcemap(sourcemap_uri)
      return _render_with_sourcemap(sourcemap_uri) unless @options[:quiet]
      Sass::Util.silence_sass_warnings {_render_with_sourcemap(sourcemap_uri)}
    end

source_encoding() click to toggle source

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

@return [Encoding, nil] @raise [Encoding::UndefinedConversionError] if the source encoding

    cannot be converted to UTF-8

@raise [ArgumentError] if the document uses an unknown encoding with `@charset`

    # File lib/sass/engine.rb, line 310
    def source_encoding
      check_encoding!
      @source_encoding
    end

to_css() click to toggle source
Alias for: render
to_tree() click to toggle source

Parses the document into its parse tree. Memoized.

@return [Sass::Tree::Node] The root of the parse tree. @raise [Sass::SyntaxError] if there’s an error in the document

    # File lib/sass/engine.rb, line 295
    def to_tree
      @tree ||= if @options[:quiet]
                  Sass::Util.silence_sass_warnings {_to_tree}
                else
                  _to_tree
                end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.