Class: Sprockets::Helpers::RailsHelper::AssetPaths
- Inherits:
-
ActionView::AssetPaths
- Object
- ActionView::AssetPaths
- Sprockets::Helpers::RailsHelper::AssetPaths
- Defined in:
- lib/sprockets/helpers/rails_helper.rb
Overview
:nodoc:
Defined Under Namespace
Classes: AssetNotPrecompiledError
Instance Attribute Summary collapse
-
#asset_digests ⇒ Object
Returns the value of attribute asset_digests.
-
#asset_environment ⇒ Object
Returns the value of attribute asset_environment.
-
#asset_prefix ⇒ Object
Returns the value of attribute asset_prefix.
-
#compile_assets ⇒ Object
Returns the value of attribute compile_assets.
-
#digest_assets ⇒ Object
Returns the value of attribute digest_assets.
Attributes inherited from ActionView::AssetPaths
Instance Method Summary collapse
- #asset_for(source, ext) ⇒ Object
- #digest_for(logical_path) ⇒ Object
- #exact_match_present?(source) ⇒ Boolean
- #rewrite_asset_path(source, dir, options = {}) ⇒ Object
- #rewrite_extension(source, dir, ext) ⇒ Object
Methods inherited from ActionView::AssetPaths
#compute_public_path, #compute_source_path, #initialize, #is_uri?
Constructor Details
This class inherits a constructor from ActionView::AssetPaths
Instance Attribute Details
#asset_digests ⇒ Object
Returns the value of attribute asset_digests.
118 119 120 |
# File 'lib/sprockets/helpers/rails_helper.rb', line 118 def asset_digests @asset_digests end |
#asset_environment ⇒ Object
Returns the value of attribute asset_environment.
118 119 120 |
# File 'lib/sprockets/helpers/rails_helper.rb', line 118 def asset_environment @asset_environment end |
#asset_prefix ⇒ Object
Returns the value of attribute asset_prefix.
118 119 120 |
# File 'lib/sprockets/helpers/rails_helper.rb', line 118 def asset_prefix @asset_prefix end |
#compile_assets ⇒ Object
Returns the value of attribute compile_assets.
118 119 120 |
# File 'lib/sprockets/helpers/rails_helper.rb', line 118 def compile_assets @compile_assets end |
#digest_assets ⇒ Object
Returns the value of attribute digest_assets.
118 119 120 |
# File 'lib/sprockets/helpers/rails_helper.rb', line 118 def digest_assets @digest_assets end |
Instance Method Details
#asset_for(source, ext) ⇒ Object
122 123 124 125 126 127 128 129 |
# File 'lib/sprockets/helpers/rails_helper.rb', line 122 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 |
#digest_for(logical_path) ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/sprockets/helpers/rails_helper.rb', line 131 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 |
#exact_match_present?(source) ⇒ Boolean
173 174 175 176 177 178 |
# File 'lib/sprockets/helpers/rails_helper.rb', line 173 def exact_match_present?(source) pathname = asset_environment.resolve(source) pathname.to_s =~ /#{Regexp.escape(source)}\Z/ rescue Sprockets::FileNotFound false end |
#rewrite_asset_path(source, dir, options = {}) ⇒ Object
146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/sprockets/helpers/rails_helper.rb', line 146 def rewrite_asset_path(source, dir, = {}) if source[0] == ?/ source else if digest_assets && [:digest] != false source = digest_for(source) end source = File.join(dir, source) source = "/#{source}" unless source =~ /^\// source end end |
#rewrite_extension(source, dir, ext) ⇒ Object
159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/sprockets/helpers/rails_helper.rb', line 159 def rewrite_extension(source, dir, ext) source_ext = File.extname(source)[1..-1] if !ext || ext == source_ext source elsif source_ext.blank? "#{source}.#{ext}" elsif File.exists?(source) || exact_match_present?(source) source else "#{source}.#{ext}" end end |