123456789_123456789_123456789_123456789_123456789_

Module: Sprockets::CoffeeScriptProcessor

Relationships & Source Files
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 information see:

github.com/rails/ruby-coffee-script

Constant Summary

Class Method Summary

Class Method Details

.cache_key

[ GitHub ]

  
# 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)

[ GitHub ]

  
# 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, input[:filename]]) 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[:][:map], map)

  { data: js, map: map }
end