Class: Sprockets::Rails::HelperAssetResolvers::Environment

Inherits:
Object
  • Object
show all
Defined in:
lib/sprockets/rails/helper.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(view) ⇒ Environment

Returns a new instance of Environment.

Raises:

  • (ArgumentError)


302
303
304
305
306
# File 'lib/sprockets/rails/helper.rb', line 302

def initialize(view)
  raise ArgumentError, 'config.assets.resolve_with includes :environment, but app.assets is nil' unless view.assets_environment
  @env = view.assets_environment
  @precompiled_asset_checker = view.precompiled_asset_checker
end

Instance Method Details

#asset_path(path, digest, allow_non_precompiled = false) ⇒ Object



308
309
310
311
312
313
314
315
316
317
318
319
# File 'lib/sprockets/rails/helper.rb', line 308

def asset_path(path, digest, allow_non_precompiled = false)
  # Digests enabled? Do the work to calculate the full asset path.
  if digest
    digest_path path, allow_non_precompiled

  # Otherwise, ask the Sprockets environment whether the asset exists
  # and check whether it's also precompiled for production deploys.
  elsif asset = find_asset(path)
    raise_unless_precompiled_asset asset.logical_path unless allow_non_precompiled
    path
  end
end

#digest_path(path, allow_non_precompiled = false) ⇒ Object



321
322
323
324
325
326
# File 'lib/sprockets/rails/helper.rb', line 321

def digest_path(path, allow_non_precompiled = false)
  if asset = find_asset(path)
    raise_unless_precompiled_asset asset.logical_path unless allow_non_precompiled
    asset.digest_path
  end
end

#find_debug_asset(path) ⇒ Object



332
333
334
335
336
337
# File 'lib/sprockets/rails/helper.rb', line 332

def find_debug_asset(path)
  if asset = find_asset(path, pipeline: :debug)
    raise_unless_precompiled_asset asset.logical_path.sub('.debug', '')
    asset
  end
end

#integrity(path) ⇒ Object



328
329
330
# File 'lib/sprockets/rails/helper.rb', line 328

def integrity(path)
  find_asset(path).try :integrity
end