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)


315
316
317
318
319
320
# File 'lib/sprockets/rails/helper.rb', line 315

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
  @check_precompiled_asset = view.check_precompiled_asset
end

Instance Method Details

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



322
323
324
325
326
327
328
329
330
331
332
333
# File 'lib/sprockets/rails/helper.rb', line 322

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



335
336
337
338
339
340
# File 'lib/sprockets/rails/helper.rb', line 335

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



346
347
348
349
350
351
# File 'lib/sprockets/rails/helper.rb', line 346

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



342
343
344
# File 'lib/sprockets/rails/helper.rb', line 342

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