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)


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

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



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

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



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

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



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

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



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

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