Skip to content

Commit

Permalink
youtube filter support https
Browse files Browse the repository at this point in the history
  • Loading branch information
dejan committed Dec 8, 2011
1 parent bf52092 commit 2d60a36
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Expand Up @@ -4,7 +4,6 @@
* Rake task for rebuilding cached markup
* default youtube embed code should be the same as provide by youtube.com; wmode is no longer default param
* reducing dependencies - do not bundle RedCloth filter. Redcarpet (markdown) is default choice for markup and planned for more usage internally, so the lib goes with only that.
*

## 1.4.2, released 2011-08-12
* Add support for YouTube short url
Expand Down
7 changes: 4 additions & 3 deletions lib/auto_html/filters/youtube.rb
@@ -1,12 +1,13 @@
AutoHtml.add_filter(:youtube).with(:width => 420, :height => 315, :frameborder => 0, :wmode => nil) do |text, options|
regex = /http:\/\/(www.)?youtube\.com\/watch\?v=([A-Za-z0-9_-]*)(\&\S+)?|http:\/\/(www.)?youtu\.be\/([A-Za-z0-9_-]*)?/
regex = /(https?):\/\/(www.)?(youtube\.com\/watch\?v=|youtu\.be\/)([A-Za-z0-9_-]*)(\&\S+)?/
text.gsub(regex) do
youtube_id = $2 || $5
protocol = $1
youtube_id = $4
width = options[:width]
height = options[:height]
frameborder = options[:frameborder]
wmode = options[:wmode]
src = "http://www.youtube.com/embed/#{youtube_id}"
src = "#{protocol}://www.youtube.com/embed/#{youtube_id}"
src += "?wmode=#{wmode}" if wmode
%{<iframe width="#{width}" height="#{height}" src="#{src}" frameborder="#{frameborder}" allowfullscreen></iframe>}
end
Expand Down
5 changes: 5 additions & 0 deletions test/unit/filters/youtube_test.rb
Expand Up @@ -31,4 +31,9 @@ def test_transform_with_short_url
result = auto_html('http://www.youtu.be/BwNrmYRiX_o') { youtube }
assert_equal '<iframe width="420" height="315" src="http://www.youtube.com/embed/BwNrmYRiX_o" frameborder="0" allowfullscreen></iframe>', result
end

def test_transform_https
result = auto_html("https://www.youtube.com/watch?v=t7NdBIA4zJg") { youtube }
assert_equal '<iframe width="420" height="315" src="https://www.youtube.com/embed/t7NdBIA4zJg" frameborder="0" allowfullscreen></iframe>', result
end
end

0 comments on commit 2d60a36

Please sign in to comment.