embedda 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.ruby-version +1 -1
- data/README.md +22 -0
- data/embedda.gemspec +2 -2
- data/lib/embedda.rb +28 -4
- data/spec/embedda_spec.rb +49 -2
- metadata +3 -2
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.9.3-
|
1
|
+
1.9.3-p392
|
data/README.md
CHANGED
@@ -26,6 +26,28 @@ This gem adds `String#embedda` to Ruby strings. You use it like this:
|
|
26
26
|
=> "String heheh <iframe width=\"560\" height=\"315\" src=\"http://www.youtube.com/embed/BVtYSy83XXw\" frameborder=\"0\" allowfullscreen></iframe> yeah"
|
27
27
|
```
|
28
28
|
|
29
|
+
If you need only one of the parsers you can do like this:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
[2] pry(main)> "String heheh http://www.youtube.com/watch?v=BVtYSy83XXw yeah".embedda(:filters => :youtube)
|
33
|
+
=> "String heheh <iframe width=\"560\" height=\"315\" src=\"http://www.youtube.com/embed/BVtYSy83XXw\" frameborder=\"0\" allowfullscreen></iframe> yeah"
|
34
|
+
```
|
35
|
+
|
36
|
+
This is the default behavoir:
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
[2] pry(main)> "String heheh http://www.youtube.com/watch?v=BVtYSy83XXw yeah".embedda(:filters => [:youtube, :vimeo])
|
40
|
+
=> "String heheh <iframe width=\"560\" height=\"315\" src=\"http://www.youtube.com/embed/BVtYSy83XXw\" frameborder=\"0\" allowfullscreen></iframe> yeah"
|
41
|
+
```
|
42
|
+
|
43
|
+
## Supported embeds
|
44
|
+
|
45
|
+
Currently embedda can embed the following formats:
|
46
|
+
|
47
|
+
* Youtube
|
48
|
+
* Vimeo
|
49
|
+
* Soundcloud
|
50
|
+
|
29
51
|
## Links
|
30
52
|
|
31
53
|
Rubygems: https://rubygems.org/gems/embedda
|
data/embedda.gemspec
CHANGED
@@ -3,8 +3,8 @@ $:.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.
|
7
|
-
gem.authors = ["Kasper Grubbe"]
|
6
|
+
gem.version = '0.0.3'
|
7
|
+
gem.authors = ["Kasper Grubbe",'Christian Takle']
|
8
8
|
gem.email = ["kaspergrubbe@gmail.com"]
|
9
9
|
gem.homepage = "http://github.com/kaspergrubbe/embedda"
|
10
10
|
gem.summary = %q{Embed content strings in your strings, and turn it to embed HTML!}
|
data/lib/embedda.rb
CHANGED
@@ -1,7 +1,17 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
|
1
3
|
class String
|
2
|
-
def embedda
|
3
|
-
|
4
|
-
|
4
|
+
def embedda(options = {})
|
5
|
+
options = {:filters => [:youtube, :vimeo, :soundcloud]}.merge(options)
|
6
|
+
|
7
|
+
# Make sure that filters is an array because we allow the short form of
|
8
|
+
# "hello".embedda(:filters => :youtube) instead of "hello".embedda(:filters => [:youtube])
|
9
|
+
options[:filters] = Array(options[:filters])
|
10
|
+
|
11
|
+
compiled = self
|
12
|
+
compiled = youtube_replace(compiled) if options[:filters].include?(:youtube)
|
13
|
+
compiled = vimeo_replace(compiled) if options[:filters].include?(:vimeo)
|
14
|
+
compiled = soundcloud_replace(compiled) if options[:filters].include?(:soundcloud)
|
5
15
|
|
6
16
|
return compiled
|
7
17
|
end
|
@@ -26,4 +36,18 @@ class String
|
|
26
36
|
def vimeo_player(token)
|
27
37
|
"<iframe src=\"http://player.vimeo.com/video/#{token}\" width=\"500\" height=\"281\" frameborder=\"0\" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>"
|
28
38
|
end
|
29
|
-
|
39
|
+
|
40
|
+
def soundcloud_replace(compiled)
|
41
|
+
r = /(https?:\/\/(?:www.)?soundcloud.com\/[A-Za-z0-9]+(?:[-_][A-Za-z0-9]+)*(?!\/sets(?:\/|$))(?:\/[A-Za-z0-9]+(?:[-_][A-Za-z0-9]+)*){1,2}\/?)/i
|
42
|
+
compiled.gsub!(r) { |match| soundcloud_player(match) }
|
43
|
+
|
44
|
+
return compiled
|
45
|
+
end
|
46
|
+
|
47
|
+
def soundcloud_player(token)
|
48
|
+
url_encoded_string = CGI::escape(token)
|
49
|
+
|
50
|
+
# Note: added '&' ...?url=...&
|
51
|
+
"<iframe width=\"100%\" height=\"166\" scrolling=\"no\" frameborder=\"no\" src=\"https://w.soundcloud.com/player/?url=#{url_encoded_string}&color=ff6600&auto_play=false&show_artwork=false\"></iframe>"
|
52
|
+
end
|
53
|
+
end
|
data/spec/embedda_spec.rb
CHANGED
@@ -36,6 +36,16 @@ describe "Embedda" do
|
|
36
36
|
story = "\n\nMy suggestions for getting ready for the dreadful monday we all hate:\n\nhttp://www.youtube.com/watch?v=dQw4w9WgXcQ\n\n".embedda
|
37
37
|
expect(story).to eq("\n\nMy suggestions for getting ready for the dreadful monday we all hate:\n\n#{@embed_string}\n\n")
|
38
38
|
end
|
39
|
+
|
40
|
+
it "should embed when enabled" do
|
41
|
+
story = "Hello, my name is Kasper: <b><a href=\"http://www.youtube.com/watch?v=dQw4w9WgXcQ\">Look here for HalfLife3!</a><br/></b>And I am embedding links".embedda(:filters => :youtube)
|
42
|
+
expect(story).to eq("Hello, my name is Kasper: <b>#{@embed_string}<br/></b>And I am embedding links")
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should not embed when disabled" do
|
46
|
+
story = "Hello, my name is Kasper: <b><a href=\"http://www.youtube.com/watch?v=dQw4w9WgXcQ\">Look here for HalfLife3!</a><br/></b>And I am embedding links".embedda(:filters => :vimeo)
|
47
|
+
expect(story).to eq("Hello, my name is Kasper: <b><a href=\"http://www.youtube.com/watch?v=dQw4w9WgXcQ\">Look here for HalfLife3!</a><br/></b>And I am embedding links")
|
48
|
+
end
|
39
49
|
end
|
40
50
|
|
41
51
|
context "Vimeo-link" do
|
@@ -53,7 +63,7 @@ describe "Embedda" do
|
|
53
63
|
expect(story).to eq("Hello, my name is Kasper: #{@embed_string}<br/>And I am embedding links")
|
54
64
|
end
|
55
65
|
|
56
|
-
it "should embed when text include anchor tag to
|
66
|
+
it "should embed when text include anchor tag to Vimeo" do
|
57
67
|
story = "<a href=\"http://vimeo.com/20241459\">Look here for HalfLife3!</a>".embedda
|
58
68
|
expect(story).to eq(@embed_string)
|
59
69
|
end
|
@@ -62,5 +72,42 @@ describe "Embedda" do
|
|
62
72
|
story = "Hello, my name is Kasper: <a href=\"http://vimeo.com/20241459\">Look here for HalfLife3!</a><br/>And I am embedding links".embedda
|
63
73
|
expect(story).to eq("Hello, my name is Kasper: #{@embed_string}<br/>And I am embedding links")
|
64
74
|
end
|
75
|
+
|
76
|
+
it "should embed when enabled" do
|
77
|
+
story = "Hello, my name is Kasper: <a href=\"http://vimeo.com/20241459\">Look here for HalfLife3!</a><br/>And I am embedding links".embedda(:filters => :vimeo)
|
78
|
+
expect(story).to eq("Hello, my name is Kasper: #{@embed_string}<br/>And I am embedding links")
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should not embed when disabled" do
|
82
|
+
story = "Hello, my name is Kasper: <a href=\"http://vimeo.com/20241459\">Look here for HalfLife3!</a><br/>And I am embedding links".embedda(:filters => :youtube)
|
83
|
+
expect(story).to eq("Hello, my name is Kasper: <a href=\"http://vimeo.com/20241459\">Look here for HalfLife3!</a><br/>And I am embedding links")
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context "Soundcloud-link" do
|
88
|
+
before(:all) do
|
89
|
+
@embed_string = "<iframe width=\"100%\" height=\"166\" scrolling=\"no\" frameborder=\"no\" src=\"https://w.soundcloud.com/player/?url=https%3A%2F%2Fsoundcloud.com%2Fflume-1%2Fflume-left-alone-bobby-tank&color=ff6600&auto_play=false&show_artwork=false\"></iframe>"
|
90
|
+
@link = "https://soundcloud.com/flume-1/flume-left-alone-bobby-tank"
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should embed when text have a link" do
|
94
|
+
story = @link.embedda
|
95
|
+
expect(story).to eq(@embed_string)
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should embed when also other text is present around link" do
|
99
|
+
story = "Hello, my name is Takle: #{@link}<br/>And I am embedding links".embedda
|
100
|
+
expect(story).to eq("Hello, my name is Takle: #{@embed_string}<br/>And I am embedding links")
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should embed when enabled" do
|
104
|
+
story = "Hello, my name is Takle: #{@link}<br/>And I am embedding links".embedda(:filters => :soundcloud)
|
105
|
+
expect(story).to eq("Hello, my name is Takle: #{@embed_string}<br/>And I am embedding links")
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should not embed when disabled" do
|
109
|
+
story = "Hello, my name is Takle: #{@link}<br/>And I am not embedding links".embedda(:filters => :youtube)
|
110
|
+
expect(story).to eq("Hello, my name is Takle: #{@link}<br/>And I am not embedding links")
|
111
|
+
end
|
65
112
|
end
|
66
|
-
end
|
113
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: embedda
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Kasper Grubbe
|
9
|
+
- Christian Takle
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date: 2013-
|
13
|
+
date: 2013-04-09 00:00:00.000000000 Z
|
13
14
|
dependencies: []
|
14
15
|
description: Embed content strings in your strings, and turn it to embed HTML!
|
15
16
|
email:
|