lumiere 0.1.2 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
data/lib/embed_code.rb ADDED
@@ -0,0 +1,55 @@
1
+ require 'open-uri'
2
+
3
+ module Lumiere
4
+ module EmbedCode
5
+ extend self
6
+
7
+ def embed_code(opts = {})
8
+ iframe_attributes = opts.fetch(:iframe_attributes, {})
9
+ url_attributes = opts.fetch(:url_attributes, {})
10
+
11
+ default_iframe_attributes = default_attributes.fetch(:iframe_attributes, {})
12
+ default_url_attributes = default_attributes.fetch(:url_attributes, {})
13
+
14
+ object_properties = default_iframe_attributes.merge(iframe_attributes)
15
+ url_properties = default_url_attributes.merge(url_attributes)
16
+
17
+ generate(embed_url, url_properties, object_properties)
18
+ end
19
+
20
+ private
21
+
22
+ def generate(src, url_properties={}, object_properties={})
23
+ src = generate_src(src, url_properties)
24
+ object_properties = {src: src}.merge(object_properties)
25
+ generate_html_object('iframe', object_properties)
26
+ end
27
+
28
+ def generate_src(src, url_properties)
29
+ if !url_properties.empty?
30
+ src += "?" + URI.encode_www_form(url_properties)
31
+ else
32
+ src
33
+ end
34
+ end
35
+
36
+ def generate_html_object(object_name, opts)
37
+ html_options = generate_object_properties(opts)
38
+ "<#{object_name} #{html_options}></#{object_name}>"
39
+ end
40
+
41
+ def generate_object_properties(opts={})
42
+ opts.map do |key, value|
43
+ generate_object_property(key, value)
44
+ end.join(' ')
45
+ end
46
+
47
+ def generate_object_property(key, value)
48
+ if value.is_a?(TrueClass)
49
+ key #set as 'option' rather than 'option=true'
50
+ else
51
+ "#{key}=\"#{value}\""
52
+ end
53
+ end
54
+ end
55
+ end
@@ -1,3 +1,3 @@
1
1
  module Lumiere
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.6"
3
3
  end
data/lib/lumiere.rb CHANGED
@@ -12,6 +12,7 @@ require_relative 'extended_uri'
12
12
  require_relative 'provider'
13
13
  require_relative 'playlist'
14
14
  require_relative 'fetcher'
15
+ require_relative 'embed_code'
15
16
 
16
17
  class Elluminate
17
18
  extend Forwardable
@@ -1,6 +1,7 @@
1
1
  module Lumiere
2
2
  class Dailymotion < Provider
3
3
  attr_accessor :url
4
+ include EmbedCode
4
5
 
5
6
  USEABLE = ['www.dailymotion.com', 'dailymotion.com']
6
7
 
@@ -29,8 +30,13 @@ class Dailymotion < Provider
29
30
  "//www.dailymotion.com/embed/video/#{video_id}"
30
31
  end
31
32
 
32
- def embed_code
33
- "<iframe frameborder=\"0\" src=\"#{embed_url}\" allowfullscreen></iframe>"
33
+ def default_attributes
34
+ {
35
+ iframe_attributes: {
36
+ frameborder: 0,
37
+ allowfullscreen: true
38
+ }
39
+ }
34
40
  end
35
41
 
36
42
  def title
@@ -1,6 +1,7 @@
1
1
  module Lumiere
2
2
  class Vimeo < Provider
3
3
  attr_accessor :url
4
+ include EmbedCode
4
5
 
5
6
  USEABLE = ['www.vimeo.com', 'vimeo.com', 'player.vimeo.com']
6
7
 
@@ -34,8 +35,15 @@ class Vimeo < Provider
34
35
  "//player.vimeo.com/video/#{video_id}"
35
36
  end
36
37
 
37
- def embed_code
38
- "<iframe src=\"#{embed_url}\" frameborder=\"0\" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>"
38
+ def default_attributes
39
+ {
40
+ iframe_attributes: {
41
+ frameborder: 0,
42
+ webkitallowfullscreen: true,
43
+ mozallowfullscreen: true,
44
+ allowfullscreen: true
45
+ }
46
+ }
39
47
  end
40
48
 
41
49
  def title
@@ -1,6 +1,7 @@
1
1
  module Lumiere
2
2
  class VimeoPlaylist < Provider
3
3
  attr_accessor :url
4
+ include EmbedCode
4
5
 
5
6
  USEABLE = ['vimeo.com', 'player.vimeo.com', 'www.vimeo.com']
6
7
  RESULTS_PER_REQUEST = 20
@@ -32,8 +33,11 @@ class VimeoPlaylist < Provider
32
33
  "//player.vimeo.com/hubnut/album/#{playlist_id}"
33
34
  end
34
35
 
35
- def embed_code
36
- "<iframe src=\"#{embed_url}?autoplay=0&byline=0&portrait=0&title=0\" frameborder=\"0\"></iframe>"
36
+ def default_attributes
37
+ {
38
+ iframe_attributes: { frameborder: 0 },
39
+ url_attributes: { autoplay: 0, byline: 0, portrait: 0, title: 0 }
40
+ }
37
41
  end
38
42
 
39
43
  def title
@@ -1,6 +1,7 @@
1
1
  module Lumiere
2
2
  class YouTube < Provider
3
3
  attr_accessor :url
4
+ include EmbedCode
4
5
 
5
6
  USEABLE = ['www.youtube.com', 'youtube.com', 'youtu.be']
6
7
 
@@ -34,8 +35,13 @@ class YouTube < Provider
34
35
  "//www.youtube.com/embed/#{video_id}"
35
36
  end
36
37
 
37
- def embed_code
38
- "<iframe src=\"#{embed_url}\" frameborder=\"0\" allowfullscreen></iframe>"
38
+ def default_attributes
39
+ { iframe_attributes:
40
+ {
41
+ frameborder: 0,
42
+ allowfullscreen: true
43
+ }
44
+ }
39
45
  end
40
46
 
41
47
  def thumbnail_small
@@ -1,6 +1,7 @@
1
1
  module Lumiere
2
2
  class YouTubePlaylist < Provider
3
3
  attr_accessor :url
4
+ include EmbedCode
4
5
 
5
6
  USEABLE = ['www.youtube.com', 'youtube.com', 'youtu.be']
6
7
  RESULTS_PER_REQUEST = 25
@@ -35,8 +36,13 @@ class YouTubePlaylist < Provider
35
36
  "//youtube.com/embed/?list=#{playlist_id}"
36
37
  end
37
38
 
38
- def embed_code
39
- "<iframe src=\"#{embed_url}\" frameborder=\"0\" allowfullscreen></iframe>"
39
+ def default_attributes
40
+ {
41
+ iframe_attributes: {
42
+ frameborder: 0,
43
+ allowfullscreen: true
44
+ }
45
+ }
40
46
  end
41
47
 
42
48
  def videos
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lumiere
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.6
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: 2014-05-06 00:00:00.000000000 Z
12
+ date: 2014-05-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: representable
@@ -146,6 +146,7 @@ extensions: []
146
146
  extra_rdoc_files: []
147
147
  files:
148
148
  - LICENSE.txt
149
+ - lib/embed_code.rb
149
150
  - lib/extended_uri.rb
150
151
  - lib/fetcher.rb
151
152
  - lib/lumiere/version.rb