提交 667d0bdd 编写于 作者: J José Valim

Merge pull request #6142 from spartan-developer/master

refactored extracting :size => 'XxY' into an extract_size! method
......@@ -393,9 +393,7 @@ def image_tag(source, options={})
options[:alt] = options.fetch(:alt){ image_alt(src) }
end
if size = options.delete(:size)
options[:width], options[:height] = size.split("x") if size =~ %r{^\d+x\d+$}
end
extract_size!(options, :width, :height)
if mouseover = options.delete(:mouseover)
options[:onmouseover] = "this.src='#{path_to_image(mouseover)}'"
......@@ -448,9 +446,7 @@ def video_tag(*sources)
multiple_sources_tag('video', sources) do |options|
options[:poster] = path_to_image(options[:poster]) if options[:poster]
if size = options.delete(:size)
options[:width], options[:height] = size.split("x") if size =~ %r{^\d+x\d+$}
end
extract_size!(options, :width, :height)
end
end
......
......@@ -317,9 +317,7 @@ def password_field_tag(name = "password", value = nil, options = {})
def text_area_tag(name, content = nil, options = {})
options = options.stringify_keys
if size = options.delete("size")
options["cols"], options["rows"] = size.split("x") if size.respond_to?(:split)
end
extract_size!(options, 'cols', 'rows')
escape = options.delete("escape") { true }
content = ERB::Util.html_escape(content) if escape
......
......@@ -137,6 +137,12 @@ def content_tag_string(name, content, options, escape = true)
"<#{name}#{tag_options}>#{PRE_CONTENT_STRINGS[name.to_sym]}#{content}</#{name}>".html_safe
end
def extract_size!(options, x_attribute, y_attribute)
if size = options.delete(:size)
options[x_attribute], options[y_attribute] = size.split("x") if size =~ %r{^\d+x\d+$}
end
end
def tag_options(options, escape = true)
return if options.blank?
attrs = []
......
......@@ -6,9 +6,7 @@ def render
options = @options.stringify_keys
add_default_name_and_id(options)
if size = options.delete("size")
options["cols"], options["rows"] = size.split("x") if size.respond_to?(:split)
end
extract_size!(options, 'cols', 'rows')
content_tag("textarea", options.delete('value') || value_before_type_cast(object), options)
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册