Parent

Merb::Assets::UniqueAssetPath

Helper for creating unique paths to a file name Can increase speed for browsers that are limited to a certain number of connections per host for downloading static files (css, js, images...)

Public Class Methods

build(filename) click to toggle source

Builds the path to the file based on the name

Parameters

filename

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"
    # File lib/merb-assets/assets.rb, line 79
79:         def build(filename)
80:           config = Merb::Plugins.config[:asset_helpers]
81:           #%{#{(USE_SSL ? 'https' : 'http')}://#{sprintf(config[:asset_domain],self.calculate_host_id(file))}.#{config[:domain]}/#{filename}}
82:           path = config[:use_ssl] ? 'https://' : 'http://'
83:           path << sprintf(config[:asset_domain],self.calculate_host_id(filename)) << "." if config[:asset_domain]
84:           path << config[:domain]
85:           path << "/" if filename.index('/') != 0
86:           path << filename
87:         end

Protected Class Methods

calculate_host_id(filename) click to toggle source

Calculates the id for the host

    # File lib/merb-assets/assets.rb, line 92
92:         def calculate_host_id(filename)
93:           ascii_total = 0
94:           filename.each_byte {|byte|
95:             ascii_total += byte
96:           }
97:           (ascii_total % Merb::Plugins.config[:asset_helpers][:max_hosts] + 1)
98:         end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.