diff options
Diffstat (limited to 'actionview/lib/action_view')
-rw-r--r-- | actionview/lib/action_view/helpers/csrf_helper.rb | 2 | ||||
-rw-r--r-- | actionview/lib/action_view/helpers/form_helper.rb | 221 | ||||
-rw-r--r-- | actionview/lib/action_view/helpers/text_helper.rb | 2 | ||||
-rw-r--r-- | actionview/lib/action_view/helpers/url_helper.rb | 2 | ||||
-rw-r--r-- | actionview/lib/action_view/lookup_context.rb | 2 | ||||
-rw-r--r-- | actionview/lib/action_view/rendering.rb | 9 | ||||
-rw-r--r-- | actionview/lib/action_view/template/handlers/erb.rb | 4 | ||||
-rw-r--r-- | actionview/lib/action_view/template/resolver.rb | 2 |
8 files changed, 233 insertions, 11 deletions
diff --git a/actionview/lib/action_view/helpers/csrf_helper.rb b/actionview/lib/action_view/helpers/csrf_helper.rb index 69c59844a6..c0422c6ff5 100644 --- a/actionview/lib/action_view/helpers/csrf_helper.rb +++ b/actionview/lib/action_view/helpers/csrf_helper.rb @@ -20,7 +20,7 @@ module ActionView # "X-CSRF-Token" HTTP header. If you are using rails-ujs this happens automatically. # def csrf_meta_tags - if protect_against_forgery? + if defined?(protect_against_forgery?) && protect_against_forgery? [ tag("meta", name: "csrf-param", content: request_forgery_protection_token), tag("meta", name: "csrf-token", content: form_authenticity_token) diff --git a/actionview/lib/action_view/helpers/form_helper.rb b/actionview/lib/action_view/helpers/form_helper.rb index c2caa77afb..c5a736bfb4 100644 --- a/actionview/lib/action_view/helpers/form_helper.rb +++ b/actionview/lib/action_view/helpers/form_helper.rb @@ -1680,6 +1680,227 @@ module ActionView @index = options[:index] || options[:child_index] end + ## + # :method: text_field + # + # :call-seq: text_field(method, options = {}) + # + # Wraps ActionView::Helpers::FormHelper#text_field for form builders: + # + # <%= form_with model: @user do |f| %> + # <%= f.text_field :name %> + # <% end %> + # + # Please refer to the documentation of the base helper for details. + + ## + # :method: password_field + # + # :call-seq: password_field(method, options = {}) + # + # Wraps ActionView::Helpers::FormHelper#password_field for form builders: + # + # <%= form_with model: @user do |f| %> + # <%= f.password_field :password %> + # <% end %> + # + # Please refer to the documentation of the base helper for details. + + ## + # :method: text_area + # + # :call-seq: text_area(method, options = {}) + # + # Wraps ActionView::Helpers::FormHelper#text_area for form builders: + # + # <%= form_with model: @user do |f| %> + # <%= f.text_area :detail %> + # <% end %> + # + # Please refer to the documentation of the base helper for details. + + ## + # :method: color_field + # + # :call-seq: color_field(method, options = {}) + # + # Wraps ActionView::Helpers::FormHelper#color_field for form builders: + # + # <%= form_with model: @user do |f| %> + # <%= f.color_field :favorite_color %> + # <% end %> + # + # Please refer to the documentation of the base helper for details. + + ## + # :method: search_field + # + # :call-seq: search_field(method, options = {}) + # + # Wraps ActionView::Helpers::FormHelper#search_field for form builders: + # + # <%= form_with model: @user do |f| %> + # <%= f.search_field :name %> + # <% end %> + # + # Please refer to the documentation of the base helper for details. + + ## + # :method: telephone_field + # + # :call-seq: telephone_field(method, options = {}) + # + # Wraps ActionView::Helpers::FormHelper#telephone_field for form builders: + # + # <%= form_with model: @user do |f| %> + # <%= f.telephone_field :phone %> + # <% end %> + # + # Please refer to the documentation of the base helper for details. + + ## + # :method: phone_field + # + # :call-seq: phone_field(method, options = {}) + # + # Wraps ActionView::Helpers::FormHelper#phone_field for form builders: + # + # <%= form_with model: @user do |f| %> + # <%= f.phone_field :phone %> + # <% end %> + # + # Please refer to the documentation of the base helper for details. + + ## + # :method: date_field + # + # :call-seq: date_field(method, options = {}) + # + # Wraps ActionView::Helpers::FormHelper#date_field for form builders: + # + # <%= form_with model: @user do |f| %> + # <%= f.date_field :born_on %> + # <% end %> + # + # Please refer to the documentation of the base helper for details. + + ## + # :method: time_field + # + # :call-seq: time_field(method, options = {}) + # + # Wraps ActionView::Helpers::FormHelper#time_field for form builders: + # + # <%= form_with model: @user do |f| %> + # <%= f.time_field :borned_at %> + # <% end %> + # + # Please refer to the documentation of the base helper for details. + + ## + # :method: datetime_field + # + # :call-seq: datetime_field(method, options = {}) + # + # Wraps ActionView::Helpers::FormHelper#datetime_field for form builders: + # + # <%= form_with model: @user do |f| %> + # <%= f.datetime_field :graduation_day %> + # <% end %> + # + # Please refer to the documentation of the base helper for details. + + ## + # :method: datetime_local_field + # + # :call-seq: datetime_local_field(method, options = {}) + # + # Wraps ActionView::Helpers::FormHelper#datetime_local_field for form builders: + # + # <%= form_with model: @user do |f| %> + # <%= f.datetime_local_field :graduation_day %> + # <% end %> + # + # Please refer to the documentation of the base helper for details. + + ## + # :method: month_field + # + # :call-seq: month_field(method, options = {}) + # + # Wraps ActionView::Helpers::FormHelper#month_field for form builders: + # + # <%= form_with model: @user do |f| %> + # <%= f.month_field :birthday_month %> + # <% end %> + # + # Please refer to the documentation of the base helper for details. + + ## + # :method: week_field + # + # :call-seq: week_field(method, options = {}) + # + # Wraps ActionView::Helpers::FormHelper#week_field for form builders: + # + # <%= form_with model: @user do |f| %> + # <%= f.week_field :birthday_week %> + # <% end %> + # + # Please refer to the documentation of the base helper for details. + + ## + # :method: url_field + # + # :call-seq: url_field(method, options = {}) + # + # Wraps ActionView::Helpers::FormHelper#url_field for form builders: + # + # <%= form_with model: @user do |f| %> + # <%= f.url_field :homepage %> + # <% end %> + # + # Please refer to the documentation of the base helper for details. + + ## + # :method: email_field + # + # :call-seq: email_field(method, options = {}) + # + # Wraps ActionView::Helpers::FormHelper#email_field for form builders: + # + # <%= form_with model: @user do |f| %> + # <%= f.email_field :address %> + # <% end %> + # + # Please refer to the documentation of the base helper for details. + + ## + # :method: number_field + # + # :call-seq: number_field(method, options = {}) + # + # Wraps ActionView::Helpers::FormHelper#number_field for form builders: + # + # <%= form_with model: @user do |f| %> + # <%= f.number_field :age %> + # <% end %> + # + # Please refer to the documentation of the base helper for details. + + ## + # :method: range_field + # + # :call-seq: range_field(method, options = {}) + # + # Wraps ActionView::Helpers::FormHelper#range_field for form builders: + # + # <%= form_with model: @user do |f| %> + # <%= f.range_field :age %> + # <% end %> + # + # Please refer to the documentation of the base helper for details. + (field_helpers - [:label, :check_box, :radio_button, :fields_for, :fields, :hidden_field, :file_field]).each do |selector| class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1 def #{selector}(method, options = {}) # def text_field(method, options = {}) diff --git a/actionview/lib/action_view/helpers/text_helper.rb b/actionview/lib/action_view/helpers/text_helper.rb index 3d378dcb2f..c282505e13 100644 --- a/actionview/lib/action_view/helpers/text_helper.rb +++ b/actionview/lib/action_view/helpers/text_helper.rb @@ -228,7 +228,7 @@ module ActionView # pluralize(2, 'Person', locale: :de) # # => 2 Personen def pluralize(count, singular, plural_arg = nil, plural: plural_arg, locale: I18n.locale) - word = if count == 1 || count =~ /^1(\.0+)?$/ + word = if count == 1 || count.to_s =~ /^1(\.0+)?$/ singular else plural || singular.pluralize(locale) diff --git a/actionview/lib/action_view/helpers/url_helper.rb b/actionview/lib/action_view/helpers/url_helper.rb index 948dd1551f..d63ada3890 100644 --- a/actionview/lib/action_view/helpers/url_helper.rb +++ b/actionview/lib/action_view/helpers/url_helper.rb @@ -618,7 +618,7 @@ module ActionView end def token_tag(token = nil, form_options: {}) - if token != false && protect_against_forgery? + if token != false && defined?(protect_against_forgery?) && protect_against_forgery? token ||= form_authenticity_token(form_options: form_options) tag(:input, type: "hidden", name: request_forgery_protection_token.to_s, value: token) else diff --git a/actionview/lib/action_view/lookup_context.rb b/actionview/lib/action_view/lookup_context.rb index af67ffa12d..554d223c0e 100644 --- a/actionview/lib/action_view/lookup_context.rb +++ b/actionview/lib/action_view/lookup_context.rb @@ -24,7 +24,7 @@ module ActionView registered_details << name Accessors::DEFAULT_PROCS[name] = block - Accessors.send :define_method, :"default_#{name}", &block + Accessors.define_method(:"default_#{name}", &block) Accessors.module_eval <<-METHOD, __FILE__, __LINE__ + 1 def #{name} @details.fetch(:#{name}, []) diff --git a/actionview/lib/action_view/rendering.rb b/actionview/lib/action_view/rendering.rb index 4e5fdfbb2d..cb4327cf16 100644 --- a/actionview/lib/action_view/rendering.rb +++ b/actionview/lib/action_view/rendering.rb @@ -64,10 +64,11 @@ module ActionView # An instance of a view class. The default view class is ActionView::Base. # # The view class must have the following methods: - # View.new[lookup_context, assigns, controller] - # Create a new ActionView instance for a controller and we can also pass the arguments. - # View#render(option) - # Returns String with the rendered template + # + # * <tt>View.new(lookup_context, assigns, controller)</tt> — Create a new + # ActionView instance for a controller and we can also pass the arguments. + # + # * <tt>View#render(option)</tt> — Returns String with the rendered template. # # Override this method in a module to change the default behavior. def view_context diff --git a/actionview/lib/action_view/template/handlers/erb.rb b/actionview/lib/action_view/template/handlers/erb.rb index 270be0a380..7d1a6767d7 100644 --- a/actionview/lib/action_view/template/handlers/erb.rb +++ b/actionview/lib/action_view/template/handlers/erb.rb @@ -17,8 +17,8 @@ module ActionView class_attribute :escape_ignore_list, default: ["text/plain"] [self, singleton_class].each do |base| - base.send(:alias_method, :escape_whitelist, :escape_ignore_list) - base.send(:alias_method, :escape_whitelist=, :escape_ignore_list=) + base.alias_method :escape_whitelist, :escape_ignore_list + base.alias_method :escape_whitelist=, :escape_ignore_list= base.deprecate( escape_whitelist: "use #escape_ignore_list instead", diff --git a/actionview/lib/action_view/template/resolver.rb b/actionview/lib/action_view/template/resolver.rb index 08dd6fb510..12ae82f8c5 100644 --- a/actionview/lib/action_view/template/resolver.rb +++ b/actionview/lib/action_view/template/resolver.rb @@ -378,7 +378,7 @@ module ActionView # This regex match does double duty of finding only files which match # details (instead of just matching the prefix) and also filtering for # case-insensitive file systems. - !filename.match(regex) || + !regex.match?(filename) || File.directory?(filename) end.sort_by do |filename| # Because we scanned the directory, instead of checking for files |