diff --git a/actionview/lib/action_view/helpers/tag_helper.rb b/actionview/lib/action_view/helpers/tag_helper.rb index 867b7b2708c33..b30ca4d7bb4b3 100644 --- a/actionview/lib/action_view/helpers/tag_helper.rb +++ b/actionview/lib/action_view/helpers/tag_helper.rb @@ -52,7 +52,7 @@ def self.define_element(name, code_generator:, method_name: name.to_s.underscore code_generator.define_cached_method(method_name, namespace: :tag_builder) do |batch| batch.push(<<~RUBY) unless instance_methods.include?(method_name.to_sym) def #{method_name}(content = nil, escape: true, **options, &block) - tag_string(#{name.inspect}, content, escape: escape, **options, &block) + tag_string("#{name}", content, options, escape: escape, &block) end RUBY end @@ -70,7 +70,7 @@ def #{method_name}(content = nil, escape: true, **options, &block) positional argument will raise, and using a block will have no effect. TEXT - tag_string("#{name}", content, escape: escape, **options, &block) + tag_string("#{name}", content, options, escape: escape, &block) else self_closing_tag_string("#{name}", options, escape, ">") end @@ -84,7 +84,7 @@ def self.define_self_closing_element(name, code_generator:, method_name: name.to batch.push(<<~RUBY) def #{method_name}(content = nil, escape: true, **options, &block) if content || block - tag_string("#{name}", content, escape: escape, **options, &block) + tag_string("#{name}", content, options, escape: escape, &block) else self_closing_tag_string("#{name}", options, escape) end @@ -239,7 +239,7 @@ def attributes(attributes) tag_options(attributes.to_h).to_s.strip.html_safe end - def tag_string(name, content = nil, escape: true, **options, &block) + def tag_string(name, content = nil, options, escape: true, &block) content = @view_context.capture(self, &block) if block content_tag_string(name, content, options, escape) @@ -252,7 +252,7 @@ def self_closing_tag_string(name, options, escape = true, tag_suffix = " />") def content_tag_string(name, content, options, escape = true) tag_options = tag_options(options, escape) if options - if escape + if escape && content.present? content = ERB::Util.unwrapped_html_escape(content) end "<#{name}#{tag_options}>#{PRE_CONTENT_STRINGS[name]}#{content}".html_safe @@ -334,12 +334,12 @@ def respond_to_missing?(*args) true end - def method_missing(called, ...) + def method_missing(called, *args, escape: true, **options, &block) name = called.name.dasherize TagHelper.ensure_valid_html5_tag_name(name) - tag_string(name, ...) + tag_string(name, *args, options, escape: escape, &block) end end diff --git a/actionview/test/template/tag_helper_test.rb b/actionview/test/template/tag_helper_test.rb index 76ccf26394115..764fd9b97688d 100644 --- a/actionview/test/template/tag_helper_test.rb +++ b/actionview/test/template/tag_helper_test.rb @@ -45,7 +45,7 @@ def test_tag_builder_self_closing_tag end def test_tag_builder_self_closing_tag_with_content - assert_equal "A circle", tag.svg { tag.circle { tag.desc "A circle" } } + assert_equal "A circle", tag.svg { tag.circle(r: "5") { tag.desc "A circle" } } end def test_tag_builder_defines_methods_to_build_html_elements