embed 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  An easy way to embed media to your Rails app. Don't worry about messy embedding HTML anymore, just use the media URL.
4
4
 
5
- As of now, it only supports YouTube.
5
+ As of now, it only supports YouTube and Vimeo.
6
6
 
7
7
  ## Installation
8
8
 
@@ -22,7 +22,7 @@ Or install it yourself as:
22
22
 
23
23
  On your view:
24
24
  ```ruby
25
- <%= embed("http://www.youtube.com/watch?v=fwncgZ15RVQ") %>
25
+ <%= embed(http://www.youtube.com/watch?v=\"fwncgZ15RVQ\")" %>
26
26
  ```
27
27
 
28
28
  ## Contributing
@@ -9,6 +9,13 @@ module Embed
9
9
  return $1
10
10
  end
11
11
  end
12
+ def self.vimeo_video_id(url)
13
+ if url[/vimeo.com\/([^\?]*)/]
14
+ return $1
15
+ end
16
+ end
12
17
  end
13
18
 
14
- ActionView::Base.send :include, Embed::EmbedHelper
19
+ if defined?(ActionView::Base)
20
+ ActionView::Base.send :include, Embed::EmbedHelper
21
+ end
@@ -1,3 +1,3 @@
1
1
  module Embed
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -6,11 +6,17 @@ module Embed
6
6
  video_id = Embed.youtube_video_id(url)
7
7
  url = %Q{<iframe id="#{video_id}" type="text/html" width="640" height="390" src="http://www.youtube.com/embed/#{video_id}?autoplay=0 frameborder="0"/>}
8
8
  url.respond_to?(:html_safe) ? url.html_safe : url
9
-
9
+ end
10
+ def vimeo_embed(url)
11
+ video_id = Embed.vimeo_video_id(url)
12
+ url = %Q{<iframe src="http://player.vimeo.com/video/#{video_id}" width="640" height="390" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>}
13
+ url.respond_to?(:html_safe) ? url.html_safe : url
10
14
  end
11
15
  def embed(url)
12
16
  if url[/(youtube.com|youtu.be)/]
13
17
  return youtube_embed(url)
18
+ elsif url[/vimeo.com/]
19
+ return vimeo_embed(url)
14
20
  end
15
21
  end
16
22
  end
@@ -6,14 +6,23 @@ include Embed::EmbedHelper
6
6
 
7
7
  describe Embed::EmbedHelper do
8
8
  let(:youtube_url) { 'http://www.youtube.com/watch?v=u1zgFlCw8Aw' }
9
+ let(:vimeo_url) { 'http://vimeo.com/49760839' }
9
10
  describe '::youtube_embed(url)' do
10
11
  it 'returns the embedding html for a YouTube URL' do
11
12
  youtube_embed(youtube_url).should == %Q{<iframe id="u1zgFlCw8Aw" type="text/html" width="640" height="390" src="http://www.youtube.com/embed/u1zgFlCw8Aw?autoplay=0 frameborder="0"/>}
12
13
  end
13
14
  end
15
+ describe '::vimeo_embed(url)' do
16
+ it 'returns the embedding html for a Vimeo URL' do
17
+ vimeo_embed(vimeo_url).should == %Q{<iframe src="http://player.vimeo.com/video/49760839" width="640" height="390" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>}
18
+ end
19
+ end
14
20
  describe '::embed(url)' do
15
21
  it 'embeds an YouTube video' do
16
22
  embed(youtube_url).should == %Q{<iframe id="u1zgFlCw8Aw" type="text/html" width="640" height="390" src="http://www.youtube.com/embed/u1zgFlCw8Aw?autoplay=0 frameborder="0"/>}
17
23
  end
24
+ it 'embeds a Vimeo video' do
25
+ embed(vimeo_url).should == %Q{<iframe src="http://player.vimeo.com/video/49760839" width="640" height="390" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>}
26
+ end
18
27
  end
19
28
  end
@@ -6,13 +6,19 @@ include Embed
6
6
 
7
7
  describe Embed do
8
8
  describe '::youtube_video_id(url)' do
9
- it 'returns the YouTube video code from a full URL' do
9
+ it 'returns the YouTube video id from a full URL' do
10
10
  url = 'http://www.youtube.com/watch?v=dMH0bHeiRNg'
11
11
  Embed.youtube_video_id(url).should == 'dMH0bHeiRNg'
12
12
  end
13
- it 'returns the YouTube video code from a short URL' do
13
+ it 'returns the YouTube video id from a short URL' do
14
14
  url = 'http://youtu.be/dMH0bHeiRNg'
15
15
  Embed.youtube_video_id(url).should == 'dMH0bHeiRNg'
16
16
  end
17
17
  end
18
+ describe '::vimeo_video_id(url)' do
19
+ it 'returns the Vimeo video id from its URL' do
20
+ url = 'http://vimeo.com/49760839'
21
+ Embed.vimeo_video_id(url).should == '49760839'
22
+ end
23
+ end
18
24
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embed
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -75,7 +75,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
75
75
  version: '0'
76
76
  segments:
77
77
  - 0
78
- hash: -3637459664052554990
78
+ hash: 3195176760563316961
79
79
  required_rubygems_version: !ruby/object:Gem::Requirement
80
80
  none: false
81
81
  requirements:
@@ -84,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
84
  version: '0'
85
85
  segments:
86
86
  - 0
87
- hash: -3637459664052554990
87
+ hash: 3195176760563316961
88
88
  requirements: []
89
89
  rubyforge_project:
90
90
  rubygems_version: 1.8.24