Class: Merb::Assets::UniqueAssetPath
- Inherits:
-
Object
- Object
- Merb::Assets::UniqueAssetPath
- Defined in:
- lib/merb-assets/assets.rb
Overview
Helper for creating unique paths to a file name Can increase speend for browsers that are limited to a certain number of connections per host for downloading static files (css, js, images…)
Class Method Summary collapse
-
.build(filename) ⇒ Object
Builds the path to the file based on the name.
Class Method Details
.build(filename) ⇒ Object
Builds the path to the file based on the name
Parameters
- filename<String>
-
Name of file to generate path for
Returns
- String
-
The path to the asset.
Examples
build("/javascripts/my_fancy_script.js")
# => "https://assets5.my-awesome-domain.com/javascripts/my_fancy_script.js"
75 76 77 78 79 80 81 82 |
# File 'lib/merb-assets/assets.rb', line 75 def build(filename) config = Merb::Plugins.config[:asset_helpers] #%{#{(USE_SSL ? 'https' : 'http')}://#{sprintf(config[:asset_domain],self.calculate_host_id(file))}.#{config[:domain]}/#{filename}} path = config[:use_ssl] ? 'https://' : 'http://' path << sprintf(config[:asset_domain],self.calculate_host_id(filename)) << ".#{config[:domain]}" path << "/" if filename.index('/') != 0 path << filename end |