diff options
author | Xavier Noria <fxn@hashref.com> | 2016-08-06 18:48:35 +0200 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2016-08-06 18:48:35 +0200 |
commit | 66a7cfa91045e05f134efc9ac0e226e66161e2e6 (patch) | |
tree | 39b8554cfe4e27a30be3eed905bc2afcc26cfe89 /actionview/lib/action_view/helpers | |
parent | bde6547bb6a8ddf18fb687bf20893d3dc87e0358 (diff) | |
download | rails-66a7cfa91045e05f134efc9ac0e226e66161e2e6.tar.gz rails-66a7cfa91045e05f134efc9ac0e226e66161e2e6.tar.bz2 rails-66a7cfa91045e05f134efc9ac0e226e66161e2e6.zip |
applies new string literal convention in actionview/lib
The current code base is not uniform. After some discussion,
we have chosen to go with double quotes by default.
Diffstat (limited to 'actionview/lib/action_view/helpers')
28 files changed, 170 insertions, 170 deletions
diff --git a/actionview/lib/action_view/helpers/active_model_helper.rb b/actionview/lib/action_view/helpers/active_model_helper.rb index d5222e3616..4f76195760 100644 --- a/actionview/lib/action_view/helpers/active_model_helper.rb +++ b/actionview/lib/action_view/helpers/active_model_helper.rb @@ -1,5 +1,5 @@ -require 'active_support/core_ext/module/attribute_accessors' -require 'active_support/core_ext/enumerable' +require "active_support/core_ext/module/attribute_accessors" +require "active_support/core_ext/enumerable" module ActionView # = Active Model Helpers @@ -42,7 +42,7 @@ module ActionView end def tag_generate_errors?(options) - options['type'] != 'hidden' + options["type"] != "hidden" end end end diff --git a/actionview/lib/action_view/helpers/asset_tag_helper.rb b/actionview/lib/action_view/helpers/asset_tag_helper.rb index d7acf08b45..a3064046e4 100644 --- a/actionview/lib/action_view/helpers/asset_tag_helper.rb +++ b/actionview/lib/action_view/helpers/asset_tag_helper.rb @@ -1,8 +1,8 @@ -require 'active_support/core_ext/array/extract_options' -require 'active_support/core_ext/hash/keys' -require 'active_support/core_ext/regexp' -require 'action_view/helpers/asset_url_helper' -require 'action_view/helpers/tag_helper' +require "active_support/core_ext/array/extract_options" +require "active_support/core_ext/hash/keys" +require "active_support/core_ext/regexp" +require "action_view/helpers/asset_url_helper" +require "action_view/helpers/tag_helper" module ActionView # = Action View Asset Tag Helpers @@ -56,7 +56,7 @@ module ActionView # # => <script src="http://www.example.com/xmlhr.js"></script> def javascript_include_tag(*sources) options = sources.extract_options!.stringify_keys - path_options = options.extract!('protocol', 'extname', 'host').symbolize_keys + path_options = options.extract!("protocol", "extname", "host").symbolize_keys sources.uniq.map { |source| tag_options = { "src" => path_to_javascript(source, path_options) @@ -92,7 +92,7 @@ module ActionView # # <link href="/css/stylish.css" media="screen" rel="stylesheet" /> def stylesheet_link_tag(*sources) options = sources.extract_options!.stringify_keys - path_options = options.extract!('protocol', 'host').symbolize_keys + path_options = options.extract!("protocol", "host").symbolize_keys sources.uniq.map { |source| tag_options = { @@ -170,10 +170,10 @@ module ActionView # # favicon_link_tag 'mb-icon.png', rel: 'apple-touch-icon', type: 'image/png' # # => <link href="/assets/mb-icon.png" rel="apple-touch-icon" type="image/png" /> - def favicon_link_tag(source='favicon.ico', options={}) - tag('link', { - :rel => 'shortcut icon', - :type => 'image/x-icon', + def favicon_link_tag(source="favicon.ico", options={}) + tag("link", { + :rel => "shortcut icon", + :type => "image/x-icon", :href => path_to_image(source) }.merge!(options.symbolize_keys)) end @@ -214,7 +214,7 @@ module ActionView src = options[:src] = path_to_image(source) - unless src.start_with?('cid:') || src.start_with?('data:') || src.blank? + unless src.start_with?("cid:") || src.start_with?("data:") || src.blank? options[:alt] = options.fetch(:alt) { image_alt(src) } end @@ -240,7 +240,7 @@ module ActionView # image_alt('underscored_file_name.png') # # => Underscored file name def image_alt(src) - File.basename(src, '.*'.freeze).sub(/-[[:xdigit:]]{32,64}\z/, ''.freeze).tr('-_'.freeze, ' '.freeze).capitalize + File.basename(src, ".*".freeze).sub(/-[[:xdigit:]]{32,64}\z/, "".freeze).tr("-_".freeze, " ".freeze).capitalize end # Returns an HTML video tag for the +sources+. If +sources+ is a string, @@ -282,7 +282,7 @@ module ActionView # video_tag(["trailer.ogg", "trailer.flv"], size: "160x120") # # => <video height="120" width="160"><source src="/videos/trailer.ogg" /><source src="/videos/trailer.flv" /></video> def video_tag(*sources) - multiple_sources_tag('video', sources) do |options| + multiple_sources_tag("video", sources) do |options| options[:poster] = path_to_image(options[:poster]) if options[:poster] options[:width], options[:height] = extract_dimensions(options.delete(:size)) if options[:size] end @@ -301,7 +301,7 @@ module ActionView # audio_tag("sound.wav", "sound.mid") # # => <audio><source src="/audios/sound.wav" /><source src="/audios/sound.mid" /></audio> def audio_tag(*sources) - multiple_sources_tag('audio', sources) + multiple_sources_tag("audio", sources) end private @@ -324,7 +324,7 @@ module ActionView def extract_dimensions(size) size = size.to_s if /\A\d+x\d+\z/.match?(size) - size.split('x') + size.split("x") elsif /\A\d+\z/.match?(size) [size, size] end diff --git a/actionview/lib/action_view/helpers/asset_url_helper.rb b/actionview/lib/action_view/helpers/asset_url_helper.rb index 8af01617fa..ca9846b90d 100644 --- a/actionview/lib/action_view/helpers/asset_url_helper.rb +++ b/actionview/lib/action_view/helpers/asset_url_helper.rb @@ -1,5 +1,5 @@ -require 'zlib' -require 'active_support/core_ext/regexp' +require "zlib" +require "active_support/core_ext/regexp" module ActionView # = Action View Asset URL Helpers @@ -132,10 +132,10 @@ module ActionView raise ArgumentError, "nil is not a valid asset source" if source.nil? source = source.to_s - return '' if source.blank? + return "" if source.blank? return source if URI_REGEXP.match?(source) - tail, source = source[/([\?#].+)$/], source.sub(/([\?#].+)$/, ''.freeze) + tail, source = source[/([\?#].+)$/], source.sub(/([\?#].+)$/, "".freeze) if extname = compute_asset_extname(source, options) source = "#{source}#{extname}" @@ -174,8 +174,8 @@ module ActionView alias_method :url_to_asset, :asset_url # aliased to avoid conflicts with an asset_url named route ASSET_EXTENSIONS = { - javascript: '.js', - stylesheet: '.css' + javascript: ".js", + stylesheet: ".css" } # Compute extname to append to asset path. Returns nil if @@ -188,12 +188,12 @@ module ActionView # Maps asset types to public directory. ASSET_PUBLIC_DIRECTORIES = { - audio: '/audios', - font: '/fonts', - image: '/images', - javascript: '/javascripts', - stylesheet: '/stylesheets', - video: '/videos' + audio: "/audios", + font: "/fonts", + image: "/images", + javascript: "/javascripts", + stylesheet: "/stylesheets", + video: "/videos" } # Computes asset path to public directory. Plugins and @@ -220,7 +220,7 @@ module ActionView args = [source] args << request if request && (arity > 1 || arity < 0) host = host.call(*args) - elsif host.include?('%d') + elsif host.include?("%d") host = host % (Zlib.crc32(source) % 4) end end diff --git a/actionview/lib/action_view/helpers/atom_feed_helper.rb b/actionview/lib/action_view/helpers/atom_feed_helper.rb index c875f5870f..9a713d573e 100644 --- a/actionview/lib/action_view/helpers/atom_feed_helper.rb +++ b/actionview/lib/action_view/helpers/atom_feed_helper.rb @@ -1,4 +1,4 @@ -require 'set' +require "set" module ActionView # = Action View Atom Feed Helpers @@ -112,13 +112,13 @@ module ActionView end end - feed_opts = {"xml:lang" => options[:language] || "en-US", "xmlns" => 'http://www.w3.org/2005/Atom'} + feed_opts = {"xml:lang" => options[:language] || "en-US", "xmlns" => "http://www.w3.org/2005/Atom"} feed_opts.merge!(options).reject!{|k,v| !k.to_s.match(/^xml/)} xml.feed(feed_opts) do xml.id(options[:id] || "tag:#{request.host},#{options[:schema_date]}:#{request.fullpath.split(".")[0]}") - xml.link(:rel => 'alternate', :type => 'text/html', :href => options[:root_url] || (request.protocol + request.host_with_port)) - xml.link(:rel => 'self', :type => 'application/atom+xml', :href => options[:url] || request.url) + xml.link(:rel => "alternate", :type => "text/html", :href => options[:root_url] || (request.protocol + request.host_with_port)) + xml.link(:rel => "self", :type => "application/atom+xml", :href => options[:url] || request.url) yield AtomFeedBuilder.new(xml, self, options) end @@ -138,7 +138,7 @@ module ActionView def method_missing(method, *arguments, &block) if xhtml_block?(method, arguments) @xml.__send__(method, *arguments) do - @xml.div(:xmlns => 'http://www.w3.org/1999/xhtml') do |xhtml| + @xml.div(:xmlns => "http://www.w3.org/1999/xhtml") do |xhtml| block.call(xhtml) end end @@ -153,7 +153,7 @@ module ActionView def xhtml_block?(method, arguments) if XHTML_TAG_NAMES.include?(method.to_s) last = arguments.last - last.is_a?(Hash) && last[:type].to_s == 'xhtml' + last.is_a?(Hash) && last[:type].to_s == "xhtml" end end end @@ -189,10 +189,10 @@ module ActionView @xml.updated((options[:updated] || record.updated_at).xmlschema) end - type = options.fetch(:type, 'text/html') + type = options.fetch(:type, "text/html") url = options.fetch(:url) { @view.polymorphic_url(record) } - @xml.link(:rel => 'alternate', :type => type, :href => url) if url + @xml.link(:rel => "alternate", :type => type, :href => url) if url yield AtomBuilder.new(@xml) end diff --git a/actionview/lib/action_view/helpers/capture_helper.rb b/actionview/lib/action_view/helpers/capture_helper.rb index df8d0affd0..5b569b5923 100644 --- a/actionview/lib/action_view/helpers/capture_helper.rb +++ b/actionview/lib/action_view/helpers/capture_helper.rb @@ -1,4 +1,4 @@ -require 'active_support/core_ext/string/output_safety' +require "active_support/core_ext/string/output_safety" module ActionView # = Action View Capture Helper diff --git a/actionview/lib/action_view/helpers/controller_helper.rb b/actionview/lib/action_view/helpers/controller_helper.rb index 3569fba8c6..645c30c2ea 100644 --- a/actionview/lib/action_view/helpers/controller_helper.rb +++ b/actionview/lib/action_view/helpers/controller_helper.rb @@ -1,4 +1,4 @@ -require 'active_support/core_ext/module/attr_internal' +require "active_support/core_ext/module/attr_internal" module ActionView module Helpers diff --git a/actionview/lib/action_view/helpers/csrf_helper.rb b/actionview/lib/action_view/helpers/csrf_helper.rb index 5af92c4ff2..ba3693b413 100644 --- a/actionview/lib/action_view/helpers/csrf_helper.rb +++ b/actionview/lib/action_view/helpers/csrf_helper.rb @@ -20,8 +20,8 @@ module ActionView def csrf_meta_tags if protect_against_forgery? [ - tag('meta', :name => 'csrf-param', :content => request_forgery_protection_token), - tag('meta', :name => 'csrf-token', :content => form_authenticity_token) + tag("meta", :name => "csrf-param", :content => request_forgery_protection_token), + tag("meta", :name => "csrf-token", :content => form_authenticity_token) ].join("\n").html_safe end end diff --git a/actionview/lib/action_view/helpers/date_helper.rb b/actionview/lib/action_view/helpers/date_helper.rb index a02702bf7a..a6740b3eec 100644 --- a/actionview/lib/action_view/helpers/date_helper.rb +++ b/actionview/lib/action_view/helpers/date_helper.rb @@ -1,10 +1,10 @@ -require 'date' -require 'action_view/helpers/tag_helper' -require 'active_support/core_ext/array/extract_options' -require 'active_support/core_ext/date/conversions' -require 'active_support/core_ext/hash/slice' -require 'active_support/core_ext/object/acts_like' -require 'active_support/core_ext/object/with_options' +require "date" +require "action_view/helpers/tag_helper" +require "active_support/core_ext/array/extract_options" +require "active_support/core_ext/date/conversions" +require "active_support/core_ext/hash/slice" +require "active_support/core_ext/object/acts_like" +require "active_support/core_ext/object/with_options" module ActionView module Helpers @@ -692,7 +692,7 @@ module ActionView class DateTimeSelector #:nodoc: include ActionView::Helpers::TagHelper - DEFAULT_PREFIX = 'date'.freeze + DEFAULT_PREFIX = "date".freeze POSITION = { :year => 1, :month => 2, :day => 3, :hour => 4, :minute => 5, :second => 6 }.freeze @@ -710,8 +710,8 @@ module ActionView @options = options.dup @html_options = html_options.dup @datetime = datetime - @options[:datetime_separator] ||= ' — ' - @options[:time_separator] ||= ' : ' + @options[:datetime_separator] ||= " — " + @options[:time_separator] ||= " : " end def select_datetime @@ -821,7 +821,7 @@ module ActionView def select_year if !@datetime || @datetime == 0 - val = '1' + val = "1" middle_year = Date.today.year else val = middle_year = year @@ -914,7 +914,7 @@ module ActionView if @options[:use_month_numbers] number elsif @options[:use_two_digit_numbers] - '%02d' % number + "%02d" % number elsif @options[:add_month_numbers] "#{number} - #{month_names[number]}" elsif format_string = @options[:month_format_string] @@ -996,11 +996,11 @@ module ActionView :id => input_id_from_type(type), :name => input_name_from_type(type) }.merge!(@html_options) - select_options[:disabled] = 'disabled' if @options[:disabled] + select_options[:disabled] = "disabled" if @options[:disabled] select_options[:class] = css_class_attribute(type, select_options[:class], @options[:with_css_classes]) if @options[:with_css_classes] select_html = "\n" - select_html << content_tag("option".freeze, '', :value => '') + "\n" if @options[:include_blank] + select_html << content_tag("option".freeze, "", :value => "") + "\n" if @options[:include_blank] select_html << prompt_option_tag(type, @options[:prompt]) + "\n" if @options[:prompt] select_html << select_options_as_html @@ -1018,7 +1018,7 @@ module ActionView type end - [html_options_class, css_class].compact.join(' ') + [html_options_class, css_class].compact.join(" ") end # Builds a prompt option tag with supplied options or from default options. @@ -1035,7 +1035,7 @@ module ActionView I18n.translate(:"datetime.prompts.#{type}", :locale => @options[:locale]) end - prompt ? content_tag("option".freeze, prompt, :value => '') : '' + prompt ? content_tag("option".freeze, prompt, :value => "") : "" end # Builds hidden input tag for date part and value. @@ -1048,7 +1048,7 @@ module ActionView :name => input_name_from_type(type), :value => value }.merge!(@html_options.slice(:disabled)) - select_options[:disabled] = 'disabled' if @options[:disabled] + select_options[:disabled] = "disabled" if @options[:disabled] tag(:input, select_options) + "\n".html_safe end @@ -1070,8 +1070,8 @@ module ActionView # Returns the id attribute for the input tag. # => "post_written_on_1i" def input_id_from_type(type) - id = input_name_from_type(type).gsub(/([\[\(])|(\]\[)/, '_').gsub(/[\]\)]/, '') - id = @options[:namespace] + '_' + id if @options[:namespace] + id = input_name_from_type(type).gsub(/([\[\(])|(\]\[)/, "_").gsub(/[\]\)]/, "") + id = @options[:namespace] + "_" + id if @options[:namespace] id end @@ -1079,7 +1079,7 @@ module ActionView # Given an ordering of datetime components, create the selection HTML # and join them with their appropriate separators. def build_selects_from_types(order) - select = '' + select = "" first_visible = order.find { |type| !@options[:"discard_#{type}"] } order.reverse_each do |type| separator = separator(type) unless type == first_visible # don't add before first visible field diff --git a/actionview/lib/action_view/helpers/form_helper.rb b/actionview/lib/action_view/helpers/form_helper.rb index 3d2ae0cfe0..3f7b6c0f9c 100644 --- a/actionview/lib/action_view/helpers/form_helper.rb +++ b/actionview/lib/action_view/helpers/form_helper.rb @@ -1,14 +1,14 @@ -require 'cgi' -require 'action_view/helpers/date_helper' -require 'action_view/helpers/tag_helper' -require 'action_view/helpers/form_tag_helper' -require 'action_view/helpers/active_model_helper' -require 'action_view/model_naming' -require 'action_view/record_identifier' -require 'active_support/core_ext/module/attribute_accessors' -require 'active_support/core_ext/hash/slice' -require 'active_support/core_ext/string/output_safety' -require 'active_support/core_ext/string/inflections' +require "cgi" +require "action_view/helpers/date_helper" +require "action_view/helpers/tag_helper" +require "action_view/helpers/form_tag_helper" +require "action_view/helpers/active_model_helper" +require "action_view/model_naming" +require "action_view/record_identifier" +require "active_support/core_ext/module/attribute_accessors" +require "active_support/core_ext/hash/slice" +require "active_support/core_ext/string/output_safety" +require "active_support/core_ext/string/inflections" module ActionView # = Action View Form Helpers @@ -1270,7 +1270,7 @@ module ActionView end def self._to_partial_path - @_to_partial_path ||= name.demodulize.underscore.sub!(/_builder$/, '') + @_to_partial_path ||= name.demodulize.underscore.sub!(/_builder$/, "") end def to_partial_path @@ -1574,7 +1574,7 @@ module ActionView record_name = if index "#{object_name}[#{index}][#{record_name}]" - elsif record_name.to_s.end_with?('[]') + elsif record_name.to_s.end_with?("[]") record_name = record_name.to_s.sub(/(.*)\[\]$/, "[\\1][#{record_object.id}]") "#{object_name}#{record_name}" else diff --git a/actionview/lib/action_view/helpers/form_options_helper.rb b/actionview/lib/action_view/helpers/form_options_helper.rb index 0cd3207b12..07d4310a4e 100644 --- a/actionview/lib/action_view/helpers/form_options_helper.rb +++ b/actionview/lib/action_view/helpers/form_options_helper.rb @@ -1,9 +1,9 @@ -require 'cgi' -require 'erb' -require 'action_view/helpers/form_helper' -require 'active_support/core_ext/string/output_safety' -require 'active_support/core_ext/array/extract_options' -require 'active_support/core_ext/array/wrap' +require "cgi" +require "erb" +require "action_view/helpers/form_helper" +require "active_support/core_ext/string/output_safety" +require "active_support/core_ext/array/extract_options" +require "active_support/core_ext/array/wrap" module ActionView # = Action View Form Option Helpers @@ -578,7 +578,7 @@ module ActionView end zone_options.safe_concat options_for_select(convert_zones[priority_zones], selected) - zone_options.safe_concat content_tag("option".freeze, '-------------', value: '', disabled: true) + zone_options.safe_concat content_tag("option".freeze, "-------------", value: "", disabled: true) zone_options.safe_concat "\n" zones = zones - priority_zones @@ -800,7 +800,7 @@ module ActionView end def prompt_text(prompt) - prompt.kind_of?(String) ? prompt : I18n.translate('helpers.select.prompt', default: 'Please select') + prompt.kind_of?(String) ? prompt : I18n.translate("helpers.select.prompt", default: "Please select") end end diff --git a/actionview/lib/action_view/helpers/form_tag_helper.rb b/actionview/lib/action_view/helpers/form_tag_helper.rb index f1375570f2..5b1392a099 100644 --- a/actionview/lib/action_view/helpers/form_tag_helper.rb +++ b/actionview/lib/action_view/helpers/form_tag_helper.rb @@ -1,7 +1,7 @@ -require 'cgi' -require 'action_view/helpers/tag_helper' -require 'active_support/core_ext/string/output_safety' -require 'active_support/core_ext/module/attribute_accessors' +require "cgi" +require "action_view/helpers/tag_helper" +require "active_support/core_ext/string/output_safety" +require "active_support/core_ext/module/attribute_accessors" module ActionView # = Action View Form Tag Helpers @@ -134,11 +134,11 @@ module ActionView if options.include?(:include_blank) include_blank = options.delete(:include_blank) - options_for_blank_options_tag = { value: '' } + options_for_blank_options_tag = { value: "" } if include_blank == true - include_blank = '' - options_for_blank_options_tag[:label] = ' ' + include_blank = "" + options_for_blank_options_tag[:label] = " " end if include_blank @@ -147,7 +147,7 @@ module ActionView end if prompt = options.delete(:prompt) - option_tags = content_tag("option".freeze, prompt, value: '').safe_concat(option_tags) + option_tags = content_tag("option".freeze, prompt, value: "").safe_concat(option_tags) end content_tag "select".freeze, option_tags, { "name" => html_name, "id" => sanitize_to_id(name) }.update(options.stringify_keys) @@ -518,12 +518,12 @@ module ActionView options ||= {} end - options = { 'name' => 'button', 'type' => 'submit' }.merge!(options.stringify_keys) + options = { "name" => "button", "type" => "submit" }.merge!(options.stringify_keys) if block_given? content_tag :button, options, &block else - content_tag :button, content_or_options || 'Button', options + content_tag :button, content_or_options || "Button", options end end @@ -693,7 +693,7 @@ module ActionView # * <tt>:step</tt> - The acceptable value granularity. # * Otherwise accepts the same options as text_field_tag. def datetime_field_tag(name, value = nil, options = {}) - text_field_tag(name, value, options.merge(type: 'datetime-local')) + text_field_tag(name, value, options.merge(type: "datetime-local")) end alias datetime_local_field_tag datetime_field_tag @@ -858,10 +858,10 @@ module ActionView method = html_options.delete("method").to_s.downcase method_tag = case method - when 'get' + when "get" html_options["method"] = "get" - '' - when 'post', '' + "" + when "post", "" html_options["method"] = "post" token_tag(authenticity_token, form_options: { action: html_options["action"], @@ -895,7 +895,7 @@ module ActionView # see http://www.w3.org/TR/html4/types.html#type-name def sanitize_to_id(name) - name.to_s.delete(']').tr('^-a-zA-Z0-9:.', "_") + name.to_s.delete("]").tr("^-a-zA-Z0-9:.", "_") end end end diff --git a/actionview/lib/action_view/helpers/javascript_helper.rb b/actionview/lib/action_view/helpers/javascript_helper.rb index ed7e882c94..8f7be4905d 100644 --- a/actionview/lib/action_view/helpers/javascript_helper.rb +++ b/actionview/lib/action_view/helpers/javascript_helper.rb @@ -1,11 +1,11 @@ -require 'action_view/helpers/tag_helper' +require "action_view/helpers/tag_helper" module ActionView module Helpers module JavaScriptHelper JS_ESCAPE_MAP = { '\\' => '\\\\', - '</' => '<\/', + "</" => '<\/', "\r\n" => '\n', "\n" => '\n', "\r" => '\n', @@ -13,8 +13,8 @@ module ActionView "'" => "\\'" } - JS_ESCAPE_MAP["\342\200\250".force_encoding(Encoding::UTF_8).encode!] = '
' - JS_ESCAPE_MAP["\342\200\251".force_encoding(Encoding::UTF_8).encode!] = '
' + JS_ESCAPE_MAP["\342\200\250".force_encoding(Encoding::UTF_8).encode!] = "
" + JS_ESCAPE_MAP["\342\200\251".force_encoding(Encoding::UTF_8).encode!] = "
" # Escapes carriage returns and single and double quotes for JavaScript segments. # @@ -27,7 +27,7 @@ module ActionView result = javascript.gsub(/(\\|<\/|\r\n|\342\200\250|\342\200\251|[\n\r"'])/u) {|match| JS_ESCAPE_MAP[match] } javascript.html_safe? ? result.html_safe : result else - '' + "" end end diff --git a/actionview/lib/action_view/helpers/number_helper.rb b/actionview/lib/action_view/helpers/number_helper.rb index 23081c5f07..3f665b39a3 100644 --- a/actionview/lib/action_view/helpers/number_helper.rb +++ b/actionview/lib/action_view/helpers/number_helper.rb @@ -1,6 +1,6 @@ -require 'active_support/core_ext/hash/keys' -require 'active_support/core_ext/string/output_safety' -require 'active_support/number_helper' +require "active_support/core_ext/hash/keys" +require "active_support/core_ext/string/output_safety" +require "active_support/number_helper" module ActionView # = Action View Number Helpers diff --git a/actionview/lib/action_view/helpers/output_safety_helper.rb b/actionview/lib/action_view/helpers/output_safety_helper.rb index d4b55423a8..f84bff7d06 100644 --- a/actionview/lib/action_view/helpers/output_safety_helper.rb +++ b/actionview/lib/action_view/helpers/output_safety_helper.rb @@ -1,4 +1,4 @@ -require 'active_support/core_ext/string/output_safety' +require "active_support/core_ext/string/output_safety" module ActionView #:nodoc: # = Action View Raw Output Helper @@ -42,9 +42,9 @@ module ActionView #:nodoc: options.assert_valid_keys(:words_connector, :two_words_connector, :last_word_connector, :locale) default_connectors = { - :words_connector => ', ', - :two_words_connector => ' and ', - :last_word_connector => ', and ' + :words_connector => ", ", + :two_words_connector => " and ", + :last_word_connector => ", and " } if defined?(I18n) i18n_connectors = I18n.translate(:'support.array', locale: options[:locale], default: {}) @@ -54,7 +54,7 @@ module ActionView #:nodoc: case array.length when 0 - ''.html_safe + "".html_safe when 1 ERB::Util.html_escape(array[0]) when 2 diff --git a/actionview/lib/action_view/helpers/sanitize_helper.rb b/actionview/lib/action_view/helpers/sanitize_helper.rb index f9784c3483..3d6ff598ee 100644 --- a/actionview/lib/action_view/helpers/sanitize_helper.rb +++ b/actionview/lib/action_view/helpers/sanitize_helper.rb @@ -1,5 +1,5 @@ -require 'active_support/core_ext/object/try' -require 'rails-html-sanitizer' +require "active_support/core_ext/object/try" +require "rails-html-sanitizer" module ActionView # = Action View Sanitize Helpers diff --git a/actionview/lib/action_view/helpers/tag_helper.rb b/actionview/lib/action_view/helpers/tag_helper.rb index 4ba37fd5e5..dfa66e11d9 100644 --- a/actionview/lib/action_view/helpers/tag_helper.rb +++ b/actionview/lib/action_view/helpers/tag_helper.rb @@ -1,7 +1,7 @@ # frozen-string-literal: true -require 'active_support/core_ext/string/output_safety' -require 'set' +require "active_support/core_ext/string/output_safety" +require "set" module ActionView # = Action View Tag Helpers @@ -25,7 +25,7 @@ module ActionView BOOLEAN_ATTRIBUTES.merge(BOOLEAN_ATTRIBUTES.map(&:to_sym)) - TAG_PREFIXES = ['aria', 'data', :aria, :data].to_set + TAG_PREFIXES = ["aria", "data", :aria, :data].to_set PRE_CONTENT_STRINGS = Hash.new { "" } PRE_CONTENT_STRINGS[:textarea] = "\n" @@ -46,7 +46,7 @@ module ActionView if VOID_ELEMENTS.include?(name) && content.nil? "<#{name.to_s.dasherize}#{tag_options(options, escape_attributes)}>".html_safe else - content_tag_string(name.to_s.dasherize, content || '', options, escape_attributes) + content_tag_string(name.to_s.dasherize, content || "", options, escape_attributes) end end @@ -290,7 +290,7 @@ module ActionView # cdata_section("hello]]>world") # # => <![CDATA[hello]]]]><![CDATA[>world]]> def cdata_section(content) - splitted = content.to_s.gsub(/\]\]\>/, ']]]]><![CDATA[>') + splitted = content.to_s.gsub(/\]\]\>/, "]]]]><![CDATA[>") "<![CDATA[#{splitted}]]>".html_safe end diff --git a/actionview/lib/action_view/helpers/tags/base.rb b/actionview/lib/action_view/helpers/tags/base.rb index 086eaa4aab..0c4b9570e3 100644 --- a/actionview/lib/action_view/helpers/tags/base.rb +++ b/actionview/lib/action_view/helpers/tags/base.rb @@ -83,7 +83,7 @@ module ActionView options["name"] = options.fetch("name"){ tag_name(options["multiple"], index) } options["id"] = options.fetch("id"){ tag_id(index) } if namespace = options.delete("namespace") - options['id'] = options['id'] ? "#{namespace}_#{options['id']}" : namespace + options["id"] = options["id"] ? "#{namespace}_#{options['id']}" : namespace end end @@ -143,10 +143,10 @@ module ActionView def add_options(option_tags, options, value = nil) if options[:include_blank] - option_tags = tag_builder.content_tag_string('option', options[:include_blank].kind_of?(String) ? options[:include_blank] : nil, :value => '') + "\n" + option_tags + option_tags = tag_builder.content_tag_string("option", options[:include_blank].kind_of?(String) ? options[:include_blank] : nil, :value => "") + "\n" + option_tags end if value.blank? && options[:prompt] - option_tags = tag_builder.content_tag_string('option', prompt_text(options[:prompt]), :value => '') + "\n" + option_tags + option_tags = tag_builder.content_tag_string("option", prompt_text(options[:prompt]), :value => "") + "\n" + option_tags end option_tags end diff --git a/actionview/lib/action_view/helpers/tags/check_box.rb b/actionview/lib/action_view/helpers/tags/check_box.rb index 6d51f2629a..653643d692 100644 --- a/actionview/lib/action_view/helpers/tags/check_box.rb +++ b/actionview/lib/action_view/helpers/tags/check_box.rb @@ -1,4 +1,4 @@ -require 'action_view/helpers/tags/checkable' +require "action_view/helpers/tags/checkable" module ActionView module Helpers diff --git a/actionview/lib/action_view/helpers/tags/collection_check_boxes.rb b/actionview/lib/action_view/helpers/tags/collection_check_boxes.rb index 3dda47a458..59eacbff8b 100644 --- a/actionview/lib/action_view/helpers/tags/collection_check_boxes.rb +++ b/actionview/lib/action_view/helpers/tags/collection_check_boxes.rb @@ -1,4 +1,4 @@ -require 'action_view/helpers/tags/collection_helpers' +require "action_view/helpers/tags/collection_helpers" module ActionView module Helpers diff --git a/actionview/lib/action_view/helpers/tags/collection_helpers.rb b/actionview/lib/action_view/helpers/tags/collection_helpers.rb index fb51460c8e..7607fe64d0 100644 --- a/actionview/lib/action_view/helpers/tags/collection_helpers.rb +++ b/actionview/lib/action_view/helpers/tags/collection_helpers.rb @@ -96,7 +96,7 @@ module ActionView # Prepend a hidden field to make sure something will be sent back to the # server if all radio buttons are unchecked. - if options.fetch('include_hidden', true) + if options.fetch("include_hidden", true) hidden_field + rendered_collection else rendered_collection diff --git a/actionview/lib/action_view/helpers/tags/collection_radio_buttons.rb b/actionview/lib/action_view/helpers/tags/collection_radio_buttons.rb index 21aaf122f8..eed7941cd6 100644 --- a/actionview/lib/action_view/helpers/tags/collection_radio_buttons.rb +++ b/actionview/lib/action_view/helpers/tags/collection_radio_buttons.rb @@ -1,4 +1,4 @@ -require 'action_view/helpers/tags/collection_helpers' +require "action_view/helpers/tags/collection_helpers" module ActionView module Helpers diff --git a/actionview/lib/action_view/helpers/tags/date_select.rb b/actionview/lib/action_view/helpers/tags/date_select.rb index 0c4ac40070..602f393ddb 100644 --- a/actionview/lib/action_view/helpers/tags/date_select.rb +++ b/actionview/lib/action_view/helpers/tags/date_select.rb @@ -1,4 +1,4 @@ -require 'active_support/core_ext/time/calculations' +require "active_support/core_ext/time/calculations" module ActionView module Helpers diff --git a/actionview/lib/action_view/helpers/tags/radio_button.rb b/actionview/lib/action_view/helpers/tags/radio_button.rb index 4849c537a5..1232183dee 100644 --- a/actionview/lib/action_view/helpers/tags/radio_button.rb +++ b/actionview/lib/action_view/helpers/tags/radio_button.rb @@ -1,4 +1,4 @@ -require 'action_view/helpers/tags/checkable' +require "action_view/helpers/tags/checkable" module ActionView module Helpers diff --git a/actionview/lib/action_view/helpers/tags/text_area.rb b/actionview/lib/action_view/helpers/tags/text_area.rb index 69038c1498..31e3a9e9b1 100644 --- a/actionview/lib/action_view/helpers/tags/text_area.rb +++ b/actionview/lib/action_view/helpers/tags/text_area.rb @@ -1,4 +1,4 @@ -require 'action_view/helpers/tags/placeholderable' +require "action_view/helpers/tags/placeholderable" module ActionView module Helpers diff --git a/actionview/lib/action_view/helpers/tags/text_field.rb b/actionview/lib/action_view/helpers/tags/text_field.rb index 5c576a20ca..9201f8d491 100644 --- a/actionview/lib/action_view/helpers/tags/text_field.rb +++ b/actionview/lib/action_view/helpers/tags/text_field.rb @@ -1,4 +1,4 @@ -require 'action_view/helpers/tags/placeholderable' +require "action_view/helpers/tags/placeholderable" module ActionView module Helpers diff --git a/actionview/lib/action_view/helpers/text_helper.rb b/actionview/lib/action_view/helpers/text_helper.rb index fe365fafe1..cb812bd5ba 100644 --- a/actionview/lib/action_view/helpers/text_helper.rb +++ b/actionview/lib/action_view/helpers/text_helper.rb @@ -1,5 +1,5 @@ -require 'active_support/core_ext/string/filters' -require 'active_support/core_ext/array/extract_options' +require "active_support/core_ext/string/filters" +require "active_support/core_ext/array/extract_options" module ActionView # = Action View Text Helpers @@ -135,7 +135,7 @@ module ActionView else match = Array(phrases).map do |p| Regexp === p ? p.to_s : Regexp.escape(p) - end.join('|') + end.join("|") if block_given? text.gsub(/(#{match})(?![^<]*?>)/i) { |found| yield found } @@ -358,7 +358,7 @@ module ActionView # <% end %> def cycle(first_value, *values) options = values.extract_options! - name = options.fetch(:name, 'default') + name = options.fetch(:name, "default") values.unshift(*first_value) diff --git a/actionview/lib/action_view/helpers/translation_helper.rb b/actionview/lib/action_view/helpers/translation_helper.rb index 622bb193ae..cbabaf5757 100644 --- a/actionview/lib/action_view/helpers/translation_helper.rb +++ b/actionview/lib/action_view/helpers/translation_helper.rb @@ -1,7 +1,7 @@ -require 'action_view/helpers/tag_helper' -require 'active_support/core_ext/string/access' -require 'active_support/core_ext/regexp' -require 'i18n/exceptions' +require "action_view/helpers/tag_helper" +require "active_support/core_ext/string/access" +require "active_support/core_ext/regexp" +require "i18n/exceptions" module ActionView # = Action View Translation Helpers @@ -101,12 +101,12 @@ module ActionView interpolations = options.except(:default, :scope) if interpolations.any? - title << ", " << interpolations.map { |k, v| "#{k}: #{ERB::Util.html_escape(v)}" }.join(', ') + title << ", " << interpolations.map { |k, v| "#{k}: #{ERB::Util.html_escape(v)}" }.join(", ") end return title unless ActionView::Base.debug_missing_translation - content_tag('span', keys.last.to_s.titleize, class: 'translation_missing', title: title) + content_tag("span", keys.last.to_s.titleize, class: "translation_missing", title: title) end end alias :t :translate diff --git a/actionview/lib/action_view/helpers/url_helper.rb b/actionview/lib/action_view/helpers/url_helper.rb index 5d7940a7b1..82aeeedad9 100644 --- a/actionview/lib/action_view/helpers/url_helper.rb +++ b/actionview/lib/action_view/helpers/url_helper.rb @@ -1,8 +1,8 @@ -require 'action_view/helpers/javascript_helper' -require 'active_support/core_ext/array/access' -require 'active_support/core_ext/hash/keys' -require 'active_support/core_ext/string/output_safety' -require 'active_support/core_ext/regexp' +require "action_view/helpers/javascript_helper" +require "active_support/core_ext/array/access" +require "active_support/core_ext/hash/keys" +require "active_support/core_ext/string/output_safety" +require "active_support/core_ext/regexp" module ActionView # = Action View URL Helpers @@ -42,14 +42,14 @@ module ActionView end def _back_url # :nodoc: - _filtered_referrer || 'javascript:history.back()' + _filtered_referrer || "javascript:history.back()" end protected :_back_url def _filtered_referrer # :nodoc: if controller.respond_to?(:request) referrer = controller.request.env["HTTP_REFERER"] - if referrer && URI(referrer).scheme != 'javascript' + if referrer && URI(referrer).scheme != "javascript" referrer end end @@ -299,34 +299,34 @@ module ActionView html_options = html_options.stringify_keys url = options.is_a?(String) ? options : url_for(options) - remote = html_options.delete('remote') - params = html_options.delete('params') + remote = html_options.delete("remote") + params = html_options.delete("params") - method = html_options.delete('method').to_s - method_tag = BUTTON_TAG_METHOD_VERBS.include?(method) ? method_tag(method) : ''.freeze.html_safe + method = html_options.delete("method").to_s + method_tag = BUTTON_TAG_METHOD_VERBS.include?(method) ? method_tag(method) : "".freeze.html_safe - form_method = method == 'get' ? 'get' : 'post' - form_options = html_options.delete('form') || {} - form_options[:class] ||= html_options.delete('form_class') || 'button_to' + form_method = method == "get" ? "get" : "post" + form_options = html_options.delete("form") || {} + form_options[:class] ||= html_options.delete("form_class") || "button_to" form_options[:method] = form_method form_options[:action] = url form_options[:'data-remote'] = true if remote - request_token_tag = if form_method == 'post' - request_method = method.empty? ? 'post' : method + request_token_tag = if form_method == "post" + request_method = method.empty? ? "post" : method token_tag(nil, form_options: { action: url, method: request_method }) else - ''.freeze + "".freeze end html_options = convert_options_to_data_attributes(options, html_options) - html_options['type'] = 'submit' + html_options["type"] = "submit" button = if block_given? - content_tag('button', html_options, &block) + content_tag("button", html_options, &block) else - html_options['value'] = name || url - tag('input', html_options) + html_options["value"] = name || url + tag("input", html_options) end inner_tags = method_tag.safe_concat(button).safe_concat(request_token_tag) @@ -335,7 +335,7 @@ module ActionView inner_tags.safe_concat tag(:input, type: "hidden", name: param[:name], value: param[:value]) end end - content_tag('form', inner_tags, form_options) + content_tag("form", inner_tags, form_options) end # Creates a link tag of the given +name+ using a URL created by the set of @@ -482,7 +482,7 @@ module ActionView option = html_options.delete(item).presence || next "#{item.dasherize}=#{ERB::Util.url_encode(option)}" }.compact - extras = extras.empty? ? ''.freeze : '?' + extras.join('&') + extras = extras.empty? ? "".freeze : "?" + extras.join("&") encoded_email_address = ERB::Util.url_encode(email_address).gsub("%40", "@") html_options["href"] = "mailto:#{encoded_email_address}#{extras}" @@ -562,21 +562,21 @@ module ActionView def convert_options_to_data_attributes(options, html_options) if html_options html_options = html_options.stringify_keys - html_options['data-remote'] = 'true'.freeze if link_to_remote_options?(options) || link_to_remote_options?(html_options) + html_options["data-remote"] = "true".freeze if link_to_remote_options?(options) || link_to_remote_options?(html_options) - method = html_options.delete('method'.freeze) + method = html_options.delete("method".freeze) add_method_to_attributes!(html_options, method) if method html_options else - link_to_remote_options?(options) ? {'data-remote' => 'true'.freeze} : {} + link_to_remote_options?(options) ? {"data-remote" => "true".freeze} : {} end end def link_to_remote_options?(options) if options.is_a?(Hash) - options.delete('remote'.freeze) || options.delete(:remote) + options.delete("remote".freeze) || options.delete(:remote) end end @@ -592,12 +592,12 @@ module ActionView token ||= form_authenticity_token(form_options: form_options) tag(:input, type: "hidden", name: request_forgery_protection_token.to_s, value: token) else - ''.freeze + "".freeze end end def method_tag(method) - tag('input', type: 'hidden', name: '_method', value: method.to_s) + tag("input", type: "hidden", name: "_method", value: method.to_s) end # Returns an array of hashes each containing :name and :value keys |