embed 0.0.1
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/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +34 -0
- data/Rakefile +1 -0
- data/embed.gemspec +22 -0
- data/lib/embed/version.rb +3 -0
- data/lib/embed.rb +14 -0
- data/lib/embed_helper.rb +17 -0
- data/lib/spec/embed_helper_spec.rb +19 -0
- data/lib/spec/embed_spec.rb +18 -0
- metadata +94 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Neil Carvalho
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# Embed
|
2
|
+
|
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
|
+
|
5
|
+
As of now, it only supports YouTube.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'embed'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install embed
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
On your view:
|
24
|
+
```ruby
|
25
|
+
<%= embed("http://www.youtube.com/watch?v=fwncgZ15RVQ") %>
|
26
|
+
```
|
27
|
+
|
28
|
+
## Contributing
|
29
|
+
|
30
|
+
1. Fork it
|
31
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
32
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
33
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
34
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/embed.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'embed/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "embed"
|
8
|
+
gem.version = Embed::VERSION
|
9
|
+
gem.authors = ["Neil Carvalho"]
|
10
|
+
gem.email = ["me@neil.pro"]
|
11
|
+
gem.description = %q{An easy way to embed media to your Rails app}
|
12
|
+
gem.summary = %q{An easy way to embed media to your Rails app}
|
13
|
+
gem.homepage = "https://github.com/neilvilela/embed"
|
14
|
+
|
15
|
+
gem.add_development_dependency 'rspec'
|
16
|
+
gem.add_development_dependency 'rake'
|
17
|
+
|
18
|
+
gem.files = `git ls-files`.split($/)
|
19
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
20
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
21
|
+
gem.require_paths = ["lib"]
|
22
|
+
end
|
data/lib/embed.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "embed/version"
|
2
|
+
require 'embed_helper'
|
3
|
+
|
4
|
+
module Embed
|
5
|
+
def self.youtube_video_id(url)
|
6
|
+
if url[/^.*((v\/)|(embed\/)|(watch\?))\??v?=?([^\&\?]*).*/]
|
7
|
+
return $5
|
8
|
+
elsif url[/youtu\.be\/([^\?]*)/]
|
9
|
+
return $1
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
ActionView::Base.send :include, Embed::EmbedHelper
|
data/lib/embed_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'embed'
|
2
|
+
|
3
|
+
module Embed
|
4
|
+
module EmbedHelper
|
5
|
+
def youtube_embed(url)
|
6
|
+
video_id = Embed.youtube_video_id(url)
|
7
|
+
url = %Q{<iframe id="#{video_id}" type="text/html" width="640" height="390" src="http://www.youtube.com/embed/#{video_id}?autoplay=0 frameborder="0"/>}
|
8
|
+
url.respond_to?(:html_safe) ? url.html_safe : url
|
9
|
+
|
10
|
+
end
|
11
|
+
def embed(url)
|
12
|
+
if url[/(youtube.com|youtu.be)/]
|
13
|
+
return youtube_embed(url)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'embed_helper'
|
3
|
+
require 'rspec'
|
4
|
+
|
5
|
+
include Embed::EmbedHelper
|
6
|
+
|
7
|
+
describe Embed::EmbedHelper do
|
8
|
+
let(:youtube_url) { 'http://www.youtube.com/watch?v=u1zgFlCw8Aw' }
|
9
|
+
describe '::youtube_embed(url)' do
|
10
|
+
it 'returns the embedding html for a YouTube URL' do
|
11
|
+
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"/>}
|
12
|
+
end
|
13
|
+
end
|
14
|
+
describe '::embed(url)' do
|
15
|
+
it 'embeds an YouTube video' do
|
16
|
+
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
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'embed'
|
3
|
+
require 'rspec'
|
4
|
+
|
5
|
+
include Embed
|
6
|
+
|
7
|
+
describe Embed do
|
8
|
+
describe '::youtube_video_id(url)' do
|
9
|
+
it 'returns the YouTube video code from a full URL' do
|
10
|
+
url = 'http://www.youtube.com/watch?v=dMH0bHeiRNg'
|
11
|
+
Embed.youtube_video_id(url).should == 'dMH0bHeiRNg'
|
12
|
+
end
|
13
|
+
it 'returns the YouTube video code from a short URL' do
|
14
|
+
url = 'http://youtu.be/dMH0bHeiRNg'
|
15
|
+
Embed.youtube_video_id(url).should == 'dMH0bHeiRNg'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: embed
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Neil Carvalho
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-23 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: An easy way to embed media to your Rails app
|
47
|
+
email:
|
48
|
+
- me@neil.pro
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- Gemfile
|
55
|
+
- LICENSE.txt
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- embed.gemspec
|
59
|
+
- lib/embed.rb
|
60
|
+
- lib/embed/version.rb
|
61
|
+
- lib/embed_helper.rb
|
62
|
+
- lib/spec/embed_helper_spec.rb
|
63
|
+
- lib/spec/embed_spec.rb
|
64
|
+
homepage: https://github.com/neilvilela/embed
|
65
|
+
licenses: []
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
segments:
|
77
|
+
- 0
|
78
|
+
hash: -3637459664052554990
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ! '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
segments:
|
86
|
+
- 0
|
87
|
+
hash: -3637459664052554990
|
88
|
+
requirements: []
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 1.8.24
|
91
|
+
signing_key:
|
92
|
+
specification_version: 3
|
93
|
+
summary: An easy way to embed media to your Rails app
|
94
|
+
test_files: []
|