Helpers for handling asset files.
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 lib/merb-assets/assets.rb, line 42 def asset_path(asset_type, filename, local_path = false) filename = filename.to_s return filename if filename =~ %{^https?://} #leave absolte paths alone # add extension if none given if filename !~ /#{'\\' + ASSET_FILE_EXTENSIONS[asset_type]}\Z/ && filename.index('?').nil? filename = "#{filename}#{ASSET_FILE_EXTENSIONS[asset_type]}" # don't modify receiver end # prepend asset type's folder path filename = "/#{asset_type}s/#{filename}" unless filename.index("/") == 0 if local_path return "public#{filename}" else return "#{Merb::Config[:path_prefix]}#{filename}" end end
Generated with the Darkfish Rdoc Generator 2.