Skip to content
This repository has been archived by the owner on Dec 1, 2021. It is now read-only.

add hide_related option #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/auto_html/youtube.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ module AutoHtml
class YouTube
include TagHelper

def initialize(width: 420, height: 315)
def initialize(width: 420, height: 315, hide_related: false)
@width = width
@height = height
@hide_related = hide_related
end

def call(text)
Expand Down Expand Up @@ -37,6 +38,9 @@ def youtube_pattern

def iframe_attributes(youtube_id)
src = "//www.youtube.com/embed/#{youtube_id}"
params = []
params << "rel=0" if @hide_related
src += "?#{params.join '&'}" unless params.empty?
{
width: @width,
height: @height,
Expand Down
6 changes: 6 additions & 0 deletions spec/auto_html/youtube_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,10 @@
result = subject.call('www.youtube.com/watch?v=t7NdBIA4zJg')
expect(result).to eq '<div class="video youtube"><iframe width="420" height="315" src="//www.youtube.com/embed/t7NdBIA4zJg" frameborder="0" allowfullscreen="yes"></iframe></div>'
end

it 'transforms url with hide_related options' do
filter = described_class.new(hide_related: true)
result = filter.call('www.youtube.com/watch?v=t7NdBIA4zJg')
expect(result).to eq '<div class="video youtube"><iframe width="420" height="315" src="//www.youtube.com/embed/t7NdBIA4zJg?rel=0" frameborder="0" allowfullscreen="yes"></iframe></div>'
end
end