embed 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +10 -0
- data/lib/embed/version.rb +1 -1
- data/lib/embed_helper.rb +15 -12
- data/spec/embed_helper_spec.rb +32 -24
- metadata +13 -27
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c5832fbdcd74bb22831d121cbb8e8c8e5cd3a93d
|
4
|
+
data.tar.gz: c95a376112cd1788632668e1daaef3a024975c1d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e4a4c4623b9d3b0ead6103cb1af400964a030265b037fc16d91481d2fbc16c1b604511131f0bc5ad3881bd104ecd923d24ef5ea3f4e8a95eb2b606f0f52ad70e
|
7
|
+
data.tar.gz: 480191370e99857d6ea036c3477cf7fdbe9b41906235b1618f94b71fe9597f6dbd0d9f5c76d54f6331e328fcfeb16e5609a2acbe65fc1d958dac8d9766afe4bf
|
data/README.md
CHANGED
@@ -30,6 +30,16 @@ On your view
|
|
30
30
|
<%= embed('http://www.youtube.com/watch?v=fwncgZ15RVQ', {:width => 540, :height => 290}) %>
|
31
31
|
```
|
32
32
|
|
33
|
+
Can also specify the protocol («http» by default)
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
<%= embed('http://www.youtube.com/watch?v=fwncgZ15RVQ', {:width => 540, :height => 290, :protocol => 'https'}) %>
|
37
|
+
```
|
38
|
+
|
39
|
+
** Soundcloud always uses https
|
40
|
+
** Wistia does not allow using https
|
41
|
+
|
42
|
+
|
33
43
|
## Contributing
|
34
44
|
|
35
45
|
1. Fork it
|
data/lib/embed/version.rb
CHANGED
data/lib/embed_helper.rb
CHANGED
@@ -6,26 +6,26 @@ require 'cgi'
|
|
6
6
|
|
7
7
|
module Embed
|
8
8
|
module EmbedHelper
|
9
|
-
def _youtube_embed(url, width, height)
|
9
|
+
def _youtube_embed(url, width, height, protocol)
|
10
10
|
video_id = Embed.youtube_video_id(url)
|
11
|
-
html = %Q{<iframe id="#{video_id}" type="text/html" width="#{width}" height="#{height}" src="
|
11
|
+
html = %Q{<iframe id="#{video_id}" type="text/html" width="#{width}" height="#{height}" src="#{protocol}://www.youtube.com/embed/#{video_id}?autoplay=0" frameborder="0"></iframe>}
|
12
12
|
html.respond_to?(:html_safe) ? html.html_safe : html
|
13
13
|
end
|
14
14
|
|
15
|
-
def _vimeo_embed(url, width, height)
|
15
|
+
def _vimeo_embed(url, width, height, protocol)
|
16
16
|
video_id = Embed.vimeo_video_id(url)
|
17
|
-
html = %Q{<iframe src="
|
17
|
+
html = %Q{<iframe src="#{protocol}://player.vimeo.com/video/#{video_id}" width="#{width}" height="#{height}" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>}
|
18
18
|
html.respond_to?(:html_safe) ? html.html_safe : html
|
19
19
|
end
|
20
20
|
|
21
|
-
def _soundcloud_embed(url)
|
21
|
+
def _soundcloud_embed(url, protocol)
|
22
22
|
params = {:format => 'json', :url => url}
|
23
|
-
_oembed(
|
23
|
+
_oembed("#{protocol}://soundcloud.com/oembed", url, params)
|
24
24
|
end
|
25
25
|
|
26
|
-
def _wistia_embed(url, width, height)
|
26
|
+
def _wistia_embed(url, width, height, protocol)
|
27
27
|
params = { :format => 'json', :url => url, :width => width, :height => height }
|
28
|
-
_oembed(
|
28
|
+
_oembed("#{protocol}://fast.wistia.com/oembed", url, params)
|
29
29
|
end
|
30
30
|
|
31
31
|
def _oembed(oembed_url, url, params)
|
@@ -45,16 +45,19 @@ module Embed
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def embed(url, params = {})
|
48
|
+
return if url.nil? || url.empty?
|
49
|
+
|
48
50
|
params[:width] ||= 640
|
49
51
|
params[:height] ||= 390
|
52
|
+
params[:protocol] ||= 'http'
|
50
53
|
if url[/(youtube.com|youtu.be)/]
|
51
|
-
return _youtube_embed(url, params[:width], params[:height])
|
54
|
+
return _youtube_embed(url, params[:width], params[:height], params[:protocol])
|
52
55
|
elsif url[/vimeo.com/]
|
53
|
-
return _vimeo_embed(url, params[:width], params[:height])
|
56
|
+
return _vimeo_embed(url, params[:width], params[:height], params[:protocol])
|
54
57
|
elsif url[/soundcloud.com/]
|
55
|
-
return _soundcloud_embed(url)
|
58
|
+
return _soundcloud_embed(url, params[:protocol])
|
56
59
|
elsif url[/wistia.com/]
|
57
|
-
return _wistia_embed(url, params[:width], params[:height])
|
60
|
+
return _wistia_embed(url, params[:width], params[:height], params[:protocol])
|
58
61
|
end
|
59
62
|
end
|
60
63
|
end
|
data/spec/embed_helper_spec.rb
CHANGED
@@ -10,60 +10,68 @@ describe Embed::EmbedHelper do
|
|
10
10
|
let(:soundcloud_url) { 'http://soundcloud.com/forss/flickermood' }
|
11
11
|
let(:wistia_url) { 'http://fast.wistia.com/embed/iframe/2cf8fbb2c0' }
|
12
12
|
|
13
|
-
describe '::_youtube_embed(url, 640, 390)' do
|
13
|
+
describe '::_youtube_embed(url, 640, 390, http)' do
|
14
14
|
it 'returns the embedding html for a YouTube URL' do
|
15
|
-
_youtube_embed(youtube_url, 640, 390).should == %Q{<iframe id="u1zgFlCw8Aw" type="text/html" width="640" height="390" src="http://www.youtube.com/embed/u1zgFlCw8Aw?autoplay=0" frameborder="0"
|
15
|
+
_youtube_embed(youtube_url, 640, 390, 'http').should == %Q{<iframe id="u1zgFlCw8Aw" type="text/html" width="640" height="390" src="http://www.youtube.com/embed/u1zgFlCw8Aw?autoplay=0" frameborder="0"></iframe>}
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
describe '::_vimeo_embed(url, 640, 390)' do
|
19
|
+
describe '::_vimeo_embed(url, 640, 390, http)' do
|
20
20
|
it 'returns the embedding html for a Vimeo URL' do
|
21
|
-
_vimeo_embed(vimeo_url, 640, 390).should == %Q{<iframe src="http://player.vimeo.com/video/49760839" width="640" height="390" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>}
|
21
|
+
_vimeo_embed(vimeo_url, 640, 390, 'http').should == %Q{<iframe src="http://player.vimeo.com/video/49760839" width="640" height="390" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>}
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
describe '::_soundcloud_embed(url)' do
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
end
|
25
|
+
# describe '::_soundcloud_embed(url, http)' do
|
26
|
+
# it 'returns the embedding html for a SoundCloud URL' do
|
27
|
+
# _soundcloud_embed(soundcloud_url, 'http').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%2F293&show_artwork=true\"></iframe>}
|
28
|
+
# end
|
29
|
+
# end
|
30
30
|
|
31
|
-
describe '::_wistia_embed(url, 640, 390)' do
|
31
|
+
describe '::_wistia_embed(url, 640, 390, http)' do
|
32
32
|
it 'returns the embedding html for a Wisita URL' do
|
33
|
-
_wistia_embed(wistia_url, 640, 390).should == %Q{<iframe src="http://fast.wistia.net/embed/iframe/2cf8fbb2c0
|
33
|
+
_wistia_embed(wistia_url, 640, 390, 'http').should == %Q{<iframe src="http://fast.wistia.net/embed/iframe/2cf8fbb2c0" allowtransparency="true" frameborder="0" scrolling="no" class="wistia_embed" name="wistia_embed" width="640" height="390"></iframe>}
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
37
|
describe '::embed(url)' do
|
38
38
|
it 'embeds an YouTube video' do
|
39
|
-
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"
|
39
|
+
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"></iframe>}
|
40
40
|
end
|
41
41
|
|
42
42
|
it 'embeds a Vimeo video' do
|
43
43
|
embed(vimeo_url).should == %Q{<iframe src="http://player.vimeo.com/video/49760839" width="640" height="390" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>}
|
44
44
|
end
|
45
45
|
|
46
|
-
|
47
|
-
|
46
|
+
# FIXME: SoundCloud always return https (?)
|
47
|
+
# it 'embeds a SoundCloud audio' do
|
48
|
+
# 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%2F293&show_artwork=true\"></iframe>}
|
49
|
+
# end
|
50
|
+
|
51
|
+
it 'embeds a SoundCloud audio using https protocol' do
|
52
|
+
embed(soundcloud_url, {:protocol => 'https'}).should == %Q{<iframe width=\"100%\" height=\"166\" scrolling=\"no\" frameborder=\"no\" src=\"https://w.soundcloud.com/player/?url=https%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F293&show_artwork=true\"></iframe>}
|
48
53
|
end
|
49
54
|
end
|
50
55
|
|
51
|
-
describe '::embed(url, 540, 290)' do
|
52
|
-
it 'embeds an YouTube video with custom sizes' do
|
53
|
-
embed(youtube_url, {:width => 540, :height => 290}).should == %Q{<iframe id="u1zgFlCw8Aw" type="text/html" width="540" height="290" src="
|
56
|
+
describe '::embed(url, 540, 290, https)' do
|
57
|
+
it 'embeds an YouTube video with custom sizes and using https protocol' do
|
58
|
+
embed(youtube_url, {:width => 540, :height => 290, :protocol => 'https'}).should == %Q{<iframe id="u1zgFlCw8Aw" type="text/html" width="540" height="290" src="https://www.youtube.com/embed/u1zgFlCw8Aw?autoplay=0" frameborder="0"></iframe>}
|
54
59
|
end
|
55
60
|
|
56
|
-
it 'embeds a Vimeo video with custom sizes' do
|
57
|
-
embed(vimeo_url, {:width => 540, :height => 290}).should == %Q{<iframe src="
|
61
|
+
it 'embeds a Vimeo video with custom sizes and using https protocol' do
|
62
|
+
embed(vimeo_url, {:width => 540, :height => 290, :protocol => 'https'}).should == %Q{<iframe src="https://player.vimeo.com/video/49760839" width="540" height="290" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>}
|
58
63
|
end
|
59
64
|
|
60
65
|
#FIXME: Wistia always return videoHeight=360&videoWidth=640 ??
|
61
|
-
|
62
|
-
|
63
|
-
|
66
|
+
# Wistia not return https protocol
|
67
|
+
# it 'embeds a Wistia video with custom sizes and using https protocol' do
|
68
|
+
# embed(wistia_url, {:width => 540, :height => 290, :protocol => 'https'}).should == %Q{<iframe src="https://fast.wistia.net/embed/iframe/2cf8fbb2c0" allowtransparency="true" frameborder="0" scrolling="no" class="wistia_embed" name="wistia_embed" width="540" height="290"></iframe>}
|
69
|
+
# end
|
64
70
|
|
65
|
-
it '
|
66
|
-
embed(
|
71
|
+
it 'do nothing when no url' do
|
72
|
+
embed(nil).should == nil
|
73
|
+
embed("").should == nil
|
67
74
|
end
|
75
|
+
|
68
76
|
end
|
69
77
|
end
|
metadata
CHANGED
@@ -1,62 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: embed
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.6
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Neil Carvalho
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-08-16 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rspec
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rake
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - '>='
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - '>='
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: fakeweb
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - '>='
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - '>='
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
description: An easy way to embed media to your Rails app
|
@@ -79,33 +72,26 @@ files:
|
|
79
72
|
- spec/embed_spec.rb
|
80
73
|
homepage: https://github.com/neilvilela/embed
|
81
74
|
licenses: []
|
75
|
+
metadata: {}
|
82
76
|
post_install_message:
|
83
77
|
rdoc_options: []
|
84
78
|
require_paths:
|
85
79
|
- lib
|
86
80
|
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
-
none: false
|
88
81
|
requirements:
|
89
|
-
- -
|
82
|
+
- - '>='
|
90
83
|
- !ruby/object:Gem::Version
|
91
84
|
version: '0'
|
92
|
-
segments:
|
93
|
-
- 0
|
94
|
-
hash: 488596979403717978
|
95
85
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
-
none: false
|
97
86
|
requirements:
|
98
|
-
- -
|
87
|
+
- - '>='
|
99
88
|
- !ruby/object:Gem::Version
|
100
89
|
version: '0'
|
101
|
-
segments:
|
102
|
-
- 0
|
103
|
-
hash: 488596979403717978
|
104
90
|
requirements: []
|
105
91
|
rubyforge_project:
|
106
|
-
rubygems_version:
|
92
|
+
rubygems_version: 2.0.3
|
107
93
|
signing_key:
|
108
|
-
specification_version:
|
94
|
+
specification_version: 4
|
109
95
|
summary: An easy way to embed media to your Rails app
|
110
96
|
test_files:
|
111
97
|
- spec/embed_helper_spec.rb
|