Class: Sprockets::SassProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/sprockets/sass_processor.rb

Overview

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

For more infomation see:

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

Direct Known Subclasses

ScssProcessor

Defined Under Namespace

Modules: Functions Classes: CacheStore

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Public: Initialize template with custom options.

options - Hash

cache_version - String custom cache version. Used to force a cache
                change after code changes are made to Sass Functions.


37
38
39
40
41
42
43
44
45
# File 'lib/sprockets/sass_processor.rb', line 37

def initialize(options = {}, &block)
  @cache_version = options[:cache_version]

  @functions = Module.new do
    include Functions
    include options[:functions] if options[:functions]
    class_eval(&block) if block_given?
  end
end

Class Method Details

.call(input) ⇒ Object



27
28
29
# File 'lib/sprockets/sass_processor.rb', line 27

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

.instanceObject

Public: Return singleton instance with default options.

Returns SassProcessor object.



23
24
25
# File 'lib/sprockets/sass_processor.rb', line 23

def self.instance
  @instance ||= new
end

.syntaxObject

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



16
17
18
# File 'lib/sprockets/sass_processor.rb', line 16

def self.syntax
  :sass
end

Instance Method Details

#call(input) ⇒ Object



47
48
49
50
51
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/sass_processor.rb', line 47

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

  options = {
    filename: input[:filename],
    syntax: self.class.syntax,
    cache_store: CacheStore.new(input[:cache], @cache_version),
    load_paths: input[:environment].paths,
    sprockets: {
      context: context,
      environment: input[:environment],
      dependencies: context.[:dependency_paths]
    }
  }

  engine = ::Sass::Engine.new(input[:data], options)

  css = Utils.module_include(::Sass::Script::Functions, @functions) do
    engine.render
  end

  # Track all imported files
  engine.dependencies.map do |dependency|
    context.[:dependency_paths] << dependency.options[:filename]
  end

  context..merge(data: css)
end