Module: Sprockets::CoffeeScriptProcessor

Defined in:
lib/sprockets/coffee_script_processor.rb

Overview

Processor engine class for the CoffeeScript compiler. Depends on the `coffee-script` and `coffee-script-source` gems.

For more infomation see:

https://github.com/rails/ruby-coffee-script

Constant Summary collapse

VERSION =
'2'

Class Method Summary collapse

Class Method Details

.cache_keyObject


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

def self.cache_key
  @cache_key ||= "#{name}:#{Autoload::CoffeeScript::Source.version}:#{VERSION}".freeze
end

.call(input) ⇒ Object


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/sprockets/coffee_script_processor.rb', line 20

def self.call(input)
  data = input[:data]

  js, map = input[:cache].fetch([self.cache_key, data]) do
    result = Autoload::CoffeeScript.compile(
      data,
      sourceMap: "v3",
      sourceFiles: [File.basename(input[:filename])],
      generatedFile: input[:filename]
    )
    [result['js'], JSON.parse(result['v3SourceMap'])]
  end

  map = SourceMapUtils.format_source_map(map, input)
  map = SourceMapUtils.combine_source_maps(input[:metadata][:map], map)

  { data: js, map: map }
end