Module: LiveScript::Rails::SprocketsProcessor

Defined in:
lib/livescript/rails/processor.rb

Class Method Summary collapse

Class Method Details

.cache_keyObject



4
5
6
# File 'lib/livescript/rails/processor.rb', line 4

def self.cache_key
  @cache_key ||= "#{name}:#{LiveScript::Source::VERSION}:#{LiveScript::VERSION}:#{LiveScript::Rails::VERSION}".freeze
end

.call(input) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/livescript/rails/processor.rb', line 8

def self.call(input)
  data = input[:data]
  options = {
    bare: true,
    header: false,
    map: 'linked-src',
    filename: input[:source_path] || input[:filename],
  }.merge(::Rails.application.config.assets.livescript || {})

  result = input[:cache].fetch([self.cache_key, data]) do
    LiveScript.compile(data, options)
  end

  # when map: none, result is String; otherwise, result is Hash
  if result.kind_of? Hash
    {
      data: result['code'],
      map: result['map'],
    }
  else
    result
  end
end