embedda 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 +18 -0
- data/.rspec +2 -0
- data/.ruby-version +1 -0
- data/.travis.yml +12 -0
- data/Gemfile +10 -0
- data/README.md +8 -0
- data/Rakefile.rb +6 -0
- data/embedda.gemspec +16 -0
- data/lib/embedda.rb +29 -0
- data/spec/embedda_spec.rb +56 -0
- data/spec/spec_helper.rb +20 -0
- metadata +58 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
1.9.3-p385
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
data/Rakefile.rb
ADDED
data/embedda.gemspec
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
|
3
|
+
|
|
4
|
+
Gem::Specification.new do |gem|
|
|
5
|
+
gem.name = "embedda"
|
|
6
|
+
gem.version = '0.0.1'
|
|
7
|
+
gem.authors = ["Kasper Grubbe"]
|
|
8
|
+
gem.email = ["kaspergrubbe@gmail.com"]
|
|
9
|
+
gem.homepage = "http://github.com/kaspergrubbe/embedda"
|
|
10
|
+
gem.summary = %q{Embed content strings in your strings, and turn it to embed HTML!}
|
|
11
|
+
gem.description = %q{Embed content strings in your strings, and turn it to embed HTML!}
|
|
12
|
+
|
|
13
|
+
gem.files = `git ls-files`.split("\n")
|
|
14
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
15
|
+
gem.require_paths = ["lib"]
|
|
16
|
+
end
|
data/lib/embedda.rb
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
class String
|
|
2
|
+
def embedda
|
|
3
|
+
compiled = youtube_replace(self)
|
|
4
|
+
compiled = vimeo_replace(compiled)
|
|
5
|
+
|
|
6
|
+
return compiled
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
private
|
|
10
|
+
def youtube_replace(compiled)
|
|
11
|
+
compiled.gsub!(/<a[^>]*?youtube\.com\/watch\?v=([a-zA-Z0-9\-\_]+).*?<\/a>/i, youtube_player("\\1"))
|
|
12
|
+
compiled.gsub!(/[http|https]+:\/\/(?:www\.)?youtube\.com\/watch\?v=([a-zA-Z0-9\-\_]+)\S*/i, youtube_player("\\1"))
|
|
13
|
+
|
|
14
|
+
return compiled
|
|
15
|
+
end
|
|
16
|
+
def youtube_player(token)
|
|
17
|
+
"<iframe width=\"560\" height=\"315\" src=\"http://www.youtube.com/embed/#{token}\" frameborder=\"0\" allowfullscreen></iframe>"
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def vimeo_replace(compiled)
|
|
21
|
+
compiled.gsub!(/<a[^>]*?vimeo\.com\/(\d+).*?<\/a>/i, vimeo_player("\\1"))
|
|
22
|
+
compiled.gsub!(/[http|https]+:\/\/(?:www\.)?vimeo\.com\/(\d+)\S*/i, vimeo_player("\\1"))
|
|
23
|
+
|
|
24
|
+
return compiled
|
|
25
|
+
end
|
|
26
|
+
def vimeo_player(token)
|
|
27
|
+
"<iframe src=\"http://player.vimeo.com/video/#{token}\" width=\"500\" height=\"281\" frameborder=\"0\" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>"
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
require 'embedda'
|
|
3
|
+
|
|
4
|
+
describe "Embedda" do
|
|
5
|
+
context "Youtube-link" do
|
|
6
|
+
before(:all) do
|
|
7
|
+
@embed_string = '<iframe width="560" height="315" src="http://www.youtube.com/embed/dQw4w9WgXcQ" frameborder="0" allowfullscreen></iframe>'
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it "should embed when text have a link" do
|
|
11
|
+
story = "http://www.youtube.com/watch?v=dQw4w9WgXcQ".embedda
|
|
12
|
+
expect(story).to eq(@embed_string)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "should embed when also other text is present around link" do
|
|
16
|
+
story = "Hello, my name is Kasper: http://www.youtube.com/watch?v=dQw4w9WgXcQ <br/>And I am embedding links".embedda
|
|
17
|
+
expect(story).to eq("Hello, my name is Kasper: #{@embed_string} <br/>And I am embedding links")
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "should embed when text include anchor tag to Youtube" do
|
|
21
|
+
story = "<a href=\"http://www.youtube.com/watch?v=dQw4w9WgXcQ\">Look here for HalfLife3!</a>".embedda
|
|
22
|
+
expect(story).to eq(@embed_string)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "should embed when also other text is present around anchor tag" do
|
|
26
|
+
story = "Hello, my name is Kasper: <a href=\"http://www.youtube.com/watch?v=dQw4w9WgXcQ\">Look here for HalfLife3!</a> <br/>And I am embedding links".embedda
|
|
27
|
+
expect(story).to eq("Hello, my name is Kasper: #{@embed_string} <br/>And I am embedding links")
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
context "Vimeo-link" do
|
|
32
|
+
before(:all) do
|
|
33
|
+
@embed_string = "<iframe src=\"http://player.vimeo.com/video/20241459\" width=\"500\" height=\"281\" frameborder=\"0\" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>"
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "should embed when text have a link" do
|
|
37
|
+
story = "http://vimeo.com/20241459".embedda
|
|
38
|
+
expect(story).to eq(@embed_string)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it "should embed when also other text is present around link" do
|
|
42
|
+
story = "Hello, my name is Kasper: http://vimeo.com/20241459 <br/>And I am embedding links".embedda
|
|
43
|
+
expect(story).to eq("Hello, my name is Kasper: #{@embed_string} <br/>And I am embedding links")
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it "should embed when text include anchor tag to Youtube" do
|
|
47
|
+
story = "<a href=\"http://vimeo.com/20241459\">Look here for HalfLife3!</a>".embedda
|
|
48
|
+
expect(story).to eq(@embed_string)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it "should embed when also other text is present around anchor tag" do
|
|
52
|
+
story = "Hello, my name is Kasper: <a href=\"http://vimeo.com/20241459\">Look here for HalfLife3!</a> <br/>And I am embedding links".embedda
|
|
53
|
+
expect(story).to eq("Hello, my name is Kasper: #{@embed_string} <br/>And I am embedding links")
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
|
4
|
+
# loaded once.
|
|
5
|
+
#
|
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
|
7
|
+
require 'rubygems'
|
|
8
|
+
require 'bundler/setup'
|
|
9
|
+
|
|
10
|
+
RSpec.configure do |config|
|
|
11
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
|
12
|
+
config.run_all_when_everything_filtered = true
|
|
13
|
+
config.filter_run :focus
|
|
14
|
+
|
|
15
|
+
# Run specs in random order to surface order dependencies. If you find an
|
|
16
|
+
# order dependency and want to debug it, you can fix the order by providing
|
|
17
|
+
# the seed, which is printed after each run.
|
|
18
|
+
# --seed 1234
|
|
19
|
+
config.order = 'random'
|
|
20
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: embedda
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
prerelease:
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Kasper Grubbe
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2013-03-17 00:00:00.000000000 Z
|
|
13
|
+
dependencies: []
|
|
14
|
+
description: Embed content strings in your strings, and turn it to embed HTML!
|
|
15
|
+
email:
|
|
16
|
+
- kaspergrubbe@gmail.com
|
|
17
|
+
executables: []
|
|
18
|
+
extensions: []
|
|
19
|
+
extra_rdoc_files: []
|
|
20
|
+
files:
|
|
21
|
+
- .gitignore
|
|
22
|
+
- .rspec
|
|
23
|
+
- .ruby-version
|
|
24
|
+
- .travis.yml
|
|
25
|
+
- Gemfile
|
|
26
|
+
- README.md
|
|
27
|
+
- Rakefile.rb
|
|
28
|
+
- embedda.gemspec
|
|
29
|
+
- lib/embedda.rb
|
|
30
|
+
- spec/embedda_spec.rb
|
|
31
|
+
- spec/spec_helper.rb
|
|
32
|
+
homepage: http://github.com/kaspergrubbe/embedda
|
|
33
|
+
licenses: []
|
|
34
|
+
post_install_message:
|
|
35
|
+
rdoc_options: []
|
|
36
|
+
require_paths:
|
|
37
|
+
- lib
|
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
39
|
+
none: false
|
|
40
|
+
requirements:
|
|
41
|
+
- - ! '>='
|
|
42
|
+
- !ruby/object:Gem::Version
|
|
43
|
+
version: '0'
|
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
45
|
+
none: false
|
|
46
|
+
requirements:
|
|
47
|
+
- - ! '>='
|
|
48
|
+
- !ruby/object:Gem::Version
|
|
49
|
+
version: '0'
|
|
50
|
+
requirements: []
|
|
51
|
+
rubyforge_project:
|
|
52
|
+
rubygems_version: 1.8.23
|
|
53
|
+
signing_key:
|
|
54
|
+
specification_version: 3
|
|
55
|
+
summary: Embed content strings in your strings, and turn it to embed HTML!
|
|
56
|
+
test_files:
|
|
57
|
+
- spec/embedda_spec.rb
|
|
58
|
+
- spec/spec_helper.rb
|