Methods

Merb::Assets::AssetHelpers

Helpers for handling asset files.

Constants

ASSET_FILE_EXTENSIONS

Public Instance Methods

asset_path(asset_type, filename, local_path = false) click to toggle source

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.

Parameters

asset_type

Type of the asset (e.g. :javascript).

filename<~to_s>

The path to the file.

local_path

If true, the returned path will be relative to the Merb.root, otherwise it will be the public URI path. Defaults to false.

Returns

String

The path to the asset.

Examples

  asset_path(:javascript, :dingo)
  # => "/javascripts/dingo.js"

  asset_path(:javascript, :dingo, true)
  # => "public/javascripts/dingo.js"
    # File lib/merb-assets/assets.rb, line 42
42:       def asset_path(asset_type, filename, local_path = false)
43:         filename = filename.to_s
44:         return filename if filename =~ %{^https?://} #leave absolte paths alone
45: 
46:         # add extension if none given
47:         if filename !~ /#{'\\' + ASSET_FILE_EXTENSIONS[asset_type]}\Z/ && filename.index('?').nil?
48:           filename = "#{filename}#{ASSET_FILE_EXTENSIONS[asset_type]}" # don't modify receiver
49:         end
50: 
51:         # prepend asset type's folder path
52:         filename = "/#{asset_type}s/#{filename}" unless filename.index("/") == 0
53: 
54:         if local_path
55:           return "public#{filename}"
56:         else
57:           return "#{Merb::Config[:path_prefix]}#{filename}"
58:         end
59:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.