Method: Padrino::Helpers::AssetTagHelpers#asset_path

Defined in:
padrino-helpers/lib/padrino-helpers/asset_tag_helpers.rb

#asset_path(kind, source = nil) ⇒ String

Returns the path to the specified asset (css or javascript).

Examples:

# Generates: /javascripts/application.js?1269008689
asset_path :js, :application

# Generates: /stylesheets/application.css?1269008689
asset_path :css, :application

# Generates: /images/example.jpg?1269008689
asset_path :images, 'example.jpg'

# Generates: /uploads/file.ext?1269008689
asset_path 'uploads/file.ext'

Parameters:

  • kind (String)

    The kind of asset (i.e :images, :js, :css).

  • source (String) (defaults to: nil)

    The path to the asset (relative or absolute).

Returns:

  • (String)

    Path for the asset given the kind and source.

[View source] [View on GitHub]

316
317
318
319
320
321
322
323
324
# File 'padrino-helpers/lib/padrino-helpers/asset_tag_helpers.rb', line 316

def asset_path(kind, source = nil)
  kind, source = source, kind if source.nil?
  source = asset_normalize_extension(kind, escape_link(source.to_s))
  return source if source =~ ABSOLUTE_URL_PATTERN || source =~ /^\//
  source = File.join(asset_folder_name(kind), source)
  timestamp = asset_timestamp(source)
  result_path = uri_root_path(source)
  "#{result_path}#{timestamp}"
end