class Revelry::Core::Engine

Public Class Methods

js_initializer(name, asset, dependency) click to toggle source

Configure an asset that depends on application files, e.g. the router which requires the route table to be established before being processed We do this by programmatically adding and initializer that makes the asset depend on the application file

name is the name to use for the initializer
asset is the asset path of the asset to configure
dependency is a callable which returns the application file to depend
  on. It is a callable so that we can defer execution until
  initialization.
# File lib/revelry_core/engine.rb, line 28
def self.js_initializer(name, asset, dependency)
  initializer name, after: "sprockets.environment" do
    if Rails.application.assets.respond_to?(:register_preprocessor)
      Rails.application.assets.register_preprocessor 'application/javascript', :'revelry.dependent_on_routes' do |ctx,data|
        ctx.depend_on(dependency.call) if ctx.logical_path == asset
        data
      end
    end
  end
end