Class: Sprockets::Helpers::RailsHelper::AssetPaths

Inherits:
ActionView::AssetPaths show all
Defined in:
actionpack/lib/sprockets/helpers/rails_helper.rb

Overview

:nodoc:

Defined Under Namespace

Classes: AssetNotPrecompiledError

Instance Attribute Summary collapse

Attributes inherited from ActionView::AssetPaths

#config, #controller

Instance Method Summary collapse

Methods inherited from ActionView::AssetPaths

#compute_public_path, #initialize, #is_uri?

Constructor Details

This class inherits a constructor from ActionView::AssetPaths

Instance Attribute Details

#asset_digestsObject

Returns the value of attribute asset_digests



117
118
119
# File 'actionpack/lib/sprockets/helpers/rails_helper.rb', line 117

def asset_digests
  @asset_digests
end

#asset_environmentObject

Returns the value of attribute asset_environment



117
118
119
# File 'actionpack/lib/sprockets/helpers/rails_helper.rb', line 117

def asset_environment
  @asset_environment
end

#asset_prefixObject

Returns the value of attribute asset_prefix



117
118
119
# File 'actionpack/lib/sprockets/helpers/rails_helper.rb', line 117

def asset_prefix
  @asset_prefix
end

#compile_assetsObject

Returns the value of attribute compile_assets



117
118
119
# File 'actionpack/lib/sprockets/helpers/rails_helper.rb', line 117

def compile_assets
  @compile_assets
end

#digest_assetsObject

Returns the value of attribute digest_assets



117
118
119
# File 'actionpack/lib/sprockets/helpers/rails_helper.rb', line 117

def digest_assets
  @digest_assets
end

Instance Method Details

#asset_for(source, ext) ⇒ Object



126
127
128
129
130
131
132
133
# File 'actionpack/lib/sprockets/helpers/rails_helper.rb', line 126

def asset_for(source, ext)
  source = source.to_s
  return nil if is_uri?(source)
  source = rewrite_extension(source, nil, ext)
  asset_environment[source]
rescue Sprockets::FileOutsidePaths
  nil
end

#compute_source_path(source, ext) ⇒ Object

Return the filesystem path for the source



122
123
124
# File 'actionpack/lib/sprockets/helpers/rails_helper.rb', line 122

def compute_source_path(source, ext)
  asset_for(source, ext)
end

#digest_for(logical_path) ⇒ Object



135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'actionpack/lib/sprockets/helpers/rails_helper.rb', line 135

def digest_for(logical_path)
  if digest_assets && asset_digests && (digest = asset_digests[logical_path])
    return digest
  end

  if compile_assets
    if digest_assets && asset = asset_environment[logical_path]
      return asset.digest_path
    end
    return logical_path
  else
    raise AssetNotPrecompiledError.new("#{logical_path} isn't precompiled")
  end
end

#rewrite_asset_path(source, dir, options = {}) ⇒ Object



150
151
152
153
154
155
156
157
158
159
# File 'actionpack/lib/sprockets/helpers/rails_helper.rb', line 150

def rewrite_asset_path(source, dir, options = {})
  if source[0] == ?/
    source
  else
    source = digest_for(source) unless options[:digest] == false
    source = File.join(dir, source)
    source = "/#{source}" unless source =~ /^\//
    source
  end
end

#rewrite_extension(source, dir, ext) ⇒ Object



161
162
163
164
165
166
167
# File 'actionpack/lib/sprockets/helpers/rails_helper.rb', line 161

def rewrite_extension(source, dir, ext)
  if ext && File.extname(source).empty?
    "#{source}.#{ext}"
  else
    source
  end
end