123456789_123456789_123456789_123456789_123456789_

Class: Sprockets::SasscProcessor

Relationships & Source Files
Namespace Children
Modules:
Extension / Inclusion / Inheritance Descendants
Subclasses:
Inherits: Object
Defined in: lib/sprockets/sassc_processor.rb

Overview

Processor engine class for the SASS/SCSS compiler. Depends on the sassc gem.

For more information see:

github.com/sass/sassc-ruby github.com/sass/sassc-rails

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(options = {}, &block) ⇒ SasscProcessor

[ GitHub ]

  
# File 'lib/sprockets/sassc_processor.rb', line 40

def initialize(options = {}, &block)
  @cache_version = options[:cache_version]
  @cache_key = "#{self.class.name}:#{VERSION}:#{Autoload::SassC::VERSION}:#{@cache_version}".freeze
  @importer_class = options[:importer]
  @sass_config = options[:sass_config] || {}
  @functions = Module.new do
    include Functions
    include options[:functions] if options[:functions]
    class_eval(&block) if block_given?
  end
end

Class Method Details

.cache_key

[ GitHub ]

  
# File 'lib/sprockets/sassc_processor.rb', line 34

def self.cache_key
  instance.cache_key
end

.call(input)

[ GitHub ]

  
# File 'lib/sprockets/sassc_processor.rb', line 30

def self.call(input)
  instance.call(input)
end

.instance

Public: Return singleton instance with default options.

Returns SasscProcessor object.

[ GitHub ]

  
# File 'lib/sprockets/sassc_processor.rb', line 26

def self.instance
  @instance ||= new
end

.syntax

Internal: Defines default sass syntax to use. Exposed so the ScsscProcessor may override it.

[ GitHub ]

  
# File 'lib/sprockets/sassc_processor.rb', line 19

def self.syntax
  :sass
end

Instance Attribute Details

#cache_key (readonly)

[ GitHub ]

  
# File 'lib/sprockets/sassc_processor.rb', line 38

attr_reader :cache_key

Instance Method Details

#call(input)

[ GitHub ]

  
# File 'lib/sprockets/sassc_processor.rb', line 52

def call(input)
  context = input[:environment].context_class.new(input)

  options = engine_options(input, context)
  engine = Autoload::SassC::Engine.new(input[:data], options)

  css = Utils.module_include(Autoload::SassC::Script::Functions, @functions) do
    engine.render.sub(/^\n^\/\*# sourceMappingURL=.*\*\/$/m, '')
  end

  begin
    map = SourceMapUtils.format_source_map(JSON.parse(engine.source_map), input)
    map = SourceMapUtils.combine_source_maps(input[:][:map], map)

    engine.dependencies.each do |dependency|
      context.[:dependencies] << URIUtils.build_file_digest_uri(dependency.filename)
    end
  rescue SassC::NotRenderedError
    map = input[:][:map]
  end

  context..merge(data: css, map: map)
end

#engine_options(input, context)

[ GitHub ]

  
# File 'lib/sprockets/sassc_processor.rb', line 273

def engine_options(input, context)
  merge_options({
    filename: input[:filename],
    syntax: self.class.syntax,
    load_paths: input[:environment].paths,
    importer: @importer_class,
    source_map_contents: false,
    source_map_file: "#{input[:filename]}.map",
    omit_source_map_url: true,
    sprockets: {
      context: context,
      environment: input[:environment],
      dependencies: context.[:dependencies]
    }
  })
end

#merge_options(options) (private)

[ GitHub ]

  
# File 'lib/sprockets/sassc_processor.rb', line 78

def merge_options(options)
  defaults = @sass_config.dup

  if load_paths = defaults.delete(:load_paths)
    options[:load_paths] += load_paths
  end

  options.merge!(defaults)
  options
end