Class: ActionView::AssetPaths
- Inherits:
-
Object
- Object
- ActionView::AssetPaths
- Defined in:
- lib/action_view/asset_paths.rb
Overview
:nodoc:
Direct Known Subclasses
Helpers::AssetTagHelper::AssetPaths, Sprockets::Helpers::RailsHelper::AssetPaths
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#controller ⇒ Object
readonly
Returns the value of attribute controller.
Instance Method Summary collapse
-
#compute_public_path(source, dir, ext = nil, include_host = true, protocol = nil) ⇒ Object
Add the extension
extif not present. -
#compute_source_path(source, dir, ext) ⇒ Object
Return the filesystem path for the source.
-
#initialize(config, controller = nil) ⇒ AssetPaths
constructor
A new instance of AssetPaths.
- #is_uri?(path) ⇒ Boolean
Constructor Details
#initialize(config, controller = nil) ⇒ AssetPaths
Returns a new instance of AssetPaths.
9 10 11 12 |
# File 'lib/action_view/asset_paths.rb', line 9 def initialize(config, controller = nil) @config = config @controller = controller end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
7 8 9 |
# File 'lib/action_view/asset_paths.rb', line 7 def config @config end |
#controller ⇒ Object (readonly)
Returns the value of attribute controller.
7 8 9 |
# File 'lib/action_view/asset_paths.rb', line 7 def controller @controller end |
Instance Method Details
#compute_public_path(source, dir, ext = nil, include_host = true, protocol = nil) ⇒ Object
Add the extension ext if not present. Return full or scheme-relative URLs otherwise untouched.
Prefix with /dir/ if lacking a leading /. Account for relative URL
roots. Rewrite the asset path for cache-busting asset ids. Include
asset host, if configured, with the correct request protocol.
When include_host is true and the asset host does not specify the protocol the protocol parameter specifies how the protocol will be added. When :relative (default), the protocol will be determined by the client using current protocol When :request, the protocol will be the request protocol Otherwise, the protocol is used (E.g. :http, :https, etc)
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/action_view/asset_paths.rb', line 24 def compute_public_path(source, dir, ext = nil, include_host = true, protocol = nil) source = source.to_s return source if is_uri?(source) source = rewrite_extension(source, dir, ext) if ext source = rewrite_asset_path(source, dir) source = rewrite_relative_url_root(source, relative_url_root) if has_request? source = rewrite_host_and_protocol(source, protocol) if include_host source end |
#compute_source_path(source, dir, ext) ⇒ Object
Return the filesystem path for the source
36 37 38 39 |
# File 'lib/action_view/asset_paths.rb', line 36 def compute_source_path(source, dir, ext) source = rewrite_extension(source, dir, ext) if ext File.join(config.assets_dir, dir, source) end |
#is_uri?(path) ⇒ Boolean
41 42 43 |
# File 'lib/action_view/asset_paths.rb', line 41 def is_uri?(path) path =~ %r{^[-a-z]+://|^cid:|^//} end |