Project

embedda

0.0
No commit activity in last 3 years
No release in over 3 years
Embed content strings in your strings, and turn it to embed HTML!
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0

Runtime

>= 0
 Project Readme

embedda

Easily embed content in a string from Youtube or Vimeo by writing a simple string

Tests:

Build Status

Install

Add this to your Gemfile:

gem 'embedda'

And remember to bundle

Usage

If you want to extend Ruby String#embedda add the following.

require 'embedda'

class String
  def embedda(options = {})
    Embedda.new(self, options).embed
  end
end

Its best practice not to extend core objects and use the Embedda class itself. Examples are written with the String extended. You use it like this:

"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:

"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:

"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):

"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"

You can set video width and height with proper settings:

"http://www.youtube.com/watch?v=BVtYSy83XXw yeah".embedda(video_width: 600, video_height: 300)
=> "String heheh <iframe width=\"600\" height=\"300\" src=\"https://www.youtube.com/embed/BVtYSy83XXw\" frameborder=\"0\" allowfullscreen></iframe> yeah"

You can set vimeo query string with vimeo_params option:

"http://vimeo.com/42620553".embedda(:vimeo_params => {:title => 0, :byline => 0, :portrait => 0, :color => "42b7ed"})
=> %q{<iframe src="http://player.vimeo.com/video/20241459?title=0&byline=0&portrait=0&color=42b7ed" width="560" height="315" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>}

Supported embeds

Currently embedda can embed the following formats:

  • Youtube
  • Vimeo
  • Soundcloud

Links

Rubygems: https://rubygems.org/gems/embedda