require 'sprockets/version'

class JsRoutes
  SPROCKETS3 = Gem::Version.new(Sprockets::VERSION) >= Gem::Version.new('3.0.0')
  class Engine < ::Rails::Engine

    if SPROCKETS3
      initializer 'js-routes.dependent_on_routes', after: :engines_blank_point, before: :finisher_hook do
        Rails.application.config.assets.configure do |config|
          routes = Rails.root.join('config', 'routes.rb').to_s
          config.register_preprocessor 'application/javascript', :'js-routes_dependent_on_routes' do |ctx,data|
            ctx.depend_on(routes) if ctx.logical_path == 'js-routes'
            data
          end
        end
      end
    else
      initializer 'js-routes.dependent_on_routes', after: "sprockets.environment" do

        if Rails.application.assets.respond_to?(:register_preprocessor)
          routes = Rails.root.join('config', 'routes.rb').to_s
          Rails.application.assets.register_preprocessor 'application/javascript', :'js-routes_dependent_on_routes' do |ctx,data|
            ctx.depend_on(routes) if ctx.logical_path == 'js-routes'
            data
          end
        end
      end
    end
  end
end

class JsRoutesSprocketsExtension
  def initialize(filename, &block)
    @filename = filename
    @source   = block.call
  end

  def render(context, empty_hash_wtf)
    self.class.run(@filename, @source, context)
  end

  def self.run(filename, source, context)
    routes = Rails.root.join('config', 'routes.rb').to_s
    context.depend_on(routes) if context.logical_path == 'js-routes'
    source
  end

  def self.call(input)
    filename = input[:filename]
    source   = input[:data]
    context  = input[:environment].context_class.new(input)

    result = run(filename, source, context)
    { data: result }
  end
end

class Engine < ::Rails::Engine
  initializer 'js-routes.dependent_on_routes', after: :engines_blank_point, before: :finisher_hook do
    Rails.application.config.assets.register_preprocessor 'application/javascript', JsRoutesSprocketsExtension
  end
end
Update Sprockets extension to work with Sprockets 2, 3, 4
Update Sprockets extension to work with Sprockets 2, 3, 4

Sprockets 3.x display deprecation warning: You are using the a deprecated processor interface #<Proc:0x007f9002044f90@/.../gems/ruby-2.3.1/gems/js-routes-1.2.7/lib/js_routes/engine.rb:11>.
Please update your processor interface:
https://github.com/rails/sprockets/blob/master/guides/extending_sprockets.md#supporting-all-versions-of-sprockets-in-processors

I've followed the guide and updated the engine to support all versions of sprockets.
