url_to_media_tag 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/url_to_media_tag.rb +19 -11
- data/spec/url_to_media_tag_spec.rb +14 -2
- data/url_to_media_tag.gemspec +2 -2
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/lib/url_to_media_tag.rb
CHANGED
@@ -6,6 +6,16 @@ module UrlToMediaTag
|
|
6
6
|
:height => 480
|
7
7
|
}
|
8
8
|
|
9
|
+
def self.video_iframe(url, options)
|
10
|
+
options = {:src => url, :class => "url-to-media-tag-video", :frameborder => 0}.merge(options)
|
11
|
+
tag(:iframe, options)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.tag(name, options)
|
15
|
+
options = options.map{|k,v| "#{k}=\"#{v}\"" }.sort.join(" ")
|
16
|
+
%{<#{name} #{options}></#{name}>}
|
17
|
+
end
|
18
|
+
|
9
19
|
def self.convert(url, options={})
|
10
20
|
options = DEFAULTS.merge(options)
|
11
21
|
|
@@ -17,24 +27,22 @@ module UrlToMediaTag
|
|
17
27
|
# youtube
|
18
28
|
when /http:\/\/(www.)?youtube\.com\/watch\?v=([A-Za-z0-9._%-]*)(\&\S+)?|http:\/\/(www.)?youtu\.be\/([A-Za-z0-9._%-]*)?/
|
19
29
|
youtube_id = $2 || $5
|
20
|
-
|
21
|
-
height = options[:height]
|
22
|
-
frameborder = options[:frameborder]
|
23
|
-
%{<iframe class="youtube-player" type="text/html" width="#{width}" height="#{height}" src="http://www.youtube.com/embed/#{youtube_id}" frameborder="#{frameborder}"></iframe>}
|
30
|
+
video_iframe "http://www.youtube.com/embed/#{youtube_id}", options
|
24
31
|
|
25
32
|
# vimeo
|
26
33
|
when /http:\/\/(www.)?vimeo\.com\/([A-Za-z0-9._%-]*)((\?|#)\S+)?/
|
27
34
|
vimeo_id = $2
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
show_byline = "byline=0" unless options[:show_byline]
|
32
|
-
show_portrait = "portrait=0" unless options[:show_portrait]
|
33
|
-
frameborder = options[:frameborder] || 0
|
35
|
+
show_title = "title=0" unless options.delete(:show_title)
|
36
|
+
show_byline = "byline=0" unless options.delete(:show_byline)
|
37
|
+
show_portrait = "portrait=0" unless options.delete(:show_portrait)
|
34
38
|
query_string_variables = [show_title, show_byline, show_portrait].compact.join("&")
|
35
39
|
query_string = "?" + query_string_variables unless query_string_variables.empty?
|
36
40
|
|
37
|
-
|
41
|
+
video_iframe "http://player.vimeo.com/video/#{vimeo_id}#{query_string}", options
|
42
|
+
|
43
|
+
# image
|
44
|
+
when /https?:\/\/\S+\.(jpe?g|gif|png|bmp|tif)(\?\S+)?/i
|
45
|
+
tag(:img, options.merge(:src => $&))
|
38
46
|
end
|
39
47
|
|
40
48
|
result = result.html_safe if result.respond_to?(:html_safe)
|
@@ -7,15 +7,27 @@ describe UrlToMediaTag do
|
|
7
7
|
|
8
8
|
describe 'convert' do
|
9
9
|
it "converts youtube" do
|
10
|
-
expected = "<iframe class=\"
|
10
|
+
expected = "<iframe class=\"url-to-media-tag-video\" frameborder=\"0\" height=\"480\" src=\"http://www.youtube.com/embed/kW-dS4otEZU\" width=\"640\"></iframe>"
|
11
11
|
UrlToMediaTag.convert('http://www.youtube.com/watch?v=kW-dS4otEZU').should == expected
|
12
12
|
end
|
13
13
|
|
14
14
|
it "converts vimeo" do
|
15
|
-
expected = "<iframe src=\"http://player.vimeo.com/video/26881896?title=0&byline=0&portrait=0\" width=\"640\"
|
15
|
+
expected = "<iframe class=\"url-to-media-tag-video\" frameborder=\"0\" height=\"480\" src=\"http://player.vimeo.com/video/26881896?title=0&byline=0&portrait=0\" width=\"640\"></iframe>"
|
16
16
|
UrlToMediaTag.convert('http://vimeo.com/26881896').should == expected
|
17
17
|
end
|
18
18
|
|
19
|
+
it "converts images" do
|
20
|
+
UrlToMediaTag.convert('http://foo.com/foo.jpg').should == "<img height=\"480\" src=\"http://foo.com/foo.jpg\" width=\"640\"></img>"
|
21
|
+
UrlToMediaTag.convert('http://foo.com/foo.gif').should == "<img height=\"480\" src=\"http://foo.com/foo.gif\" width=\"640\"></img>"
|
22
|
+
UrlToMediaTag.convert('http://foo.com/foo.png').should == "<img height=\"480\" src=\"http://foo.com/foo.png\" width=\"640\"></img>"
|
23
|
+
UrlToMediaTag.convert('http://foo.com/foo.jpeg').should == "<img height=\"480\" src=\"http://foo.com/foo.jpeg\" width=\"640\"></img>"
|
24
|
+
UrlToMediaTag.convert('http://foo.com/foo.JPG').should == "<img height=\"480\" src=\"http://foo.com/foo.JPG\" width=\"640\"></img>"
|
25
|
+
end
|
26
|
+
|
27
|
+
it "converts images with ?" do
|
28
|
+
UrlToMediaTag.convert('http://foo.com/foo.jpg?foo=bar').should == "<img height=\"480\" src=\"http://foo.com/foo.jpg?foo=bar\" width=\"640\"></img>"
|
29
|
+
end
|
30
|
+
|
19
31
|
it "does not convert unknown" do
|
20
32
|
UrlToMediaTag.convert('xxx').should == nil
|
21
33
|
end
|
data/url_to_media_tag.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{url_to_media_tag}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Michael Grosser"]
|
12
|
-
s.date = %q{2011-08-
|
12
|
+
s.date = %q{2011-08-04}
|
13
13
|
s.email = %q{michael@grosser.it}
|
14
14
|
s.files = [
|
15
15
|
"Gemfile",
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: url_to_media_tag
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Michael Grosser
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-08-
|
18
|
+
date: 2011-08-04 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|