Sha256: 27b4186110b4c9d763f57c83729402ab4b7d1d935cdcbc163520c89a4edcb61f

Contents?: true

Size: 595 Bytes

Versions: 1

Compression:

Stored size: 595 Bytes

Contents

# frozen_string_literal: true

require 'sprockets'

module Middleware
  # Sprockets Rack middleware.
  #
  class SprocketsChain
    attr_reader :app, :prefix, :sprockets

    def initialize(app, prefix)
      @app = app
      @prefix = prefix
      @sprockets = Sprockets::Environment.new
      yield sprockets if block_given?
    end

    def call(env)
      path_info = env['PATH_INFO']
      if path_info =~ prefix
        env['PATH_INFO'].sub!(prefix, '')
        sprockets.call(env)
      else
        app.call(env)
      end
    ensure
      env['PATH_INFO'] = path_info
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hoboken-0.9.0 lib/hoboken/templates/sprockets_chain.rb