Class: Sprockets::SasscProcessor

Inherits:
Object
  • Object
show all
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:

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

Direct Known Subclasses

ScsscProcessor

Defined Under Namespace

Modules: Functions

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}, &block) ⇒ SasscProcessor

Returns a new instance of SasscProcessor.



40
41
42
43
44
45
46
47
48
49
50
# 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

Instance Attribute Details

#cache_keyObject (readonly)

Returns the value of attribute cache_key.



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

def cache_key
  @cache_key
end

Class Method Details

.cache_keyObject



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

def self.cache_key
  instance.cache_key
end

.call(input) ⇒ Object



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

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

.instanceObject

Public: Return singleton instance with default options.

Returns SasscProcessor object.



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

def self.instance
  @instance ||= new
end

.syntaxObject

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



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

def self.syntax
  :sass
end

Instance Method Details

#call(input) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# 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[:metadata][:map], map)

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

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