embedda 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -54,6 +54,13 @@ You can set video width and height with proper settings:
54
54
  => "String heheh <iframe width=\"600\" height=\"300\" src=\"https://www.youtube.com/embed/BVtYSy83XXw\" frameborder=\"0\" allowfullscreen></iframe> yeah"
55
55
  ```
56
56
 
57
+ You can set vimeo query string with `vimeo_params` option:
58
+
59
+ ```ruby
60
+ "http://vimeo.com/42620553".embedda(:vimeo_params => {:title => 0, :byline => 0, :portrait => 0, :color => "42b7ed"})
61
+ => %q{<iframe src="http://player.vimeo.com/video/20241459?title=0&byline=0&portrait=0&color=42b7ed" width="560" height="315" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>}
62
+ ```
63
+
57
64
  ## Supported embeds
58
65
 
59
66
  Currently embedda can embed the following formats:
data/embedda.gemspec CHANGED
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |gem|
5
5
  gem.name = "embedda"
6
- gem.version = '0.0.5'
6
+ gem.version = '0.0.6'
7
7
  gem.authors = ["Kasper Grubbe",'Christian Takle']
8
8
  gem.email = ["kaspergrubbe@gmail.com"]
9
9
  gem.homepage = "http://github.com/kaspergrubbe/embedda"
@@ -13,4 +13,7 @@ Gem::Specification.new do |gem|
13
13
  gem.files = `git ls-files`.split("\n")
14
14
  gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
15
  gem.require_paths = ["lib"]
16
+
17
+ gem.add_development_dependency "rspec"
18
+ gem.add_runtime_dependency "rack"
16
19
  end
@@ -14,7 +14,7 @@ class Embedda
14
14
  def get(filter_name)
15
15
  case filter_name
16
16
  when :vimeo
17
- Vimeo.new(protocol, video_width, video_height)
17
+ Vimeo.new(protocol, video_width, video_height, vimeo_params)
18
18
  when :youtube
19
19
  Youtube.new(protocol, video_width, video_height)
20
20
  when :soundcloud
@@ -38,6 +38,10 @@ class Embedda
38
38
  options.fetch(:video_height, 315)
39
39
  end
40
40
 
41
+ def vimeo_params
42
+ options.fetch(:vimeo_params, nil)
43
+ end
44
+
41
45
  end
42
46
  end
43
47
  end
@@ -1,10 +1,14 @@
1
+ require 'rack'
2
+ require 'uri'
3
+
1
4
  class Embedda
2
5
  module Filters
3
6
  class Vimeo
4
- def initialize(protocol, width, height)
7
+ def initialize(protocol, width, height, vimeo_params)
5
8
  @protocol = protocol
6
9
  @width = width
7
10
  @height = height
11
+ @vimeo_params= vimeo_params
8
12
  end
9
13
 
10
14
  def process(string)
@@ -16,7 +20,19 @@ class Embedda
16
20
  private
17
21
 
18
22
  def player(token)
19
- %Q{<iframe src="#{@protocol}://player.vimeo.com/video/#{token}" width="#{@width}" height="#{@height}" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>}
23
+ %Q{<iframe src="#{player_url(token)}" width="#{@width}"#{height_attribute} frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>}
24
+ end
25
+
26
+ def player_url(token)
27
+ url = URI.parse("http://player.vimeo.com/")
28
+ url.scheme = @protocol
29
+ url.path = "/video/#{token}"
30
+ url.query = Rack::Utils.build_query @vimeo_params if @vimeo_params
31
+ url.to_s
32
+ end
33
+
34
+ def height_attribute
35
+ %Q{ height="#{@height}"} if @height
20
36
  end
21
37
  end
22
38
  end
data/spec/embedda_spec.rb CHANGED
@@ -1,4 +1,7 @@
1
1
  require "spec_helper"
2
+ require "rack"
3
+ require "uri"
4
+
2
5
  require "embedda"
3
6
 
4
7
  describe Embedda do
@@ -68,6 +71,8 @@ describe Embedda do
68
71
  let(:embed_string) { '<iframe src="http://player.vimeo.com/video/20241459" width="560" height="315" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>' }
69
72
  let(:https_embed_string) { embed_string.gsub("http", "https") }
70
73
  let(:horizontal_embed_string) { embed_string.gsub("560", "200").gsub("315", "400") }
74
+ let(:query_string_embed) { embed_string.gsub("20241459", "20241459?title=0&byline=0&portrait=0&color=42b7ed") }
75
+ let(:no_height_embed) { embed_string.gsub(%q{height="315" }, "") }
71
76
 
72
77
  it "should embed when text have a link" do
73
78
  @story = "http://vimeo.com/20241459"
@@ -111,6 +116,20 @@ describe Embedda do
111
116
  embedda = described_class.new(@story, :video_width => 200, :video_height => 400).embed
112
117
  expect(embedda).to eq(horizontal_embed_string)
113
118
  end
119
+
120
+ it 'generates iframe with query string' do
121
+ @story = "http://vimeo.com/20241459"
122
+ vimeo_params = {:title => 0, :byline => 0, :portrait => 0, :color => "42b7ed"}
123
+ embedda = described_class.new(@story, :vimeo_params => vimeo_params).embed
124
+ vimeo_expected_params = {"title" => "0", "byline" => "0", "portrait" => "0", "color" => "42b7ed"}
125
+ Rack::Utils.parse_query( URI.parse(embedda.split('"')[1]).query ).should == vimeo_expected_params
126
+ end
127
+
128
+ it 'generates iframe without height attribute when height is falsy' do
129
+ @story = "http://vimeo.com/20241459"
130
+ embedda = described_class.new(@story, :video_height => false).embed
131
+ expect(embedda).to eq(no_height_embed)
132
+ end
114
133
  end
115
134
 
116
135
  context "Soundcloud-link" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embedda
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,8 +10,40 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-08-29 00:00:00.000000000 Z
14
- dependencies: []
13
+ date: 2013-08-30 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
31
+ - !ruby/object:Gem::Dependency
32
+ name: rack
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ type: :runtime
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
15
47
  description: Embed content strings in your strings, and turn it to embed HTML!
16
48
  email:
17
49
  - kaspergrubbe@gmail.com