Module | Merb::Assets::AssetHelpers |
In: |
merb-assets/lib/merb-assets/assets.rb
|
Helpers for handling asset files.
ASSET_FILE_EXTENSIONS | = | { :javascript => ".js", :stylesheet => ".css" |
Returns the URI path to a particular asset file. If local_path is true, returns the path relative to the Merb.root, not the public directory. Uses the path_prefix, if any is configured.
asset_type<Symbol>: | Type of the asset (e.g. :javascript). |
filename<~to_s>: | The path to the file. |
local_path<Boolean>: | If true, the returned path will be relative to the Merb.root, otherwise it will be the public URI path. Defaults to false. |
String: | The path to the asset. |
asset_path(:javascript, :dingo) # => "/javascripts/dingo.js" asset_path(:javascript, :dingo, true) # => "public/javascripts/dingo.js"
# File merb-assets/lib/merb-assets/assets.rb, line 42 42: def asset_path(asset_type, filename, local_path = false) 43: filename = filename.to_s 44: if filename !~ /#{'\\' + ASSET_FILE_EXTENSIONS[asset_type]}\Z/ && filename.index('?').nil? 45: filename = "#{filename}#{ASSET_FILE_EXTENSIONS[asset_type]}" # don't modify receiver 46: end 47: if filename !~ %r{^(/|https?://)} 48: filename = "/#{asset_type}s/#{filename}" 49: end 50: if local_path 51: return "public#{filename}" 52: else 53: return "#{Merb::Config[:path_prefix]}#{filename}" 54: end 55: end