Class: Sprockets::Helpers::AssetPath

Inherits:
BasePath
  • Object
show all
Defined in:
lib/sprockets/helpers/asset_path.rb

Overview

‘AssetPath` generates a full path for an asset that exists in Sprockets environment.

Direct Known Subclasses

ManifestPath

Instance Attribute Summary

Attributes inherited from BasePath

#options, #uri

Instance Method Summary collapse

Methods inherited from BasePath

#sprockets_helpers_settings, #to_s

Constructor Details

#initialize(uri, asset, environment, options = {}) ⇒ AssetPath

Returns a new instance of AssetPath.



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/sprockets/helpers/asset_path.rb', line 6

def initialize(uri, asset, environment, options = {})
  @uri = uri
  @asset = asset
  @environment = environment
  @options = options
  @options = {
    :body => false,
    :digest => sprockets_helpers_settings.digest,
    :prefix => sprockets_helpers_settings.prefix
  }.merge options

  @uri.path = @options[:digest] ? asset.digest_path : asset.logical_path
end

Instance Method Details

#to_aObject



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/sprockets/helpers/asset_path.rb', line 20

def to_a
  if @asset.respond_to?(:to_a)
    @asset.to_a.map do |dependency|
      AssetPath.new(@uri.clone, dependency, @environment, @options.merge(:body => true)).to_s
    end
  elsif @asset.[:included]
    @asset.[:included].map do |uri|
      AssetPath.new(@uri.clone, @environment.load(uri), @environment, @options.merge(:body => true)).to_s
    end
  else
    AssetPath.new(@uri.clone, @asset, @environment, @options.merge(:body => true)).to_s
  end
end