Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
kaspergrubbe committed Mar 17, 2013
1 parent d915b61 commit fad6d85
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--color
--format progress
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.9.3-p385
18 changes: 18 additions & 0 deletions embedda.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)

Gem::Specification.new do |gem|
gem.name = "embedda"
gem.version = '0.0.1'
gem.authors = ["Kasper Grubbe"]
gem.email = ["[email protected]"]
gem.homepage = "http://github.com/kaspergrubbe/embedda"
gem.summary = %q{Embed content strings in your strings, and turn it to embed HTML!}
gem.description = %q{Embed content strings in your strings, and turn it to embed HTML!}

gem.files = `git ls-files`.split("\n")
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
gem.require_paths = ["lib"]

#gem.add_runtime_dependency 'bundler'
end
27 changes: 27 additions & 0 deletions lib/embedda.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
class String
def embedda
youtube_replace!
vimeo_replace!
end

private
def youtube_replace!
self.gsub(/[http|https]+:\/\/(?:www\.)?youtube\.com\/watch\?v=([a-zA-Z0-9\-\_]+)\S*/, youtube_player("\\1"))
self.gsub(/<a[^>]*?youtube\.com\/watch\?sv=([a-zA-Z0-9\-\_]+).*?<\/a>/, youtube_player("\\1"))
end
def youtube_player(token)
return <<-END
<iframe width="560" height="315" src="http://www.youtube.com/embed/#{token}" frameborder="0" allowfullscreen></iframe>
END
end

def vimeo_replace!
self.gsub(/[http|https]+:\/\/(?:www\.)?vimeo\.com\/(\d+)\S*/, vimeo_player("\\1"))
self.gsub(/<a[^>]*?vimeo\.com\/(\d+).*?<\/a>/, vimeo_player("\\1"))
end
def vimeo_player(token)
return <<-END
<iframe src="http://player.vimeo.com/video/#{token}" width="500" height="281" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>
END
end
end

0 comments on commit fad6d85

Please sign in to comment.