youtube_embed 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +12 -1
- data/lib/youtube_embed.rb +10 -8
- data/lib/youtube_embed/version.rb +1 -1
- data/vendor/assets/stylesheets/youtube_embed.css +3 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -20,6 +20,16 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
$ gem install youtube_embed
|
22
22
|
|
23
|
+
And add CSS and JS
|
24
|
+
|
25
|
+
CSS in application.css
|
26
|
+
|
27
|
+
*= require youtube_embed
|
28
|
+
|
29
|
+
JS in application.js
|
30
|
+
|
31
|
+
//= require youtube_embed
|
32
|
+
|
23
33
|
## Usage
|
24
34
|
|
25
35
|
It can be used in model where we can specify simple iframe embed or embedding with thumbnail & description
|
@@ -30,13 +40,14 @@ Simple:
|
|
30
40
|
|
31
41
|
With Thumbnail & Description:
|
32
42
|
|
33
|
-
youtube_embed :field_name, {:with_description =>
|
43
|
+
youtube_embed :field_name, {:with_description => true, :width => 450, :height => 300}
|
34
44
|
|
35
45
|
|
36
46
|
This will modify the youtube link into html required to embed, If you don't want to modify html or simple change the view you can call method in view like this:
|
37
47
|
|
38
48
|
<?= YoutubeEmbed::youtube_embed(attr_here) ?>
|
39
49
|
|
50
|
+
|
40
51
|
Working on further improvements
|
41
52
|
|
42
53
|
## Contributing
|
data/lib/youtube_embed.rb
CHANGED
@@ -20,11 +20,13 @@ module YoutubeEmbed
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def self.youtube_embed(data, options = {:with_description => true, :height => 200, :width => 300})
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
if data.match(/https?:\/\/?(?:www\.)?youtu(?:\.be|be\.com)/)
|
24
|
+
data = data.gsub(/<a?[^<]+ href="(?:https?:\/\/)?(?:www\.)?youtu(?:\.be|be\.com)\/(?:watch\?v=)?\w{10,11}"?[^<]+>([^<]+)<\/a>/i, '\1')
|
25
|
+
if options[:with_description]
|
26
|
+
data = data.gsub(/((?:https?:\/\/)?(?:www\.)?youtu(?:\.be|be\.com)\/(?:watch\?v=)?\w{10,11})/i, thumbnail_and_description("#{$1}", options[:width], options[:height]))
|
27
|
+
else
|
28
|
+
data = data.gsub(/((?:https?:\/\/)?(?:www\.)?youtu(?:\.be|be\.com)\/(?:watch\?v=)?\w{10,11})/i, simple("#{$1}", options[:width], options[:height]))
|
29
|
+
end
|
28
30
|
end
|
29
31
|
return data
|
30
32
|
end
|
@@ -39,16 +41,16 @@ module YoutubeEmbed
|
|
39
41
|
return %Q{<div class="youtube_embed_video">
|
40
42
|
<div class="youtube_embed_partial_video">
|
41
43
|
<div class="youtube_embed_thumbnail">
|
42
|
-
<img src="#{thumbnails[1]["url"]}" />
|
44
|
+
<img src="#{thumbnails[1]["url"] ? thumbnails[1]["url"] : ""}" />
|
43
45
|
</div>
|
44
46
|
<div class="youtube_embed_details">
|
45
47
|
<div class="youtube_embed_title">
|
46
48
|
<strong>
|
47
|
-
#{video_details.title["__content__"]}
|
49
|
+
#{video_details.title["__content__"] ? video_details.title["__content__"] : ""}
|
48
50
|
</strong>
|
49
51
|
</div>
|
50
52
|
<div class="youtube_embed_description">
|
51
|
-
#{video_details.description["__content__"].truncate(185)}
|
53
|
+
#{video_details.description["__content__"] ? video_details.description["__content__"].truncate(185) : ""}
|
52
54
|
</div>
|
53
55
|
</div>
|
54
56
|
</div>
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: youtube_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:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05-
|
12
|
+
date: 2013-05-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|