Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: opal/opal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: c2ab935081ad
Choose a base ref
...
head repository: opal/opal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 7e843b026a35
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Jun 19, 2014

  1. Copy the full SHA
    22b6d5d View commit details
  2. Copy the full SHA
    7e843b0 View commit details
Showing with 26 additions and 16 deletions.
  1. +1 −1 lib/opal/builder_processors.rb
  2. +25 −15 lib/opal/sprockets/server.rb
2 changes: 1 addition & 1 deletion lib/opal/builder_processors.rb
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ def self.match_regexp
end

def source_map
''
'a map for: '+filename
end

def mark_as_required(filename)
40 changes: 25 additions & 15 deletions lib/opal/sprockets/server.rb
Original file line number Diff line number Diff line change
@@ -10,7 +10,8 @@
module Opal

class SourceMapServer
def initialize sprockets, prefix
def initialize app, sprockets, prefix
@app = app
@sprockets = sprockets
@prefix = prefix
end
@@ -22,16 +23,27 @@ def inspect
end

def call(env)
path_info = env['PATH_INFO']
path = path_info.scan(%r{^#{prefix}/(.*)\.map$}).flatten.first
app_results = @app.call(env)
# return app_results unless app_results.first == 404

if path
asset = sprockets[path]
return [404, {}, []] if asset.nil?
path_info = env['PATH_INFO'].to_s.sub(/^\//, '')

return [200, {"Content-Type" => "text/json"}, [$OPAL_SOURCE_MAPS[asset.pathname].to_s]]
case path_info
when %r{^(.*)\.map$}
path = $1
asset = sprockets[path]
return app_results if asset.nil?
register = Opal::Processor.source_map_register
source = register[asset.pathname].to_s
return [404, {}, register.keys] if source.nil?
return app_results if source.nil?
return [200, {"Content-Type" => "text/json"}, [source]]
when %r{^(.*)\.rb$}
source = File.read(sprockets.resolve(path_info))
return app_results if source.nil?
return [200, {"Content-Type" => "text/text"}, [source]]
else
return [200, {"Content-Type" => "text/text"}, [File.read(sprockets.resolve(path_info))]]
app_results
end
end
end
@@ -84,23 +96,21 @@ def use_gem gem_name

def create_app
server, sprockets, prefix = self, @sprockets, self.prefix

sprockets.logger.level = Logger::DEBUG
@app = Rack::Builder.app do
not_found = lambda { |env| [404, {}, []] }

use Rack::Deflater
use Rack::ShowExceptions
map(prefix) { run sprockets }
map(server.source_maps.prefix) { run server.source_maps } if server.source_map_enabled
map(prefix) do
use SourceMapServer, sprockets, prefix if server.source_map_enabled
run sprockets
end
use Index, server if server.use_index
run Rack::Static.new(not_found, :root => server.public_root, :urls => server.public_urls)
end
end

def source_maps
@source_maps ||= SourceMapServer.new(@sprockets, prefix)
end

def call(env)
@app.call env
end