Class: Sprockets::SassTemplate

### Home Classes Methods

### In Files

- lib/sprockets/sass_template.rb

### Parent

Tilt::Template

### Methods

- ::engine_initialized?
- #evaluate
- #initialize_engine
- #prepare
- #syntax

### Class/Module Index

Quicksearch

- Sprockets
- Sprockets::ArgumentError
- Sprockets::Asset
- Sprockets::AssetAttributes
- Sprockets::Base
- Sprockets::BundledAsset
- Sprockets::Cache
- Sprockets::Cache::FileStore
- Sprockets::Caching
- Sprockets::CharsetNormalizer
- Sprockets::CircularDependencyError
- Sprockets::ClosureCompressor
- Sprockets::Compressing
- Sprockets::ContentTypeMismatch
- Sprockets::Context
- Sprockets::DirectiveProcessor
- Sprockets::EcoTemplate
- Sprockets::EjsTemplate
- Sprockets::EncodingError
- Sprockets::EngineError
- Sprockets::Engines
- Sprockets::Environment
- Sprockets::Error
- Sprockets::FileNotFound
- Sprockets::FileOutsidePaths
- Sprockets::Index
- Sprockets::JstProcessor
- Sprockets::Manifest
- Sprockets::Mime
- Sprockets::NotImplementedError
- Sprockets::Paths
- Sprockets::ProcessedAsset
- Sprockets::ProcessedAsset::DependencyFile
- Sprockets::Processing
- Sprockets::Processor
- Sprockets::SafetyColons
- Sprockets::SassCacheStore
- Sprockets::SassCompressor
- Sprockets::SassFunctions
- Sprockets::SassImporter
- Sprockets::SassTemplate
- Sprockets::ScssTemplate
- Sprockets::Server
- Sprockets::StaticAsset
- Sprockets::UglifierCompressor
- Sprockets::UnserializeError
- Sprockets::Utils
- Sprockets::YUICompressor
- Rake
- Rake::SprocketsTask

No matching classes.

# Sprockets::SassTemplate

This custom Tilt handler replaces the one built into Tilt. The main difference is that it uses a custom importer that plays nice with sprocket's caching system.

See `SassImporter` for more infomation.

### Public Class Methods

engine_initialized?() click to toggle source

    # File lib/sprockets/sass_template.rb, line 12
    def self.engine_initialized?
      defined?(::Sass::Engine) && defined?(::Sass::Script::Functions) &&
        ::Sass::Script::Functions < Sprockets::SassFunctions
    end

### Public Instance Methods

evaluate(context, locals, &block) click to toggle source

    # File lib/sprockets/sass_template.rb, line 36
    def evaluate(context, locals, &block)
      # Use custom importer that knows about Sprockets Caching
      cache_store = SassCacheStore.new(context.environment)

      options = {
        :filename => eval_file,
        :line => line,
        :syntax => syntax,
        :cache_store => cache_store,
        :importer => SassImporter.new(context.pathname.to_s),
        :load_paths => context.environment.paths.map { |path| SassImporter.new(path.to_s) },
        :sprockets => {
          :context => context,
          :environment => context.environment
        }
      }

      result = ::Sass::Engine.new(data, options).render

      # Track all imported files
      filenames = ([options[:importer].imported_filenames] + options[:load_paths].map(&:imported_filenames)).flatten.uniq
      filenames.each { |filename| context.depend_on(filename) }

      result
    rescue ::Sass::SyntaxError => e
      # Annotates exception message with parse line number
      context.__LINE__ = e.sass_backtrace.first[:line]
      raise e
    end

initialize_engine() click to toggle source

    # File lib/sprockets/sass_template.rb, line 17
    def initialize_engine
      # Double check constant to avoid tilt warning
      unless defined? ::Sass
        require_template_library 'sass'
      end

      # Install custom functions. It'd be great if this didn't need to
      # be installed globally, but could be passed into Engine as an
      # option.
      ::Sass::Script::Functions.send :include, Sprockets::SassFunctions
    end

prepare() click to toggle source

    # File lib/sprockets/sass_template.rb, line 29
    def prepare
    end

syntax() click to toggle source

    # File lib/sprockets/sass_template.rb, line 32
    def syntax
      :sass
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.