@@ -52,7 +52,7 @@ def self.define_element(name, code_generator:, method_name: name.to_s.underscore
52
52
code_generator . define_cached_method ( method_name , namespace : :tag_builder ) do |batch |
53
53
batch . push ( <<~RUBY ) unless instance_methods . include? ( method_name . to_sym )
54
54
def #{ method_name } (content = nil, escape: true, **options, &block)
55
- tag_string(#{ name . inspect } , content, escape: escape, **options , &block)
55
+ tag_string(" #{ name } " , content, options, escape: escape, &block)
56
56
end
57
57
RUBY
58
58
end
@@ -70,7 +70,7 @@ def #{method_name}(content = nil, escape: true, **options, &block)
70
70
positional argument will raise, and using a block will have
71
71
no effect.
72
72
TEXT
73
- tag_string("#{ name } ", content, escape: escape, **options , &block)
73
+ tag_string("#{ name } ", content, options, escape: escape, &block)
74
74
else
75
75
self_closing_tag_string("#{ name } ", options, escape, ">")
76
76
end
@@ -84,7 +84,7 @@ def self.define_self_closing_element(name, code_generator:, method_name: name.to
84
84
batch . push ( <<~RUBY )
85
85
def #{ method_name } (content = nil, escape: true, **options, &block)
86
86
if content || block
87
- tag_string("#{ name } ", content, escape: escape, **options , &block)
87
+ tag_string("#{ name } ", content, options, escape: escape, &block)
88
88
else
89
89
self_closing_tag_string("#{ name } ", options, escape)
90
90
end
@@ -239,7 +239,7 @@ def attributes(attributes)
239
239
tag_options ( attributes . to_h ) . to_s . strip . html_safe
240
240
end
241
241
242
- def tag_string ( name , content = nil , escape : true , ** options , &block )
242
+ def tag_string ( name , content = nil , options , escape : true , &block )
243
243
content = @view_context . capture ( self , &block ) if block
244
244
245
245
content_tag_string ( name , content , options , escape )
@@ -252,7 +252,7 @@ def self_closing_tag_string(name, options, escape = true, tag_suffix = " />")
252
252
def content_tag_string ( name , content , options , escape = true )
253
253
tag_options = tag_options ( options , escape ) if options
254
254
255
- if escape
255
+ if escape && content . present?
256
256
content = ERB ::Util . unwrapped_html_escape ( content )
257
257
end
258
258
"<#{ name } #{ tag_options } >#{ PRE_CONTENT_STRINGS [ name ] } #{ content } </#{ name } >" . html_safe
@@ -334,12 +334,12 @@ def respond_to_missing?(*args)
334
334
true
335
335
end
336
336
337
- def method_missing ( called , ... )
337
+ def method_missing ( called , * args , escape : true , ** options , & block )
338
338
name = called . name . dasherize
339
339
340
340
TagHelper . ensure_valid_html5_tag_name ( name )
341
341
342
- tag_string ( name , ... )
342
+ tag_string ( name , * args , options , escape : escape , & block )
343
343
end
344
344
end
345
345
0 commit comments