diff options
Diffstat (limited to 'actionpack/lib/action_view/helpers')
12 files changed, 75 insertions, 77 deletions
diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb index 2f8b28c82b..d4d09e2ee9 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb @@ -15,7 +15,7 @@ module ActionView # image_tag("rails.png") # # => <img alt="Rails" src="/images/rails.png?1230601161" /> # stylesheet_link_tag("application") - # # => <link href="/stylesheets/application.css?1232285206" media="screen" rel="stylesheet" type="text/css" /> + # # => <link href="/stylesheets/application.css?1232285206" media="screen" rel="stylesheet" /> # # === Using asset hosts # @@ -34,7 +34,7 @@ module ActionView # image_tag("rails.png") # # => <img alt="Rails" src="http://assets.example.com/images/rails.png?1230601161" /> # stylesheet_link_tag("application") - # # => <link href="http://assets.example.com/stylesheets/application.css?1232285206" media="screen" rel="stylesheet" type="text/css" /> + # # => <link href="http://assets.example.com/stylesheets/application.css?1232285206" media="screen" rel="stylesheet" /> # # Browsers typically open at most two simultaneous connections to a single # host, which means your assets often have to wait for other assets to finish @@ -47,7 +47,7 @@ module ActionView # image_tag("rails.png") # # => <img alt="Rails" src="http://assets0.example.com/images/rails.png?1230601161" /> # stylesheet_link_tag("application") - # # => <link href="http://assets2.example.com/stylesheets/application.css?1232285206" media="screen" rel="stylesheet" type="text/css" /> + # # => <link href="http://assets2.example.com/stylesheets/application.css?1232285206" media="screen" rel="stylesheet" /> # # To do this, you can either setup four actual hosts, or you can use wildcard # DNS to CNAME the wildcard to a single asset host. You can read more about @@ -66,7 +66,7 @@ module ActionView # image_tag("rails.png") # # => <img alt="Rails" src="http://assets1.example.com/images/rails.png?1230601161" /> # stylesheet_link_tag("application") - # # => <link href="http://assets2.example.com/stylesheets/application.css?1232285206" media="screen" rel="stylesheet" type="text/css" /> + # # => <link href="http://assets2.example.com/stylesheets/application.css?1232285206" media="screen" rel="stylesheet" /> # # The example above generates "http://assets1.example.com" and # "http://assets2.example.com". This option is useful for example if @@ -86,7 +86,7 @@ module ActionView # image_tag("rails.png") # # => <img alt="Rails" src="http://images.example.com/images/rails.png?1230601161" /> # stylesheet_link_tag("application") - # # => <link href="http://assets.example.com/stylesheets/application.css?1232285206" media="screen" rel="stylesheet" type="text/css" /> + # # => <link href="http://assets.example.com/stylesheets/application.css?1232285206" media="screen" rel="stylesheet" /> # # Alternatively you may ask for a second parameter +request+. That one is # particularly useful for serving assets from an SSL-protected page. The @@ -163,7 +163,7 @@ module ActionView # image_tag("rails.png") # # => <img alt="Rails" src="/release-12345/images/rails.png" /> # stylesheet_link_tag("application") - # # => <link href="/release-12345/stylesheets/application.css?1232285206" media="screen" rel="stylesheet" type="text/css" /> + # # => <link href="/release-12345/stylesheets/application.css?1232285206" media="screen" rel="stylesheet" /> # # Changing the asset_path does require that your web servers have # knowledge of the asset template paths that you rewrite to so it's not diff --git a/actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb b/actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb index c67f81dcf4..e3329c0345 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb @@ -16,7 +16,7 @@ module ActionView end def asset_tag(source, options) - content_tag("script", "", { "type" => Mime::JS, "src" => path_to_asset(source) }.merge(options)) + content_tag("script", "", { "src" => path_to_asset(source) }.merge(options)) end def custom_dir @@ -60,9 +60,9 @@ module ActionView # ActionView::Helpers::AssetTagHelper.register_javascript_expansion :monkey => ["head", "body", "tail"] # # javascript_include_tag :monkey # => - # <script type="text/javascript" src="/javascripts/head.js"></script> - # <script type="text/javascript" src="/javascripts/body.js"></script> - # <script type="text/javascript" src="/javascripts/tail.js"></script> + # <script src="/javascripts/head.js"></script> + # <script src="/javascripts/body.js"></script> + # <script src="/javascripts/tail.js"></script> def register_javascript_expansion(expansions) js_expansions = JavascriptIncludeTag.expansions expansions.each do |key, values| @@ -116,36 +116,36 @@ module ActionView # # ==== Examples # javascript_include_tag "xmlhr" - # # => <script type="text/javascript" src="/javascripts/xmlhr.js?1284139606"></script> + # # => <script src="/javascripts/xmlhr.js?1284139606"></script> # # javascript_include_tag "xmlhr.js" - # # => <script type="text/javascript" src="/javascripts/xmlhr.js?1284139606"></script> + # # => <script src="/javascripts/xmlhr.js?1284139606"></script> # # javascript_include_tag "common.javascript", "/elsewhere/cools" - # # => <script type="text/javascript" src="/javascripts/common.javascript?1284139606"></script> - # # <script type="text/javascript" src="/elsewhere/cools.js?1423139606"></script> + # # => <script src="/javascripts/common.javascript?1284139606"></script> + # # <script src="/elsewhere/cools.js?1423139606"></script> # # javascript_include_tag "http://www.example.com/xmlhr" - # # => <script type="text/javascript" src="http://www.example.com/xmlhr"></script> + # # => <script src="http://www.example.com/xmlhr"></script> # # javascript_include_tag "http://www.example.com/xmlhr.js" - # # => <script type="text/javascript" src="http://www.example.com/xmlhr.js"></script> + # # => <script src="http://www.example.com/xmlhr.js"></script> # # javascript_include_tag :defaults - # # => <script type="text/javascript" src="/javascripts/jquery.js?1284139606"></script> - # # <script type="text/javascript" src="/javascripts/rails.js?1284139606"></script> - # # <script type="text/javascript" src="/javascripts/application.js?1284139606"></script> + # # => <script src="/javascripts/jquery.js?1284139606"></script> + # # <script src="/javascripts/rails.js?1284139606"></script> + # # <script src="/javascripts/application.js?1284139606"></script> # # * = The application.js file is only referenced if it exists # # You can also include all JavaScripts in the +javascripts+ directory using <tt>:all</tt> as the source: # # javascript_include_tag :all - # # => <script type="text/javascript" src="/javascripts/jquery.js?1284139606"></script> - # # <script type="text/javascript" src="/javascripts/rails.js?1284139606"></script> - # # <script type="text/javascript" src="/javascripts/application.js?1284139606"></script> - # # <script type="text/javascript" src="/javascripts/shop.js?1284139606"></script> - # # <script type="text/javascript" src="/javascripts/checkout.js?1284139606"></script> + # # => <script src="/javascripts/jquery.js?1284139606"></script> + # # <script src="/javascripts/rails.js?1284139606"></script> + # # <script src="/javascripts/application.js?1284139606"></script> + # # <script src="/javascripts/shop.js?1284139606"></script> + # # <script src="/javascripts/checkout.js?1284139606"></script> # # Note that your defaults of choice will be included first, so they will be available to all subsequently # included files. @@ -166,25 +166,25 @@ module ActionView # # # assuming config.perform_caching is false # javascript_include_tag :all, :cache => true - # # => <script type="text/javascript" src="/javascripts/jquery.js?1284139606"></script> - # # <script type="text/javascript" src="/javascripts/rails.js?1284139606"></script> - # # <script type="text/javascript" src="/javascripts/application.js?1284139606"></script> - # # <script type="text/javascript" src="/javascripts/shop.js?1284139606"></script> - # # <script type="text/javascript" src="/javascripts/checkout.js?1284139606"></script> + # # => <script src="/javascripts/jquery.js?1284139606"></script> + # # <script src="/javascripts/rails.js?1284139606"></script> + # # <script src="/javascripts/application.js?1284139606"></script> + # # <script src="/javascripts/shop.js?1284139606"></script> + # # <script src="/javascripts/checkout.js?1284139606"></script> # # # assuming config.perform_caching is true # javascript_include_tag :all, :cache => true - # # => <script type="text/javascript" src="/javascripts/all.js?1344139789"></script> + # # => <script src="/javascripts/all.js?1344139789"></script> # # # assuming config.perform_caching is false # javascript_include_tag "jquery", "cart", "checkout", :cache => "shop" - # # => <script type="text/javascript" src="/javascripts/jquery.js?1284139606"></script> - # # <script type="text/javascript" src="/javascripts/cart.js?1289139157"></script> - # # <script type="text/javascript" src="/javascripts/checkout.js?1299139816"></script> + # # => <script src="/javascripts/jquery.js?1284139606"></script> + # # <script src="/javascripts/cart.js?1289139157"></script> + # # <script src="/javascripts/checkout.js?1299139816"></script> # # # assuming config.perform_caching is true # javascript_include_tag "jquery", "cart", "checkout", :cache => "shop" - # # => <script type="text/javascript" src="/javascripts/shop.js?1299139816"></script> + # # => <script src="/javascripts/shop.js?1299139816"></script> # # The <tt>:recursive</tt> option is also available for caching: # diff --git a/actionpack/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb b/actionpack/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb index 2584b67548..60d4af178a 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb @@ -17,7 +17,7 @@ module ActionView def asset_tag(source, options) # We force the :request protocol here to avoid a double-download bug in IE7 and IE8 - tag("link", { "rel" => "stylesheet", "type" => Mime::CSS, "media" => "screen", "href" => path_to_asset(source, :protocol => :request) }.merge(options)) + tag("link", { "rel" => "stylesheet", "media" => "screen", "href" => path_to_asset(source, :protocol => :request) }.merge(options)) end def custom_dir @@ -38,9 +38,9 @@ module ActionView # ActionView::Helpers::AssetTagHelper.register_stylesheet_expansion :monkey => ["head", "body", "tail"] # # stylesheet_link_tag :monkey # => - # <link href="/stylesheets/head.css" media="screen" rel="stylesheet" type="text/css" /> - # <link href="/stylesheets/body.css" media="screen" rel="stylesheet" type="text/css" /> - # <link href="/stylesheets/tail.css" media="screen" rel="stylesheet" type="text/css" /> + # <link href="/stylesheets/head.css" media="screen" rel="stylesheet" /> + # <link href="/stylesheets/body.css" media="screen" rel="stylesheet" /> + # <link href="/stylesheets/tail.css" media="screen" rel="stylesheet" /> def register_stylesheet_expansion(expansions) style_expansions = StylesheetIncludeTag.expansions expansions.each do |key, values| @@ -81,30 +81,30 @@ module ActionView # # ==== Examples # stylesheet_link_tag "style" # => - # <link href="/stylesheets/style.css" media="screen" rel="stylesheet" type="text/css" /> + # <link href="/stylesheets/style.css" media="screen" rel="stylesheet" /> # # stylesheet_link_tag "style.css" # => - # <link href="/stylesheets/style.css" media="screen" rel="stylesheet" type="text/css" /> + # <link href="/stylesheets/style.css" media="screen" rel="stylesheet" /> # # stylesheet_link_tag "http://www.example.com/style.css" # => - # <link href="http://www.example.com/style.css" media="screen" rel="stylesheet" type="text/css" /> + # <link href="http://www.example.com/style.css" media="screen" rel="stylesheet" /> # # stylesheet_link_tag "style", :media => "all" # => - # <link href="/stylesheets/style.css" media="all" rel="stylesheet" type="text/css" /> + # <link href="/stylesheets/style.css" media="all" rel="stylesheet" /> # # stylesheet_link_tag "style", :media => "print" # => - # <link href="/stylesheets/style.css" media="print" rel="stylesheet" type="text/css" /> + # <link href="/stylesheets/style.css" media="print" rel="stylesheet" /> # # stylesheet_link_tag "random.styles", "/css/stylish" # => - # <link href="/stylesheets/random.styles" media="screen" rel="stylesheet" type="text/css" /> - # <link href="/css/stylish.css" media="screen" rel="stylesheet" type="text/css" /> + # <link href="/stylesheets/random.styles" media="screen" rel="stylesheet" /> + # <link href="/css/stylish.css" media="screen" rel="stylesheet" /> # # You can also include all styles in the stylesheets directory using <tt>:all</tt> as the source: # # stylesheet_link_tag :all # => - # <link href="/stylesheets/style1.css" media="screen" rel="stylesheet" type="text/css" /> - # <link href="/stylesheets/styleB.css" media="screen" rel="stylesheet" type="text/css" /> - # <link href="/stylesheets/styleX2.css" media="screen" rel="stylesheet" type="text/css" /> + # <link href="/stylesheets/style1.css" media="screen" rel="stylesheet" /> + # <link href="/stylesheets/styleB.css" media="screen" rel="stylesheet" /> + # <link href="/stylesheets/styleX2.css" media="screen" rel="stylesheet" /> # # If you want Rails to search in all the subdirectories under stylesheets, you should explicitly set <tt>:recursive</tt>: # @@ -119,20 +119,20 @@ module ActionView # # ==== Examples # stylesheet_link_tag :all, :cache => true # when config.perform_caching is false => - # <link href="/stylesheets/style1.css" media="screen" rel="stylesheet" type="text/css" /> - # <link href="/stylesheets/styleB.css" media="screen" rel="stylesheet" type="text/css" /> - # <link href="/stylesheets/styleX2.css" media="screen" rel="stylesheet" type="text/css" /> + # <link href="/stylesheets/style1.css" media="screen" rel="stylesheet" /> + # <link href="/stylesheets/styleB.css" media="screen" rel="stylesheet" /> + # <link href="/stylesheets/styleX2.css" media="screen" rel="stylesheet" /> # # stylesheet_link_tag :all, :cache => true # when config.perform_caching is true => - # <link href="/stylesheets/all.css" media="screen" rel="stylesheet" type="text/css" /> + # <link href="/stylesheets/all.css" media="screen" rel="stylesheet" /> # # stylesheet_link_tag "shop", "cart", "checkout", :cache => "payment" # when config.perform_caching is false => - # <link href="/stylesheets/shop.css" media="screen" rel="stylesheet" type="text/css" /> - # <link href="/stylesheets/cart.css" media="screen" rel="stylesheet" type="text/css" /> - # <link href="/stylesheets/checkout.css" media="screen" rel="stylesheet" type="text/css" /> + # <link href="/stylesheets/shop.css" media="screen" rel="stylesheet" /> + # <link href="/stylesheets/cart.css" media="screen" rel="stylesheet" /> + # <link href="/stylesheets/checkout.css" media="screen" rel="stylesheet" /> # # stylesheet_link_tag "shop", "cart", "checkout", :cache => "payment" # when config.perform_caching is true => - # <link href="/stylesheets/payment.css" media="screen" rel="stylesheet" type="text/css" /> + # <link href="/stylesheets/payment.css" media="screen" rel="stylesheet" /> # # The <tt>:recursive</tt> option is also available for caching: # diff --git a/actionpack/lib/action_view/helpers/atom_feed_helper.rb b/actionpack/lib/action_view/helpers/atom_feed_helper.rb index 70164217de..f9aa8d7cee 100644 --- a/actionpack/lib/action_view/helpers/atom_feed_helper.rb +++ b/actionpack/lib/action_view/helpers/atom_feed_helper.rb @@ -189,7 +189,7 @@ module ActionView @xml.updated((options[:updated] || record.updated_at).xmlschema) end - type = options.fetch(:type) { 'text/html' } + type = options.fetch(:type, 'text/html') @xml.link(:rel => 'alternate', :type => type, :href => options[:url] || @view.polymorphic_url(record)) diff --git a/actionpack/lib/action_view/helpers/capture_helper.rb b/actionpack/lib/action_view/helpers/capture_helper.rb index 278139cadb..d9d6f90211 100644 --- a/actionpack/lib/action_view/helpers/capture_helper.rb +++ b/actionpack/lib/action_view/helpers/capture_helper.rb @@ -96,7 +96,7 @@ module ActionView # Please login! # # <% content_for :script do %> - # <script type="text/javascript">alert('You are not authorized to view this page!')</script> + # <script>alert('You are not authorized to view this page!')</script> # <% end %> # # Then, in another view, you could to do something like this: diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb index e403d6cf5e..b5e0970612 100644 --- a/actionpack/lib/action_view/helpers/form_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb @@ -122,11 +122,11 @@ module ActionView html_name = (options[:multiple] == true && !name.to_s.ends_with?("[]")) ? "#{name}[]" : name if options.delete(:include_blank) - option_tags = "<option value=\"\"></option>".html_safe + option_tags + option_tags = content_tag(:option, '', :value => '').safe_concat(option_tags) end if prompt = options.delete(:prompt) - option_tags = "<option value=\"\">#{prompt}</option>".html_safe + option_tags + option_tags = content_tag(:option, prompt, :value => '').safe_concat(option_tags) end content_tag :select, option_tags, { "name" => html_name, "id" => sanitize_to_id(name) }.update(options.stringify_keys) diff --git a/actionpack/lib/action_view/helpers/javascript_helper.rb b/actionpack/lib/action_view/helpers/javascript_helper.rb index d88f5babb9..5a869d6303 100644 --- a/actionpack/lib/action_view/helpers/javascript_helper.rb +++ b/actionpack/lib/action_view/helpers/javascript_helper.rb @@ -37,7 +37,7 @@ module ActionView # javascript_tag "alert('All is good')" # # Returns: - # <script type="text/javascript"> + # <script> # //<![CDATA[ # alert('All is good') # //]]> @@ -46,7 +46,7 @@ module ActionView # +html_options+ may be a hash of attributes for the <tt>\<script></tt> # tag. Example: # javascript_tag "alert('All is good')", :defer => 'defer' - # # => <script defer="defer" type="text/javascript">alert('All is good')</script> + # # => <script defer="defer">alert('All is good')</script> # # Instead of passing the content as an argument, you can also use a block # in which case, you pass your +html_options+ as the first parameter. @@ -62,7 +62,7 @@ module ActionView content_or_options_with_block end - content_tag(:script, javascript_cdata_section(content), html_options.merge(:type => Mime::JS)) + content_tag(:script, javascript_cdata_section(content), html_options) end def javascript_cdata_section(content) #:nodoc: diff --git a/actionpack/lib/action_view/helpers/number_helper.rb b/actionpack/lib/action_view/helpers/number_helper.rb index 485a9357be..d3a7a1bb96 100644 --- a/actionpack/lib/action_view/helpers/number_helper.rb +++ b/actionpack/lib/action_view/helpers/number_helper.rb @@ -74,11 +74,11 @@ module ActionView number.slice!(0, 1) if number.start_with?(delimiter) && !delimiter.blank? end - str = [] + str = '' str << "+#{country_code}#{delimiter}" unless country_code.blank? str << number str << " x #{extension}" unless extension.blank? - ERB::Util.html_escape(str.join) + ERB::Util.html_escape(str) end # Formats a +number+ into a currency string (e.g., $13.65). You can customize the format @@ -137,12 +137,12 @@ module ActionView begin value = number_with_precision(number, options.merge(:raise => true)) - format.gsub(/%n/, value).gsub(/%u/, unit).html_safe + format.gsub('%n', value).gsub('%u', unit).html_safe rescue InvalidNumberError => e if options[:raise] raise else - formatted_number = format.gsub(/%n/, e.number).gsub(/%u/, unit) + formatted_number = format.gsub('%n', e.number).gsub('%u', unit) e.number.to_s.html_safe? ? formatted_number.html_safe : formatted_number end end diff --git a/actionpack/lib/action_view/helpers/tag_helper.rb b/actionpack/lib/action_view/helpers/tag_helper.rb index 71be2955a8..23777721f6 100644 --- a/actionpack/lib/action_view/helpers/tag_helper.rb +++ b/actionpack/lib/action_view/helpers/tag_helper.rb @@ -14,7 +14,7 @@ module ActionView BOOLEAN_ATTRIBUTES = %w(disabled readonly multiple checked autobuffer autoplay controls loop selected hidden scoped async defer reversed ismap seemless muted required - autofocus novalidate formnovalidate open pubdate).to_set + autofocus novalidate formnovalidate open pubdate itemscope).to_set BOOLEAN_ATTRIBUTES.merge(BOOLEAN_ATTRIBUTES.map {|attribute| attribute.to_sym }) PRE_CONTENT_STRINGS = { diff --git a/actionpack/lib/action_view/helpers/tags/base.rb b/actionpack/lib/action_view/helpers/tags/base.rb index 7c2f12d8e7..e4f431a6d7 100644 --- a/actionpack/lib/action_view/helpers/tags/base.rb +++ b/actionpack/lib/action_view/helpers/tags/base.rb @@ -123,7 +123,7 @@ module ActionView add_default_name_and_id(html_options) select = content_tag("select", add_options(option_tags, options, value(object)), html_options) - if html_options["multiple"] && options.fetch(:include_hidden) { true } + if html_options["multiple"] && options.fetch(:include_hidden, true) tag("input", :disabled => html_options["disabled"], :name => html_options["name"], :type => "hidden", :value => "") + select else select diff --git a/actionpack/lib/action_view/helpers/text_helper.rb b/actionpack/lib/action_view/helpers/text_helper.rb index 3dc651501e..eb806f44cf 100644 --- a/actionpack/lib/action_view/helpers/text_helper.rb +++ b/actionpack/lib/action_view/helpers/text_helper.rb @@ -1,5 +1,6 @@ require 'active_support/core_ext/object/blank' require 'active_support/core_ext/string/filters' +require 'active_support/core_ext/array/extract_options' module ActionView # = Action View Text Helpers @@ -306,12 +307,9 @@ module ActionView # </tr> # <% end %> def cycle(first_value, *values) - if (values.last.instance_of? Hash) - params = values.pop - name = params[:name] - else - name = "default" - end + options = values.extract_options! + name = options.fetch(:name, "default") + values.unshift(first_value) cycle = get_cycle(name) diff --git a/actionpack/lib/action_view/helpers/url_helper.rb b/actionpack/lib/action_view/helpers/url_helper.rb index 4a641fada3..d0f716cc80 100644 --- a/actionpack/lib/action_view/helpers/url_helper.rb +++ b/actionpack/lib/action_view/helpers/url_helper.rb @@ -481,7 +481,7 @@ module ActionView # # => <a href="mailto:me@domain.com">me@domain.com</a> # # mail_to "me@domain.com", "My email", :encode => "javascript" - # # => <script type="text/javascript">eval(decodeURIComponent('%64%6f%63...%27%29%3b'))</script> + # # => <script>eval(decodeURIComponent('%64%6f%63...%27%29%3b'))</script> # # mail_to "me@domain.com", "My email", :encode => "hex" # # => <a href="mailto:%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d">My email</a> @@ -515,7 +515,7 @@ module ActionView "document.write('#{html}');".each_byte do |c| string << sprintf("%%%x", c) end - "<script type=\"#{Mime::JS}\">eval(decodeURIComponent('#{string}'))</script>".html_safe + "<script>eval(decodeURIComponent('#{string}'))</script>".html_safe when "hex" email_address_encoded = email_address_obfuscated.unpack('C*').map {|c| sprintf("&#%d;", c) |