diff options
Diffstat (limited to 'actionpack/lib/action_view')
11 files changed, 49 insertions, 17 deletions
diff --git a/actionpack/lib/action_view/asset_paths.rb b/actionpack/lib/action_view/asset_paths.rb index aa5db0d7bc..f6115dbb1b 100644 --- a/actionpack/lib/action_view/asset_paths.rb +++ b/actionpack/lib/action_view/asset_paths.rb @@ -37,7 +37,7 @@ module ActionView end def is_uri?(path) - path =~ %r{^[-a-z]+://|^cid:|^//} + path =~ %r{^[-a-z]+://|^(?:cid|data):|^//} end private diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb index 5dbba3c4a7..51d5d586bf 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb @@ -272,7 +272,7 @@ module ActionView # The alias +path_to_image+ is provided to avoid that. Rails uses the alias internally, and # plugin authors are encouraged to do so. def image_path(source) - asset_paths.compute_public_path(source, 'images') + source.present? ? asset_paths.compute_public_path(source, 'images') : "" end alias_method :path_to_image, :image_path # aliased to avoid conflicts with an image_path named route @@ -358,7 +358,7 @@ module ActionView src = options[:src] = path_to_image(source) - unless src =~ /^cid:/ + unless src =~ /^(?:cid|data):/ || src.blank? options[:alt] = options.fetch(:alt){ image_alt(src) } end @@ -367,6 +367,8 @@ module ActionView end if mouseover = options.delete(:mouseover) + ActiveSupport::Deprecation.warn ":mouseover option is deprecated and will be removed from Rails 4.0" + options[:onmouseover] = "this.src='#{path_to_image(mouseover)}'" options[:onmouseout] = "this.src='#{src}'" end diff --git a/actionpack/lib/action_view/helpers/asset_tag_helpers/asset_paths.rb b/actionpack/lib/action_view/helpers/asset_tag_helpers/asset_paths.rb index dd4e9ae4cc..35f91cec18 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helpers/asset_paths.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helpers/asset_paths.rb @@ -1,5 +1,6 @@ require 'thread' require 'active_support/core_ext/file' +require 'active_support/core_ext/module/attribute_accessors' module ActionView module Helpers diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index edca950638..a3409ee3c7 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -9,6 +9,7 @@ require 'active_support/core_ext/module/method_names' require 'active_support/core_ext/object/blank' require 'active_support/core_ext/string/output_safety' require 'active_support/core_ext/array/extract_options' +require 'active_support/core_ext/string/inflections' module ActionView # = Action View Form Helpers @@ -656,15 +657,16 @@ module ActionView # 'Accept <a href="/terms">Terms</a>.'.html_safe # end def label(object_name, method, content_or_options = nil, options = nil, &block) + options ||= {} + content_is_options = content_or_options.is_a?(Hash) if content_is_options || block_given? - options = content_or_options if content_is_options + options.merge!(content_or_options) if content_is_options text = nil else text = content_or_options end - options ||= {} InstanceTag.new(object_name, method, self, options.delete(:object)).to_label_tag(text, options, &block) end @@ -958,9 +960,14 @@ module ActionView object_name = ActiveModel::Naming.param_key(object) end - builder = options[:builder] || ActionView::Base.default_form_builder + builder = options[:builder] || default_form_builder builder.new(object_name, object, self, options, block) end + + def default_form_builder + builder = ActionView::Base.default_form_builder + builder.respond_to?(:constantize) ? builder.constantize : builder + end end class InstanceTag diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb index 066b98d4a2..3d3ae44eb4 100644 --- a/actionpack/lib/action_view/helpers/form_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb @@ -417,6 +417,8 @@ module ActionView options = options.stringify_keys if disable_with = options.delete("disable_with") + ActiveSupport::Deprecation.warn ":disable_with option is deprecated and will be removed from Rails 4.0. Use 'data-disable-with' instead" + options["data-disable-with"] = disable_with end @@ -467,6 +469,8 @@ module ActionView options = options.stringify_keys if disable_with = options.delete("disable_with") + ActiveSupport::Deprecation.warn ":disable_with option is deprecated and will be removed from Rails 4.0. Use 'data-disable-with' instead" + options["data-disable-with"] = disable_with end diff --git a/actionpack/lib/action_view/helpers/javascript_helper.rb b/actionpack/lib/action_view/helpers/javascript_helper.rb index 842f4c23a3..042ac4e9ee 100644 --- a/actionpack/lib/action_view/helpers/javascript_helper.rb +++ b/actionpack/lib/action_view/helpers/javascript_helper.rb @@ -82,6 +82,8 @@ module ActionView # # => <input class="ok" onclick="alert('Hello world!');" type="button" value="Greeting" /> # def button_to_function(name, function=nil, html_options={}) + ActiveSupport::Deprecation.warn("button_to_function is deprecated and will be removed from Rails 4.0") + onclick = "#{"#{html_options[:onclick]}; " if html_options[:onclick]}#{function};" tag(:input, html_options.merge(:type => 'button', :value => name, :onclick => onclick)) @@ -100,6 +102,8 @@ module ActionView # # => <a class="nav_link" href="#" onclick="alert('Hello world!'); return false;">Greeting</a> # def link_to_function(name, function, html_options={}) + ActiveSupport::Deprecation.warn("link_to_function is deprecated and will be removed from Rails 4.0") + onclick = "#{"#{html_options[:onclick]}; " if html_options[:onclick]}#{function}; return false;" href = html_options[:href] || '#' diff --git a/actionpack/lib/action_view/helpers/number_helper.rb b/actionpack/lib/action_view/helpers/number_helper.rb index eda16903b0..b5e33dc0fc 100644 --- a/actionpack/lib/action_view/helpers/number_helper.rb +++ b/actionpack/lib/action_view/helpers/number_helper.rb @@ -427,10 +427,10 @@ module ActionView # * *integers*: <tt>:unit</tt>, <tt>:ten</tt>, <tt>:hundred</tt>, <tt>:thousand</tt>, <tt>:million</tt>, <tt>:billion</tt>, <tt>:trillion</tt>, <tt>:quadrillion</tt> # * *fractionals*: <tt>:deci</tt>, <tt>:centi</tt>, <tt>:mili</tt>, <tt>:micro</tt>, <tt>:nano</tt>, <tt>:pico</tt>, <tt>:femto</tt> # * <tt>:format</tt> - Sets the format of the output string (defaults to "%n %u"). The field types are: - # * <tt>:raise</tt> - If true, raises +InvalidNumberError+ when the argument is invalid. - # # %u The quantifier (ex.: 'thousand') # %n The number + # * <tt>:raise</tt> - If true, raises +InvalidNumberError+ when the argument is invalid. + # # # ==== Examples # number_to_human(123) # => "123" diff --git a/actionpack/lib/action_view/helpers/record_tag_helper.rb b/actionpack/lib/action_view/helpers/record_tag_helper.rb index b351302d01..aae6389445 100644 --- a/actionpack/lib/action_view/helpers/record_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/record_tag_helper.rb @@ -96,8 +96,8 @@ module ActionView # for each record. def content_tag_for_single_record(tag_name, record, prefix, options, &block) options, prefix = prefix, nil if prefix.is_a?(Hash) - options ||= {} - options.merge!({ :class => "#{dom_class(record, prefix)} #{options[:class]}".strip, :id => dom_id(record, prefix) }) + options = options ? options.dup : {} + options.merge!(:class => "#{dom_class(record, prefix)} #{options[:class]}".strip, :id => dom_id(record, prefix)) if block.arity == 0 content_tag(tag_name, capture(&block), options) else diff --git a/actionpack/lib/action_view/helpers/text_helper.rb b/actionpack/lib/action_view/helpers/text_helper.rb index 209360ee82..3490b1f34f 100644 --- a/actionpack/lib/action_view/helpers/text_helper.rb +++ b/actionpack/lib/action_view/helpers/text_helper.rb @@ -111,6 +111,9 @@ module ActionView def highlight(text, phrases, *args) options = args.extract_options! unless args.empty? + ActiveSupport::Deprecation.warn "Calling highlight with a highlighter as an argument is deprecated. " \ + "Please call with :highlighter => '#{args[0]}' instead.", caller + options[:highlighter] = args[0] || '<strong class="highlight">\1</strong>' end options.reverse_merge!(:highlighter => '<strong class="highlight">\1</strong>') @@ -156,6 +159,9 @@ module ActionView options = args.extract_options! unless args.empty? + ActiveSupport::Deprecation.warn "Calling excerpt with radius and omission as arguments is deprecated. " \ + "Please call with :radius => #{args[0]}#{", :omission => '#{args[1]}'" if args[1]} instead.", caller + options[:radius] = args[0] || 100 options[:omission] = args[1] || "..." end @@ -217,6 +223,9 @@ module ActionView def word_wrap(text, *args) options = args.extract_options! unless args.blank? + ActiveSupport::Deprecation.warn "Calling word_wrap with line_width as an argument is deprecated. " \ + "Please call with :line_width => #{args[0]} instead.", caller + options[:line_width] = args[0] || 80 end options.reverse_merge!(:line_width => 80) diff --git a/actionpack/lib/action_view/helpers/url_helper.rb b/actionpack/lib/action_view/helpers/url_helper.rb index 1f1cd3cee3..6f05881d08 100644 --- a/actionpack/lib/action_view/helpers/url_helper.rb +++ b/actionpack/lib/action_view/helpers/url_helper.rb @@ -301,7 +301,7 @@ module ActionView # # <div><input value="Create" type="submit" /></div> # # </form>" # - # + # # <%= button_to "Delete Image", { :action => "delete", :id => @image.id }, # :confirm => "Are you sure?", :method => :delete %> # # => "<form method="post" action="/images/delete/1" class="button_to"> @@ -317,7 +317,7 @@ module ActionView # # => "<form class='button_to' method='post' action='http://www.example.com' data-remote='true'> # # <div> # # <input name='_method' value='delete' type='hidden' /> - # # <input value='Destroy' type='submit' disable_with='loading...' data-confirm='Are you sure?' /> + # # <input value='Destroy' type='submit' data-disable-with='loading...' data-confirm='Are you sure?' /> # # </div> # # </form>" # # @@ -333,9 +333,9 @@ module ActionView form_method = method.to_s == 'get' ? 'get' : 'post' form_options = html_options.delete('form') || {} form_options[:class] ||= html_options.delete('form_class') || 'button_to' - + remote = html_options.delete('remote') - + request_token_tag = '' if form_method == 'post' && protect_against_forgery? request_token_tag = tag(:input, :type => "hidden", :name => request_forgery_protection_token.to_s, :value => form_authenticity_token) @@ -350,7 +350,7 @@ module ActionView form_options.merge!(:method => form_method, :action => url) form_options.merge!("data-remote" => "true") if remote - + "#{tag(:form, form_options, true)}<div>#{method_tag}#{tag("input", html_options)}#{request_token_tag}</div></form>".html_safe end @@ -622,7 +622,12 @@ module ActionView confirm = html_options.delete('confirm') method = html_options.delete('method') - html_options["data-disable-with"] = disable_with if disable_with + if disable_with + ActiveSupport::Deprecation.warn ":disable_with option is deprecated and will be removed from Rails 4.0. Use 'data-disable-with' instead" + + html_options["data-disable-with"] = disable_with + end + html_options["data-confirm"] = confirm if confirm add_method_to_attributes!(html_options, method) if method diff --git a/actionpack/lib/action_view/renderer/partial_renderer.rb b/actionpack/lib/action_view/renderer/partial_renderer.rb index 25c41f042b..3093aca91e 100644 --- a/actionpack/lib/action_view/renderer/partial_renderer.rb +++ b/actionpack/lib/action_view/renderer/partial_renderer.rb @@ -407,7 +407,7 @@ module ActionView end def retrieve_variable(path) - variable = @options[:as].try(:to_sym) || path[%r'_?(\w+)(\.\w+)*$', 1].to_sym + variable = @options.fetch(:as) { path[%r'_?(\w+)(\.\w+)*$', 1] }.try(:to_sym) variable_counter = :"#{variable}_counter" if @collection [variable, variable_counter] end |