diff options
author | Yves Senn <yves.senn@gmail.com> | 2013-12-18 03:02:24 -0800 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2013-12-18 03:02:24 -0800 |
commit | 06dc51a6c07b79c069fc975622c50ac7181ae845 (patch) | |
tree | 8a7f70c08a8648a80bb62dc6dc6a3de58e06ae4e | |
parent | aaea0d8813a621da6d849a2b53dddba14593e630 (diff) | |
parent | 21f0c580f3fddc56e0e7313780ee5dd95f3edb11 (diff) | |
download | rails-06dc51a6c07b79c069fc975622c50ac7181ae845.tar.gz rails-06dc51a6c07b79c069fc975622c50ac7181ae845.tar.bz2 rails-06dc51a6c07b79c069fc975622c50ac7181ae845.zip |
Merge pull request #13370 from abhishekjain16/refactor_rails
duplication removed(DRY)
-rw-r--r-- | actionview/lib/action_view/helpers/asset_tag_helper.rb | 26 |
1 files 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 |