From 21f0c580f3fddc56e0e7313780ee5dd95f3edb11 Mon Sep 17 00:00:00 2001 From: abhishek Date: Wed, 18 Dec 2013 16:17:11 +0530 Subject: duplication removed(DRY) --- .../lib/action_view/helpers/asset_tag_helper.rb | 26 +++++++++------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/actionview/lib/action_view/helpers/asset_tag_helper.rb b/actionview/lib/action_view/helpers/asset_tag_helper.rb index bc5007b11d..ea1aadcc43 100644 --- a/actionview/lib/action_view/helpers/asset_tag_helper.rb +++ b/actionview/lib/action_view/helpers/asset_tag_helper.rb @@ -207,14 +207,7 @@ module ActionView options[:alt] = options.fetch(:alt){ image_alt(src) } end - if size = options.delete(:size) - if size =~ %r{\A\d+x\d+\z} - options[:width], options[:height] = size.split('x') - elsif size =~ %r{\A\d+\z} - options[:width] = options[:height] = size - end - end - + options[:width], options[:height] = extract_dimensions(options.delete(:size)) if options[:size] tag("img", options) end @@ -280,14 +273,7 @@ module ActionView 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) - if size =~ %r{\A\d+x\d+\z} - options[:width], options[:height] = size.split('x') - elsif size =~ %r{\A\d+\z} - options[:width] = options[:height] = size - end - end + options[:width], options[:height] = extract_dimensions(options.delete(:size)) if options[:size] end end @@ -323,6 +309,14 @@ module ActionView content_tag(type, nil, options) end end + + def extract_dimensions(size) + if size =~ %r{\A\d+x\d+\z} + size.split('x') + elsif size =~ %r{\A\d+\z} + [size, size] + end + end end end end -- cgit v1.2.3