vimeo_embed 0.0.1.alpha → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## v0.0.1
2
+
3
+ * First Release
data/README.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # VimeoEmbed
2
2
 
3
- TODO: Write a gem description
3
+ Embed vimeo videos in on site saving URL and get relevant output in view
4
+
5
+ 1. Simple Embed
6
+
7
+ 2. Embed with title, description & thumbnail
4
8
 
5
9
  ## Installation
6
10
 
@@ -16,9 +20,39 @@ Or install it yourself as:
16
20
 
17
21
  $ gem install vimeo_embed
18
22
 
23
+ And add CSS and JS
24
+
25
+ CSS in application.css
26
+
27
+ *= require vimeo_embed
28
+
29
+ JS in application.js
30
+
31
+ //= require vimeo_embed
32
+
19
33
  ## Usage
20
34
 
21
- TODO: Write usage instructions here
35
+ It can be used in model where we can specify simple iframe embed or embedding with thumbnail & description
36
+
37
+ Simple:
38
+
39
+ vimeo_embed :field_name, {:with_description => false, :width => 450, :height => 300}
40
+
41
+ With Thumbnail & Description:
42
+
43
+ vimeo_embed :field_name, {:with_description => true, :width => 450, :height => 300}
44
+
45
+
46
+ This will modify the vimeo 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:
47
+
48
+ <?= VimeoEmbed::vimeo_embed(attr_here, {:with_description => true, :width => 450, :height => 300}) ?>
49
+
50
+
51
+ Working on further improvements
52
+
53
+ ## Contributing
54
+
55
+ vimeo_embed
22
56
 
23
57
  ## Contributing
24
58
 
@@ -0,0 +1,6 @@
1
+ module VimeoEmbed
2
+ class Base
3
+ include HTTParty
4
+ base_uri 'vimeo.com/api/v2'
5
+ end # Base
6
+ end # VimeoEmbed
@@ -0,0 +1,7 @@
1
+ module VimeoEmbed
2
+ class Engine < ::Rails::Engine
3
+ initializer 'vimeo_embed.load_static_assets' do |app|
4
+ app.middleware.use ::ActionDispatch::Static, "#{root}/vendor"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ module VimeoEmbed
2
+ module ModelAdditions
3
+ def vimeo_embed(attribute, options)
4
+ before_validation do
5
+ send("#{attribute}=", VimeoEmbed.vimeo_embed(send(attribute), options))
6
+ end
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ module VimeoEmbed
2
+ class Railtie < Rails::Railtie
3
+ initializer 'vimeo_embed.model_additions' do
4
+ ActiveSupport.on_load :active_record do
5
+ extend ModelAdditions
6
+ end
7
+ end
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module VimeoEmbed
2
- VERSION = "0.0.1.alpha"
2
+ VERSION = "0.0.1"
3
3
  end
@@ -0,0 +1,11 @@
1
+ module VimeoEmbed
2
+ class VideoDetails < VimeoEmbed::Base
3
+ # Returns video information
4
+ #
5
+ # @param [String] video_id The vimeo video's id.
6
+ def self.info(video_id)
7
+ get("/video/#{video_id}.json")
8
+ end
9
+
10
+ end
11
+ end
data/lib/vimeo_embed.rb CHANGED
@@ -1,5 +1,78 @@
1
+ require 'httparty'
1
2
  require "vimeo_embed/version"
3
+ require "vimeo_embed/model_additions"
4
+ require "vimeo_embed/base"
5
+ require "vimeo_embed/video_details"
6
+ require "vimeo_embed/railtie" if defined? Rails
7
+ require "vimeo_embed/engine"
2
8
 
3
9
  module VimeoEmbed
4
- # Your code goes here...
10
+
11
+ def self.get_video_id(url)
12
+ url.strip!
13
+ return url.gsub(/https?:\/\/?(?:www\.)?vimeo\.com\/?(\d+)/i, '\1')
14
+ end
15
+
16
+ def self.vimeo_embed(data, options = {:with_description => true, :height => 200, :width => 300})
17
+ if data.match(/https?:\/\/?(?:www\.)?vimeo\.com/)
18
+ data = data.gsub(/<a?[^<]+ href="[(https?:\/\/)?(www\.)?vimeo.com[^<]+]+">([^<]+)<\/a>/i, '\1')
19
+ if options[:with_description]
20
+ data = data.gsub(/(https?:\/\/?(?:www\.)?vimeo\.com\/\d+)/i, thumbnail_and_description("#{$1}", options[:width], options[:height]))
21
+ else
22
+ data = data.gsub(/(https?:\/\/?(?:www\.)?vimeo\.com\/\d+)/i, simple("#{$1}", options[:width], options[:height]))
23
+ end
24
+ end
25
+ return data
26
+ end
27
+
28
+ def self.thumbnail_and_description(video_url, width, height)
29
+ begin
30
+ if video_url.to_s != ' '
31
+ video_id = get_video_id(video_url)
32
+ if video_id.present?
33
+ video_details = VimeoEmbed::VideoDetails.info(video_id)
34
+ return %Q{<div class="vimeo_embed_video">
35
+ <div class="vimeo_embed_partial_video">
36
+ <div class="vimeo_embed_thumbnail">
37
+ <img src="#{video_details[0]["thumbnail_small"] ? video_details[0]["thumbnail_small"] : ""}" />
38
+ </div>
39
+ <div class="vimeo_embed_details">
40
+ <div class="vimeo_embed_title">
41
+ <strong>
42
+ #{video_details[0]["title"] ? video_details[0]["title"] : ""}
43
+ </strong>
44
+ </div>
45
+ <div class="vimeo_embed_description">
46
+ #{video_details[0]["description"] ? video_details[0]["description"].truncate(185) : ""}
47
+ </div>
48
+ </div>
49
+ </div>
50
+ <div class="vimeo_embed_main_video" style="display:none;">
51
+ <iframe title="Vimeo player" width="#{ width }" height="#{ height }" src="http://player.vimeo.com/video/#{ video_id }" frameborder="0" allowfullscreen></iframe>
52
+ </div>
53
+ </div>}
54
+ else
55
+ return video_url
56
+ end
57
+ end
58
+ rescue Exception => e
59
+ Rails.logger.debug e.message
60
+ end
61
+ end
62
+
63
+ def self.simple(video_url, width, height)
64
+ begin
65
+ if video_url.to_s != ' '
66
+ video_id = get_video_id(video_url)
67
+ if video_id.present?
68
+ return %Q{<div class="vimeo_embed_video"><iframe title="Vimeo player" width="#{ width }" height="#{ height }" src="http://player.vimeo.com/video/#{ video_id }" frameborder="0" allowfullscreen></iframe></div>}
69
+ else
70
+ return video_url
71
+ end
72
+ end
73
+ rescue Exception => e
74
+ Rails.logger.debug e.message
75
+ end
76
+ end
77
+
5
78
  end
@@ -0,0 +1,6 @@
1
+ $('.vimeo_embed_partial_video').live('click', function() {
2
+ $(this).hide();
3
+ var parent = $(this).parent();
4
+ $(".vimeo_embed_main_video iframe", parent).attr('src', $(".vimeo_embed_main_video iframe", parent).attr('src') + '?autoplay=1');
5
+ $(".vimeo_embed_main_video", parent).show();
6
+ });
@@ -0,0 +1,24 @@
1
+ .vimeo_embed_video {
2
+ float:left;
3
+ width:100%;
4
+ }
5
+ .vimeo_embed_partial_video {
6
+ cursor:pointer;
7
+ }
8
+ .vimeo_embed_thumbnail {
9
+ float:left;
10
+ width:120px;
11
+ padding-right:10px;
12
+ }
13
+ .vimeo_embed_details {
14
+ float:left;
15
+ width:300px;
16
+ }
17
+ .vimeo_embed_details .vimeo_embed_title {
18
+ float:left;
19
+ width:100%;
20
+ }
21
+ .vimeo_embed_details .vimeo_embed_description {
22
+ float:left;
23
+ width:100%;
24
+ }
data/vimeo_embed.gemspec CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |gem|
8
8
  gem.version = VimeoEmbed::VERSION
9
9
  gem.authors = ["Mohit Sharma"]
10
10
  gem.email = ["developer.pht@gmail.com"]
11
- gem.description = %q{Embedding vimeo videos}
11
+ gem.description = %q{Embedding vimeo simple and with title, thumbnail and description}
12
12
  gem.summary = %q{Embedding vimeo videos}
13
13
  gem.homepage = ""
14
14
 
@@ -16,4 +16,7 @@ Gem::Specification.new do |gem|
16
16
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ["lib"]
19
+ gem.add_runtime_dependency "httparty"
20
+ gem.add_development_dependency "rake"
21
+ gem.add_development_dependency "rspec"
19
22
  end
metadata CHANGED
@@ -1,17 +1,65 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vimeo_embed
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.alpha
5
- prerelease: 6
4
+ version: 0.0.1
5
+ prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Mohit Sharma
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-27 00:00:00.000000000 Z
13
- dependencies: []
14
- description: Embedding vimeo videos
12
+ date: 2013-05-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
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
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Embedding vimeo simple and with title, thumbnail and description
15
63
  email:
16
64
  - developer.pht@gmail.com
17
65
  executables: []
@@ -19,12 +67,20 @@ extensions: []
19
67
  extra_rdoc_files: []
20
68
  files:
21
69
  - .gitignore
70
+ - CHANGELOG.md
22
71
  - Gemfile
23
72
  - LICENSE.txt
24
73
  - README.md
25
74
  - Rakefile
26
75
  - lib/vimeo_embed.rb
76
+ - lib/vimeo_embed/base.rb
77
+ - lib/vimeo_embed/engine.rb
78
+ - lib/vimeo_embed/model_additions.rb
79
+ - lib/vimeo_embed/railtie.rb
27
80
  - lib/vimeo_embed/version.rb
81
+ - lib/vimeo_embed/video_details.rb
82
+ - vendor/assets/javascripts/vimeo_embed.js
83
+ - vendor/assets/stylesheets/vimeo_embed.css
28
84
  - vimeo_embed.gemspec
29
85
  homepage: ''
30
86
  licenses: []
@@ -41,9 +97,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
41
97
  required_rubygems_version: !ruby/object:Gem::Requirement
42
98
  none: false
43
99
  requirements:
44
- - - ! '>'
100
+ - - ! '>='
45
101
  - !ruby/object:Gem::Version
46
- version: 1.3.1
102
+ version: '0'
47
103
  requirements: []
48
104
  rubyforge_project:
49
105
  rubygems_version: 1.8.24