embedda 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
@@ -0,0 +1 @@
1
+ 1.9.3-p385
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 1.9.3
5
+ - 1.9.2
6
+ - 1.9.1
7
+ - jruby-18mode # JRuby in 1.8 mode
8
+ - jruby-19mode # JRuby in 1.9 mode
9
+ - rbx-18mode
10
+ - rbx-19mode
11
+ - 1.8.7
12
+ - ree
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :test, :development do
6
+ gem 'pry'
7
+ gem 'bundler'
8
+ gem 'rake'
9
+ gem 'rspec'
10
+ end
@@ -0,0 +1,8 @@
1
+ embedda
2
+ =======
3
+
4
+ Easily embed content in a string from Youtube or Vimeo by writing a simple string
5
+
6
+ ## Tests:
7
+
8
+ [![Build Status](https://travis-ci.org/kaspergrubbe/embedda.png)](https://travis-ci.org/kaspergrubbe/embedda)
@@ -0,0 +1,6 @@
1
+ require 'rake'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -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
@@ -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
@@ -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