Module: Ext::JsHelpers::Helpers

Defined in:
lib/ext/js_helpers.rb

Instance Method Summary collapse

Instance Method Details

#joined_js(*scripts) ⇒ Object

Returns a link to the JoinJavascripts controller with the desired scripts. If no script is passed, it will use the UseHelper specified javascripts.

This is useful to avoid IE bugs. IE does not guarantee the javascript loading order. That way, you are sure they’re always as you want ;-)

raises ArgumentError if the produced url is longer than 512 chars.

Example

joined_js('prototype.js', 'event-selector.js')
#=> "/join_js/prototype-and-event-selector.js"

Usage in the Views

def layout
  html do
    head do
      script :type=>'text/css', :src=>joined_js
    end
    body { yield }
  end
end

def index
  use 'prototype.js', 'event-selector.js', 'my-script.js'
end

Raises:

  • (ArgumentError)


42
43
44
45
46
47
48
# File 'lib/ext/js_helpers.rb', line 42

def joined_js(*scripts)
  scripts = javascripts if scripts.empty?
  script_name = scripts.map{|js| File.basename(js, '.js')}.join('-and-')
  url = R(app::Controllers::JoinJavascripts, script_name)
  raise ArgumentError, "Script name '#{script_name}' is too long" unless url.to_s.size < 512
  url
end