Guest User

Untitled

a guest
Mar 9th, 2015
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.52 KB | None | 0 0
  1. def string_to_src(url)
  2.     if url[/(?:png|jpe?g|gif|svg)$/]
  3.       "<img src='#{url}' / class='link-image thumbnail'>".html_safe
  4.     elsif url[/^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/ix]
  5.       "<a href='#{url}' target='_blank'>#{url}</a>".html_safe
  6.     elsif url[/^(?:https?:\/\/)?(?:www\.)?youtu(?:\.be|be\.com)\/(?:watch\?v=)?([\w-]{10,})/]
  7.      # "<iframe width='420' height='315' src='#{url}' frameborder='0' allowfullscreen></iframe>".html_safe
  8.     else
  9.       url
  10.     end
  11.   end
Advertisement
Add Comment
Please, Sign In to add comment