提交 57863957 编写于 作者: R rizwanreza 提交者: Pratik Naik

Allow content_tag options to take an array [#1741 state:resolved] [rizwanreza, Nick Quaranto]

Example:
  content_tag('p', "limelight", :class => ["song", "play"])
  # => <p class="song play">limelight</p>
Signed-off-by: NPratik Naik <pratiknaik@gmail.com>
上级 761283ff
......@@ -134,16 +134,14 @@ def content_tag_string(name, content, options, escape = true)
def tag_options(options, escape = true)
unless options.blank?
attrs = []
if escape
options.each_pair do |key, value|
if BOOLEAN_ATTRIBUTES.include?(key)
attrs << %(#{key}="#{key}") if value
else
attrs << %(#{key}="#{escape_once(value)}") if !value.nil?
end
options.each_pair do |key, value|
if BOOLEAN_ATTRIBUTES.include?(key)
attrs << %(#{key}="#{key}") if value
elsif !value.nil?
final_value = value.is_a?(Array) ? value.join(" ") : value
final_value = escape_once(final_value) if escape
attrs << %(#{key}="#{final_value}")
end
else
attrs = options.map { |key, value| %(#{key}="#{value}") }
end
" #{attrs.sort * ' '}" unless attrs.empty?
end
......
......@@ -71,6 +71,19 @@ def test_content_tag_nested_in_content_tag_in_erb
assert_equal '<p><b>Hello</b></p>', output_buffer
end
def test_content_tag_with_escaped_array_class
str = content_tag('p', "limelight", :class => ["song", "play>"])
assert_equal "<p class=\"song play&gt;\">limelight</p>", str
str = content_tag('p', "limelight", :class => ["song", "play"])
assert_equal "<p class=\"song play\">limelight</p>", str
end
def test_content_tag_with_unescaped_array_class
str = content_tag('p', "limelight", {:class => ["song", "play>"]}, false)
assert_equal "<p class=\"song play>\">limelight</p>", str
end
def test_cdata_section
assert_equal "<![CDATA[<hello world>]]>", cdata_section("<hello world>")
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册