Class: Opal::SourceMapServer

Inherits:
Object
  • Object
show all
Defined in:
opal/lib/opal/sprockets/server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sprockets) ⇒ SourceMapServer

Returns a new instance of SourceMapServer



13
14
15
# File 'opal/lib/opal/sprockets/server.rb', line 13

def initialize sprockets
  @sprockets = sprockets
end

Instance Attribute Details

#prefixObject



21
22
23
# File 'opal/lib/opal/sprockets/server.rb', line 21

def prefix
  @prefix ||= '/__opal_source_maps__'
end

#sprocketsObject (readonly)

Returns the value of attribute sprockets



17
18
19
# File 'opal/lib/opal/sprockets/server.rb', line 17

def sprockets
  @sprockets
end

Instance Method Details

#call(env) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'opal/lib/opal/sprockets/server.rb', line 29

def call(env)
  path_info = env['PATH_INFO']

  if path_info =~ /\.js\.map$/
    path   = env['PATH_INFO'].gsub(/^\/|\.js\.map$/, '')
    asset  = sprockets[path]
    return [404, {}, []] if asset.nil?

    return [200, {"Content-Type" => "text/json"}, [$OPAL_SOURCE_MAPS[asset.pathname].to_s]]
  else
    return [200, {"Content-Type" => "text/text"}, [File.read(sprockets.resolve(path_info))]]
  end
end

#inspectObject



25
26
27
# File 'opal/lib/opal/sprockets/server.rb', line 25

def inspect
  "#<#{self.class}:#{object_id}>"
end