Module: Opal::Sprockets::Processor::PlainJavaScriptLoader

Defined in:
opal/lib/opal/sprockets/processor.rb

Class Method Summary collapse

Class Method Details

.call(input) ⇒ Object



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'opal/lib/opal/sprockets/processor.rb', line 142

def self.call(input)
  sprockets = input[:environment]
  asset = OpenStruct.new(input)

  opal_extnames = sprockets.engines.map do |ext, engine|
    ext if engine <= ::Opal::Processor
  end.compact

  path_extnames     = -> path  { File.basename(path).scan(/\.[^.]+/) }
  processed_by_opal = -> asset { (path_extnames[asset.filename] & opal_extnames).any? }

  unless processed_by_opal[asset]
    [
      input[:data],
      %{if (typeof(OpalLoaded) === 'undefined') OpalLoaded = []; OpalLoaded.push(#{input[:name].to_json});}
    ].join(";\n")
  end
end