Class: Opal::SourceMapServer
- Defined in:
- opal/lib/opal/sprockets/server.rb
Instance Attribute Summary collapse
- 
  
    
      #prefix  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute prefix. 
- 
  
    
      #sprockets  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute sprockets. 
Instance Method Summary collapse
- #call(env) ⇒ Object
- 
  
    
      #initialize(sprockets, prefix = '/')  ⇒ SourceMapServer 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of SourceMapServer. 
- #inspect ⇒ Object
- #not_found(*messages) ⇒ Object
- #register ⇒ Object
Constructor Details
#initialize(sprockets, prefix = '/') ⇒ SourceMapServer
Returns a new instance of SourceMapServer
| 16 17 18 19 | # File 'opal/lib/opal/sprockets/server.rb', line 16 def initialize sprockets, prefix = '/' @sprockets = sprockets @prefix = prefix end | 
Instance Attribute Details
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix
| 21 22 23 | # File 'opal/lib/opal/sprockets/server.rb', line 21 def prefix @prefix end | 
#sprockets ⇒ Object (readonly)
Returns the value of attribute sprockets
| 21 22 23 | # File 'opal/lib/opal/sprockets/server.rb', line 21 def sprockets @sprockets end | 
Instance Method Details
#call(env) ⇒ Object
| 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | # File 'opal/lib/opal/sprockets/server.rb', line 27 def call(env) prefix_regex = %r{^(?:#{prefix}/|/)} path_info = env['PATH_INFO'].to_s.sub(prefix_regex, '') case path_info when %r{^(.*)\.map$} path = $1 asset = sprockets[path] return not_found(path) if asset.nil? # "logical_name" of a BundledAsset keeps the .js extension source = register[asset.logical_path.sub(/\.js$/, '')] return not_found(asset) if source.nil? map = JSON.parse(source) map['sources'] = map['sources'].map {|s| "#{prefix}/#{s}"} source = map.to_json return not_found(asset) if source.nil? return [200, {"Content-Type" => "text/json"}, [source.to_s]] when %r{^(.*)\.rb$} source = File.read(sprockets.resolve(path_info)) return not_found(path_info) if source.nil? return [200, {"Content-Type" => "text/ruby"}, [source]] else not_found(path_info) end end | 
#inspect ⇒ Object
| 23 24 25 | # File 'opal/lib/opal/sprockets/server.rb', line 23 def inspect "#<#{self.class}:#{object_id}>" end | 
#not_found(*messages) ⇒ Object
| 56 57 58 | # File 'opal/lib/opal/sprockets/server.rb', line 56 def not_found(*) not_found = [404, {}, [{not_found: , keys: register.keys}.inspect]] end | 
#register ⇒ Object
| 60 61 62 | # File 'opal/lib/opal/sprockets/server.rb', line 60 def register Opal::Processor.source_map_register end |