Easily embed content in a string from Youtube or Vimeo by writing a simple string
Add this to your Gemfile
:
gem 'embedda'
And remember to bundle
This gem adds String#embedda
to Ruby strings. You use it like this:
[2] pry(main)> "String heheh http://www.youtube.com/watch?v=BVtYSy83XXw yeah".embedda
=> "String heheh <iframe width=\"560\" height=\"315\" src=\"http://www.youtube.com/embed/BVtYSy83XXw\" frameborder=\"0\" allowfullscreen></iframe> yeah"
If you need only one of the parsers you can do like this:
[2] pry(main)> "String heheh http://www.youtube.com/watch?v=BVtYSy83XXw yeah".embedda(:filters => :youtube)
=> "String heheh <iframe width=\"560\" height=\"315\" src=\"http://www.youtube.com/embed/BVtYSy83XXw\" frameborder=\"0\" allowfullscreen></iframe> yeah"
This is the default behavoir:
[2] pry(main)> "String heheh http://www.youtube.com/watch?v=BVtYSy83XXw yeah".embedda(:filters => [:youtube, :vimeo])
=> "String heheh <iframe width=\"560\" height=\"315\" src=\"http://www.youtube.com/embed/BVtYSy83XXw\" frameborder=\"0\" allowfullscreen></iframe> yeah"
You can enforce https URLs (useful on SSL-secured sites):
[2] pry(main)> "String heheh http://www.youtube.com/watch?v=BVtYSy83XXw yeah".embedda(ssl: true)
=> "String heheh <iframe width=\"560\" height=\"315\" src=\"https://www.youtube.com/embed/BVtYSy83XXw\" frameborder=\"0\" allowfullscreen></iframe> yeah"
Currently embedda can embed the following formats:
- Youtube
- Vimeo
- Soundcloud
Rubygems: https://rubygems.org/gems/embedda