Class: ActionView::AssetPaths

Inherits:
Object
  • Object
show all
Defined in:
actionpack/lib/action_view/asset_paths.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, controller = nil) ⇒ AssetPaths

Returns a new instance of AssetPaths.



9
10
11
12
# File 'actionpack/lib/action_view/asset_paths.rb', line 9

def initialize(config, controller = nil)
  @config = config
  @controller = controller
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config



7
8
9
# File 'actionpack/lib/action_view/asset_paths.rb', line 7

def config
  @config
end

#controllerObject (readonly)

Returns the value of attribute controller



7
8
9
# File 'actionpack/lib/action_view/asset_paths.rb', line 7

def controller
  @controller
end

Instance Method Details

#compute_public_path(source, dir, options = {}) ⇒ 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 :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)



22
23
24
25
26
27
28
29
30
31
# File 'actionpack/lib/action_view/asset_paths.rb', line 22

def compute_public_path(source, dir, options = {})
  source = source.to_s
  return source if is_uri?(source)

  source = rewrite_extension(source, dir, options[:ext]) if options[:ext]
  source = rewrite_asset_path(source, dir, options)
  source = rewrite_relative_url_root(source, relative_url_root)
  source = rewrite_host_and_protocol(source, options[:protocol])
  source
end

#compute_source_path(source, dir, ext) ⇒ Object

Return the filesystem path for the source



34
35
36
37
# File 'actionpack/lib/action_view/asset_paths.rb', line 34

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

Returns:

  • (Boolean)


39
40
41
# File 'actionpack/lib/action_view/asset_paths.rb', line 39

def is_uri?(path)
  path =~ %r{^[-a-z]+://|^cid:|^//}
end