video_embed 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/video_embed/version.rb +1 -1
- data/lib/video_embed/vimeo.rb +1 -1
- data/lib/video_embed/youtube.rb +11 -3
- data/spec/video_embed_spec.rb +10 -0
- metadata +1 -1
data/lib/video_embed/version.rb
CHANGED
data/lib/video_embed/vimeo.rb
CHANGED
data/lib/video_embed/youtube.rb
CHANGED
@@ -3,7 +3,7 @@ require 'cgi'
|
|
3
3
|
class VideoEmbed
|
4
4
|
class YouTube
|
5
5
|
def url?(url)
|
6
|
-
url.host =~ /youtube\.com/
|
6
|
+
url.host =~ /(:?youtube\.com|youtu.be)/
|
7
7
|
end
|
8
8
|
|
9
9
|
def embed(url, options = {})
|
@@ -27,8 +27,16 @@ class VideoEmbed
|
|
27
27
|
private
|
28
28
|
|
29
29
|
def video_id
|
30
|
-
|
31
|
-
|
30
|
+
if short_url?
|
31
|
+
url.path.match(/\/(.*)\??/)[1]
|
32
|
+
else
|
33
|
+
params = CGI.parse(url.query)
|
34
|
+
params['v'].first
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def short_url?
|
39
|
+
url.host == 'youtu.be'
|
32
40
|
end
|
33
41
|
end
|
34
42
|
end
|
data/spec/video_embed_spec.rb
CHANGED
@@ -7,6 +7,11 @@ describe VideoEmbed do
|
|
7
7
|
video_embed.should eql(%Q{<iframe width="560" height="315" src="http://www.youtube.com/embed/4Z3r9X8OahA?rel=0" frameborder="0" allowfullscreen></iframe>})
|
8
8
|
end
|
9
9
|
|
10
|
+
it 'returns embed html from a short url' do
|
11
|
+
video_embed = VideoEmbed.embed('http://youtu.be/4Z3r9X8OahA')
|
12
|
+
video_embed.should include('http://www.youtube.com/embed/4Z3r9X8OahA?rel=0')
|
13
|
+
end
|
14
|
+
|
10
15
|
it 'accepts a custom width' do
|
11
16
|
video_embed = VideoEmbed.embed('http://www.youtube.com/watch?v=NtgtMQwr3Ko', :width => 1280)
|
12
17
|
video_embed.should match(/width="1280"/)
|
@@ -24,6 +29,11 @@ describe VideoEmbed do
|
|
24
29
|
video_embed.should eql(%Q{<iframe src="http://player.vimeo.com/video/11040425?title=0&byline=0&portrait=0" width="560" height="315" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>})
|
25
30
|
end
|
26
31
|
|
32
|
+
it 'returns embed html from a mobile url' do
|
33
|
+
video_embed = VideoEmbed.embed('http://vimeo.com/m/11040425')
|
34
|
+
video_embed.should include('http://player.vimeo.com/video/11040425?title=0&byline=0&portrait=0')
|
35
|
+
end
|
36
|
+
|
27
37
|
it 'accepts a custom width' do
|
28
38
|
video_embed = VideoEmbed.embed('http://vimeo.com/11040425', :width => 720)
|
29
39
|
video_embed.should match(/width="720"/)
|