Files
nairobi/app/helpers/embed_videos_helper.rb
2016-04-19 00:08:12 +02:00

30 lines
726 B
Ruby

module EmbedVideosHelper
def embedded_video_code
link = @proposal.video_url
if link.match(/vimeo.*/)
server = "Vimeo"
elsif link.match(/youtu*.*/)
server = "YouTube"
end
if server == "Vimeo"
regExp = /vimeo.*(staffpicks\/|channels\/|videos\/|video\/|\/)([^#\&\?]*).*/
src = "https://player.vimeo.com/video/"
elsif server == "YouTube"
regExp = /youtu.*(be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/
src = "https://www.youtube.com/embed/"
end
if regExp
match = link.match(regExp)
end
if match and match[2]
'<iframe src="' + src + match[2] + '" frameborder="0" allowfullscreen></iframe>'
else
''
end
end
end