Module: Ruby2JS::SprocketsTransformer

Includes:
Sprockets
Defined in:
lib/ruby2js/sprockets.rb

Constant Summary collapse

VERSION =
'1'
@@options =
{}

Class Method Summary collapse

Class Method Details

.cache_keyObject



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

def self.cache_key
  @cache_key ||= "#{name}:#{Ruby2JS::VERSION::STRING}:#{VERSION}".freeze
end

.call(input) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ruby2js/sprockets.rb', line 23

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

  js, map = input[:cache].fetch([self.cache_key, data]) do
    result = Ruby2JS.convert(data, {**@@options, file: input[:filename]})
    [result.to_s, result.sourcemap.transform_keys {|key| key.to_s}]
  end

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

  { data: js, map: map }
end

.options=(options) ⇒ Object



15
16
17
# File 'lib/ruby2js/sprockets.rb', line 15

def self.options=(options)
  @@options = options
end