Module: Sprockets::Rails::Workarea

Defined in:
lib/workarea/ext/sprockets/task.rb

Instance Method Summary collapse

Instance Method Details

#environmentObject

This is required because when precompiling assets in a deployed env like staging or production, Rails.application.assets will be nil because Rails.application.config.assets.compile = false. This means “don’t fall back to the asset pipeline if an asset can’t be found”, which is what we want in those environvments.

When Rails.application.assets == nil, sprockets-rails falls back and uses it’s own Sprockets::Environment. Since there is no Sprockets::Environment for our app to add our plugin asset appends points during initialization, we must monkey patch the ad hoc creation of one for these rake tasks here to get these included. PRETTY SHITTY.



18
19
20
21
22
23
24
25
26
# File 'lib/workarea/ext/sprockets/task.rb', line 18

def environment
  result = super

  result.context_class.instance_eval do
    include ::Workarea::Plugin::AssetAppendsHelper
  end

  result
end