Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

duplication removed(DRY)

  • Loading branch information...
commit 21f0c580f3fddc56e0e7313780ee5dd95f3edb11 1 parent 2c9cb49
@abhishekjain16 abhishekjain16 authored
Showing with 10 additions and 16 deletions.
  1. +10 −16 actionview/lib/action_view/helpers/asset_tag_helper.rb
View
26 actionview/lib/action_view/helpers/asset_tag_helper.rb
@@ -207,14 +207,7 @@ def image_tag(source, options={})
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 @@ def image_alt(src)
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 @@ def multiple_sources_tag(type, sources)
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
Please sign in to comment.
Something went wrong with that request. Please try again.