@@ -44,9 +44,6 @@ module TagHelper
44
44
PRE_CONTENT_STRINGS [ "textarea" ] = "\n "
45
45
46
46
class TagBuilder # :nodoc:
47
- include CaptureHelper
48
- include OutputSafetyHelper
49
-
50
47
def self . define_element ( name , code_generator :, method_name : name )
51
48
return if method_defined? ( name )
52
49
@@ -226,17 +223,7 @@ def attributes(attributes)
226
223
tag_options ( attributes . to_h ) . to_s . strip . html_safe
227
224
end
228
225
229
- def tag_string ( name , content = nil , options , escape : true , &block )
230
- content = @view_context . capture ( self , &block ) if block
231
-
232
- content_tag_string ( name , content , options , escape )
233
- end
234
-
235
- def self_closing_tag_string ( name , options , escape = true , tag_suffix = " />" )
236
- "<#{ name } #{ tag_options ( options , escape ) } #{ tag_suffix } " . html_safe
237
- end
238
-
239
- def content_tag_string ( name , content , options , escape = true )
226
+ def content_tag_string ( name , content , options , escape = true ) # :nodoc:
240
227
tag_options = tag_options ( options , escape ) if options
241
228
242
229
if escape && content . present?
@@ -245,7 +232,7 @@ def content_tag_string(name, content, options, escape = true)
245
232
"<#{ name } #{ tag_options } >#{ PRE_CONTENT_STRINGS [ name ] } #{ content } </#{ name } >" . html_safe
246
233
end
247
234
248
- def tag_options ( options , escape = true )
235
+ def tag_options ( options , escape = true ) # :nodoc:
249
236
return if options . blank?
250
237
output = +""
251
238
sep = " "
@@ -266,7 +253,7 @@ def tag_options(options, escape = true)
266
253
tokens = TagHelper . build_tag_values ( v )
267
254
next if tokens . none?
268
255
269
- v = safe_join ( tokens , " " )
256
+ v = @view_context . safe_join ( tokens , " " )
270
257
else
271
258
v = v . to_s
272
259
end
@@ -287,28 +274,38 @@ def tag_options(options, escape = true)
287
274
output unless output . empty?
288
275
end
289
276
290
- def boolean_tag_option ( key )
291
- %( #{ key } =" #{ key } " )
292
- end
277
+ private
278
+ def tag_string ( name , content = nil , options , escape : true , & block )
279
+ content = @view_context . capture ( self , & block ) if block
293
280
294
- def tag_option ( key , value , escape )
295
- key = ERB ::Util . xml_name_escape ( key ) if escape
296
-
297
- case value
298
- when Array , Hash
299
- value = TagHelper . build_tag_values ( value ) if key . to_s == "class"
300
- value = escape ? safe_join ( value , " " ) : value . join ( " " )
301
- when Regexp
302
- value = escape ? ERB ::Util . unwrapped_html_escape ( value . source ) : value . source
303
- else
304
- value = escape ? ERB ::Util . unwrapped_html_escape ( value ) : value . to_s
281
+ content_tag_string ( name , content , options , escape )
305
282
end
306
- value = value . gsub ( '"' , """ ) if value . include? ( '"' )
307
283
308
- %(#{ key } ="#{ value } ")
309
- end
284
+ def self_closing_tag_string ( name , options , escape = true , tag_suffix = " />" )
285
+ "<#{ name } #{ tag_options ( options , escape ) } #{ tag_suffix } " . html_safe
286
+ end
287
+
288
+ def boolean_tag_option ( key )
289
+ %(#{ key } ="#{ key } ")
290
+ end
291
+
292
+ def tag_option ( key , value , escape )
293
+ key = ERB ::Util . xml_name_escape ( key ) if escape
294
+
295
+ case value
296
+ when Array , Hash
297
+ value = TagHelper . build_tag_values ( value ) if key . to_s == "class"
298
+ value = escape ? @view_context . safe_join ( value , " " ) : value . join ( " " )
299
+ when Regexp
300
+ value = escape ? ERB ::Util . unwrapped_html_escape ( value . source ) : value . source
301
+ else
302
+ value = escape ? ERB ::Util . unwrapped_html_escape ( value ) : value . to_s
303
+ end
304
+ value = value . gsub ( '"' , """ ) if value . include? ( '"' )
305
+
306
+ %(#{ key } ="#{ value } ")
307
+ end
310
308
311
- private
312
309
def prefix_tag_option ( prefix , key , value , escape )
313
310
key = "#{ prefix } -#{ key . to_s . dasherize } "
314
311
unless value . is_a? ( String ) || value . is_a? ( Symbol ) || value . is_a? ( BigDecimal )
0 commit comments