embed 0.0.2 → 0.0.3
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/README.md +2 -2
- data/lib/embed/version.rb +1 -1
- data/lib/embed_helper.rb +22 -4
- data/lib/spec/embed_helper_spec.rb +9 -0
- metadata +3 -3
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 and
|
5
|
+
As of now, it only supports YouTube, Vimeo and SoundCloud.
|
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
|
25
|
+
<%= embed("http://www.youtube.com/watch?v=fwncgZ15RVQ") %>
|
26
26
|
```
|
27
27
|
|
28
28
|
## Contributing
|
data/lib/embed/version.rb
CHANGED
data/lib/embed_helper.rb
CHANGED
@@ -1,22 +1,40 @@
|
|
1
1
|
require 'embed'
|
2
|
+
require 'json'
|
3
|
+
require 'net/http'
|
4
|
+
require 'uri'
|
5
|
+
require 'cgi'
|
2
6
|
|
3
7
|
module Embed
|
4
8
|
module EmbedHelper
|
5
9
|
def youtube_embed(url)
|
6
10
|
video_id = Embed.youtube_video_id(url)
|
7
|
-
|
8
|
-
|
11
|
+
html = %Q{<iframe id="#{video_id}" type="text/html" width="640" height="390" src="http://www.youtube.com/embed/#{video_id}?autoplay=0 frameborder="0"/>}
|
12
|
+
html.respond_to?(:html_safe) ? html.html_safe : html
|
9
13
|
end
|
10
14
|
def vimeo_embed(url)
|
11
15
|
video_id = Embed.vimeo_video_id(url)
|
12
|
-
|
13
|
-
|
16
|
+
html = %Q{<iframe src="http://player.vimeo.com/video/#{video_id}" width="640" height="390" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>}
|
17
|
+
html.respond_to?(:html_safe) ? html.html_safe : html
|
18
|
+
end
|
19
|
+
def soundcloud_embed(url)
|
20
|
+
uri = URI("http://soundcloud.com/oembed")
|
21
|
+
params = {:format => 'json', :url => url}
|
22
|
+
uri.query = params.collect { |k,v| "#{k}=#{CGI::escape(v.to_s)}" }.join('&')
|
23
|
+
response = Net::HTTP.get(uri)
|
24
|
+
if response
|
25
|
+
html = JSON.parse(response)["html"]
|
26
|
+
html.respond_to?(:html_safe) ? html.html_safe : html
|
27
|
+
else
|
28
|
+
return link_to(url)
|
29
|
+
end
|
14
30
|
end
|
15
31
|
def embed(url)
|
16
32
|
if url[/(youtube.com|youtu.be)/]
|
17
33
|
return youtube_embed(url)
|
18
34
|
elsif url[/vimeo.com/]
|
19
35
|
return vimeo_embed(url)
|
36
|
+
elsif url[/soundcloud.com/]
|
37
|
+
return soundcloud_embed(url)
|
20
38
|
end
|
21
39
|
end
|
22
40
|
end
|
@@ -7,6 +7,7 @@ include Embed::EmbedHelper
|
|
7
7
|
describe Embed::EmbedHelper do
|
8
8
|
let(:youtube_url) { 'http://www.youtube.com/watch?v=u1zgFlCw8Aw' }
|
9
9
|
let(:vimeo_url) { 'http://vimeo.com/49760839' }
|
10
|
+
let(:soundcloud_url) { 'http://soundcloud.com/dj-slink/in-for-the-kill-dj-slinks-gets' }
|
10
11
|
describe '::youtube_embed(url)' do
|
11
12
|
it 'returns the embedding html for a YouTube URL' do
|
12
13
|
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"/>}
|
@@ -17,6 +18,11 @@ describe Embed::EmbedHelper do
|
|
17
18
|
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
19
|
end
|
19
20
|
end
|
21
|
+
describe '::soundcloud_embed(url)' do
|
22
|
+
it 'returns the embedding html for a SoundCloud URL' do
|
23
|
+
soundcloud_embed(soundcloud_url).should == %Q{<iframe width="100%" height="166" scrolling="no" frameborder="no" src="http://w.soundcloud.com/player/?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F60522748&show_artwork=true"></iframe>}
|
24
|
+
end
|
25
|
+
end
|
20
26
|
describe '::embed(url)' do
|
21
27
|
it 'embeds an YouTube video' do
|
22
28
|
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"/>}
|
@@ -24,5 +30,8 @@ describe Embed::EmbedHelper do
|
|
24
30
|
it 'embeds a Vimeo video' do
|
25
31
|
embed(vimeo_url).should == %Q{<iframe src="http://player.vimeo.com/video/49760839" width="640" height="390" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>}
|
26
32
|
end
|
33
|
+
it 'embeds a SoundCloud audio' do
|
34
|
+
embed(soundcloud_url).should == %Q{<iframe width="100%" height="166" scrolling="no" frameborder="no" src="http://w.soundcloud.com/player/?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F60522748&show_artwork=true"></iframe>}
|
35
|
+
end
|
27
36
|
end
|
28
37
|
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.
|
4
|
+
version: 0.0.3
|
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:
|
78
|
+
hash: -1582312353035851371
|
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:
|
87
|
+
hash: -1582312353035851371
|
88
88
|
requirements: []
|
89
89
|
rubyforge_project:
|
90
90
|
rubygems_version: 1.8.24
|