url_to_media_tag 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +7 -0
- data/Gemfile.lock +26 -0
- data/Rakefile +18 -0
- data/Readme.md +37 -0
- data/VERSION +1 -0
- data/lib/url_to_media_tag.rb +37 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/url_to_media_tag_spec.rb +19 -0
- data/url_to_media_tag.gemspec +39 -0
- metadata +75 -0
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.1.2)
|
5
|
+
git (1.2.5)
|
6
|
+
jeweler (1.6.4)
|
7
|
+
bundler (~> 1.0)
|
8
|
+
git (>= 1.2.5)
|
9
|
+
rake
|
10
|
+
rake (0.9.2)
|
11
|
+
rspec (2.6.0)
|
12
|
+
rspec-core (~> 2.6.0)
|
13
|
+
rspec-expectations (~> 2.6.0)
|
14
|
+
rspec-mocks (~> 2.6.0)
|
15
|
+
rspec-core (2.6.4)
|
16
|
+
rspec-expectations (2.6.0)
|
17
|
+
diff-lcs (~> 1.1.2)
|
18
|
+
rspec-mocks (2.6.0)
|
19
|
+
|
20
|
+
PLATFORMS
|
21
|
+
ruby
|
22
|
+
|
23
|
+
DEPENDENCIES
|
24
|
+
jeweler
|
25
|
+
rake
|
26
|
+
rspec (~> 2)
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
task :default do
|
2
|
+
sh "rspec spec/"
|
3
|
+
end
|
4
|
+
|
5
|
+
begin
|
6
|
+
require 'jeweler'
|
7
|
+
Jeweler::Tasks.new do |gem|
|
8
|
+
gem.name = 'url_to_media_tag'
|
9
|
+
gem.summary = "Convert a Url to image or video embed"
|
10
|
+
gem.email = "michael@grosser.it"
|
11
|
+
gem.homepage = "http://github.com/grosser/#{gem.name}"
|
12
|
+
gem.authors = ["Michael Grosser"]
|
13
|
+
end
|
14
|
+
|
15
|
+
Jeweler::GemcutterTasks.new
|
16
|
+
rescue LoadError
|
17
|
+
puts "Jeweler, or one of its dependencies, is not available. Install it with: gem install jeweler"
|
18
|
+
end
|
data/Readme.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
Convert a Url to image or video embed.
|
2
|
+
|
3
|
+
Supports:
|
4
|
+
|
5
|
+
- Youtube
|
6
|
+
- Vimeo
|
7
|
+
- ... soon more ...
|
8
|
+
|
9
|
+
Install
|
10
|
+
=======
|
11
|
+
sudo gem install url_to_media_tag
|
12
|
+
Or
|
13
|
+
|
14
|
+
rails plugin install git://github.com/grosser/url_to_media_tag.git
|
15
|
+
|
16
|
+
Usage
|
17
|
+
=====
|
18
|
+
UrlToMediaTag.convert('http://www.youtube.com/watch?v=kW-dS4otEZU') # -> <iframe ...>
|
19
|
+
UrlToMediaTag.convert(url, :width => 480, :height => 320) # -> <iframe ...>
|
20
|
+
UrlToMediaTag.convert('no-url') # -> nil
|
21
|
+
|
22
|
+
Alternative
|
23
|
+
===========
|
24
|
+
- [auto_html](https://github.com/dejan/auto_html) If you want more fancy stuff like auto-linking + strip-tags + active-record-integration (and more dependencies / C-extensions)
|
25
|
+
|
26
|
+
TODO
|
27
|
+
====
|
28
|
+
- support images
|
29
|
+
- let users choose which providers to convert
|
30
|
+
|
31
|
+
Author
|
32
|
+
======
|
33
|
+
Filter logic borrowed from Dejan Simic`s [auto_html](https://github.com/dejan/auto_html) MIT-LICENSE
|
34
|
+
|
35
|
+
[Michael Grosser](http://grosser.it)<br/>
|
36
|
+
michael@grosser.it<br/>
|
37
|
+
Hereby placed under public domain, do what you want, just do not hold me accountable...
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module UrlToMediaTag
|
2
|
+
VERSION = File.read( File.join(File.dirname(__FILE__),'..','VERSION') ).strip
|
3
|
+
|
4
|
+
DEFAULTS = {
|
5
|
+
:width => 640,
|
6
|
+
:height => 480
|
7
|
+
}
|
8
|
+
|
9
|
+
def self.convert(url, options={})
|
10
|
+
options = DEFAULTS.merge(options)
|
11
|
+
|
12
|
+
case url
|
13
|
+
|
14
|
+
# youtube
|
15
|
+
when /http:\/\/(www.)?youtube\.com\/watch\?v=([A-Za-z0-9._%-]*)(\&\S+)?|http:\/\/(www.)?youtu\.be\/([A-Za-z0-9._%-]*)?/
|
16
|
+
youtube_id = $2 || $5
|
17
|
+
width = options[:width]
|
18
|
+
height = options[:height]
|
19
|
+
frameborder = options[:frameborder]
|
20
|
+
%{<iframe class="youtube-player" type="text/html" width="#{width}" height="#{height}" src="http://www.youtube.com/embed/#{youtube_id}" frameborder="#{frameborder}"></iframe>}
|
21
|
+
|
22
|
+
# vimeo
|
23
|
+
when /http:\/\/(www.)?vimeo\.com\/([A-Za-z0-9._%-]*)((\?|#)\S+)?/
|
24
|
+
vimeo_id = $2
|
25
|
+
width = options[:width]
|
26
|
+
height = options[:height]
|
27
|
+
show_title = "title=0" unless options[:show_title]
|
28
|
+
show_byline = "byline=0" unless options[:show_byline]
|
29
|
+
show_portrait = "portrait=0" unless options[:show_portrait]
|
30
|
+
frameborder = options[:frameborder] || 0
|
31
|
+
query_string_variables = [show_title, show_byline, show_portrait].compact.join("&")
|
32
|
+
query_string = "?" + query_string_variables unless query_string_variables.empty?
|
33
|
+
|
34
|
+
%{<iframe src="http://player.vimeo.com/video/#{vimeo_id}#{query_string}" width="#{width}" height="#{height}" frameborder="#{frameborder}"></iframe>}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.expand_path('spec/spec_helper')
|
2
|
+
|
3
|
+
describe UrlToMediaTag do
|
4
|
+
it "has a VERSION" do
|
5
|
+
UrlToMediaTag::VERSION.should =~ /^\d+\.\d+\.\d+$/
|
6
|
+
end
|
7
|
+
|
8
|
+
describe 'convert' do
|
9
|
+
it "converts youtube" do
|
10
|
+
expected = "<iframe class=\"youtube-player\" type=\"text/html\" width=\"640\" height=\"480\" src=\"http://www.youtube.com/embed/kW-dS4otEZU\" frameborder=\"\"></iframe>"
|
11
|
+
UrlToMediaTag.convert('http://www.youtube.com/watch?v=kW-dS4otEZU').should == expected
|
12
|
+
end
|
13
|
+
|
14
|
+
it "converts vimeo" do
|
15
|
+
expected = "<iframe src=\"http://player.vimeo.com/video/26881896?title=0&byline=0&portrait=0\" width=\"640\" height=\"480\" frameborder=\"0\"></iframe>"
|
16
|
+
UrlToMediaTag.convert('http://vimeo.com/26881896').should == expected
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{url_to_media_tag}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Michael Grosser"]
|
12
|
+
s.date = %q{2011-08-03}
|
13
|
+
s.email = %q{michael@grosser.it}
|
14
|
+
s.files = [
|
15
|
+
"Gemfile",
|
16
|
+
"Gemfile.lock",
|
17
|
+
"Rakefile",
|
18
|
+
"Readme.md",
|
19
|
+
"VERSION",
|
20
|
+
"lib/url_to_media_tag.rb",
|
21
|
+
"spec/spec_helper.rb",
|
22
|
+
"spec/url_to_media_tag_spec.rb",
|
23
|
+
"url_to_media_tag.gemspec"
|
24
|
+
]
|
25
|
+
s.homepage = %q{http://github.com/grosser/url_to_media_tag}
|
26
|
+
s.require_paths = ["lib"]
|
27
|
+
s.rubygems_version = %q{1.6.2}
|
28
|
+
s.summary = %q{Convert a Url to image or video embed}
|
29
|
+
|
30
|
+
if s.respond_to? :specification_version then
|
31
|
+
s.specification_version = 3
|
32
|
+
|
33
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
34
|
+
else
|
35
|
+
end
|
36
|
+
else
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: url_to_media_tag
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Michael Grosser
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-08-03 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description:
|
23
|
+
email: michael@grosser.it
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files: []
|
29
|
+
|
30
|
+
files:
|
31
|
+
- Gemfile
|
32
|
+
- Gemfile.lock
|
33
|
+
- Rakefile
|
34
|
+
- Readme.md
|
35
|
+
- VERSION
|
36
|
+
- lib/url_to_media_tag.rb
|
37
|
+
- spec/spec_helper.rb
|
38
|
+
- spec/url_to_media_tag_spec.rb
|
39
|
+
- url_to_media_tag.gemspec
|
40
|
+
has_rdoc: true
|
41
|
+
homepage: http://github.com/grosser/url_to_media_tag
|
42
|
+
licenses: []
|
43
|
+
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
hash: 3
|
55
|
+
segments:
|
56
|
+
- 0
|
57
|
+
version: "0"
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
hash: 3
|
64
|
+
segments:
|
65
|
+
- 0
|
66
|
+
version: "0"
|
67
|
+
requirements: []
|
68
|
+
|
69
|
+
rubyforge_project:
|
70
|
+
rubygems_version: 1.6.2
|
71
|
+
signing_key:
|
72
|
+
specification_version: 3
|
73
|
+
summary: Convert a Url to image or video embed
|
74
|
+
test_files: []
|
75
|
+
|