auto_html 1.6.3 → 1.6.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ AutoHtml.add_filter(:youtube_image).with(:width => 320, :height => 315, :style => 'medium', :target => 'blank', :border => '0') do |text, options|
2
+ styles = { 'default' => 'default', 'high' => 'hqdefault',
3
+ 'medium' => 'mqdefault', 'normal' => 'sddefault',
4
+ 'max' => 'maxresdefault' }
5
+ regex = /(https?:\/\/)?(www.)?(youtube\.com\/watch\?v=|youtu\.be\/|youtube\.com\/watch\?feature=player_embedded&v=)([A-Za-z0-9_-]*)(\&\S+)?(\?\S+)?/
6
+ text.gsub(regex) do
7
+ youtube_id = $4
8
+ video_url = "https://www.youtube.com/watch?v=#{youtube_id}"
9
+ target = options[:target]
10
+ width = options[:width]
11
+ height = options[:height]
12
+ border = options[:border]
13
+ style = styles[options[:style]] rescue styles['default']
14
+ src = "//img.youtube.com/vi/#{youtube_id}/#{style}.jpg"
15
+ %{<div class="thumbnail youtube"><a href="#{video_url}" target="_#{target}"><img src="#{src}" width="#{width}" height="#{height}" border="#{border}"></a></div>}
16
+ end
17
+ end
@@ -0,0 +1,59 @@
1
+ require File.expand_path('../../unit_test_helper', __FILE__)
2
+
3
+ class YouTubeImageTest < Test::Unit::TestCase
4
+
5
+ def test_transform
6
+ result = auto_html('http://www.youtube.com/watch?v=BwNrmYRiX_o') { youtube_image }
7
+ assert_equal '<div class="thumbnail youtube"><a href="https://www.youtube.com/watch?v=BwNrmYRiX_o" target="_blank"><img src="//img.youtube.com/vi/BwNrmYRiX_o/mqdefault.jpg" width="320" height="315" border="0"></a></div>', result
8
+ end
9
+
10
+ def test_transform2
11
+ result = auto_html('http://www.youtube.com/watch?v=BwNrmYRiX_o&eurl=http%3A%2F%2Fvukajlija.com%2Fvideo%2Fklipovi%3Fstrana%3D6&feature=player_embedded') { youtube_image }
12
+ assert_equal '<div class="thumbnail youtube"><a href="https://www.youtube.com/watch?v=BwNrmYRiX_o" target="_blank"><img src="//img.youtube.com/vi/BwNrmYRiX_o/mqdefault.jpg" width="320" height="315" border="0"></a></div>', result
13
+ end
14
+
15
+ def test_transform3
16
+ result = auto_html('http://www.youtube.com/watch?v=BwNrmYRiX_o&feature=related') { youtube_image }
17
+ assert_equal '<div class="thumbnail youtube"><a href="https://www.youtube.com/watch?v=BwNrmYRiX_o" target="_blank"><img src="//img.youtube.com/vi/BwNrmYRiX_o/mqdefault.jpg" width="320" height="315" border="0"></a></div>', result
18
+ end
19
+
20
+ def test_transform3
21
+ result = auto_html('foo http://www.youtube.com/watch?v=fT1ahr81HLw bar') { youtube_image }
22
+ assert_equal 'foo <div class="thumbnail youtube"><a href="https://www.youtube.com/watch?v=fT1ahr81HLw" target="_blank"><img src="//img.youtube.com/vi/fT1ahr81HLw/mqdefault.jpg" width="320" height="315" border="0"></a></div> bar', result
23
+ end
24
+
25
+ def test_transform4
26
+ result = auto_html('foo http://www.youtube.com/watch?v=fT1ahr81HLw<br>bar') { youtube_image }
27
+ assert_equal 'foo <div class="thumbnail youtube"><a href="https://www.youtube.com/watch?v=fT1ahr81HLw" target="_blank"><img src="//img.youtube.com/vi/fT1ahr81HLw/mqdefault.jpg" width="320" height="315" border="0"></a></div><br>bar', result
28
+ end
29
+
30
+ def test_transform_url_without_www
31
+ result = auto_html('http://youtube.com/watch?v=BwNrmYRiX_o') { youtube_image }
32
+ assert_equal '<div class="thumbnail youtube"><a href="https://www.youtube.com/watch?v=BwNrmYRiX_o" target="_blank"><img src="//img.youtube.com/vi/BwNrmYRiX_o/mqdefault.jpg" width="320" height="315" border="0"></a></div>', result
33
+ end
34
+
35
+ def test_transform_with_options
36
+ result = auto_html('http://www.youtube.com/watch?v=BwNrmYRiX_o') { youtube_image(:width => 300, :height => 255, :style => 'high', :target => 'self', :border => 1) }
37
+ assert_equal '<div class="thumbnail youtube"><a href="https://www.youtube.com/watch?v=BwNrmYRiX_o" target="_self"><img src="//img.youtube.com/vi/BwNrmYRiX_o/hqdefault.jpg" width="300" height="255" border="1"></a></div>', result
38
+ end
39
+
40
+ def test_transform_with_short_url
41
+ result = auto_html('http://www.youtu.be/BwNrmYRiX_o') { youtube_image }
42
+ assert_equal '<div class="thumbnail youtube"><a href="https://www.youtube.com/watch?v=BwNrmYRiX_o" target="_blank"><img src="//img.youtube.com/vi/BwNrmYRiX_o/mqdefault.jpg" width="320" height="315" border="0"></a></div>', result
43
+ end
44
+
45
+ def test_transform_https
46
+ result = auto_html("https://www.youtube.com/watch?v=t7NdBIA4zJg") { youtube_image }
47
+ assert_equal '<div class="thumbnail youtube"><a href="https://www.youtube.com/watch?v=t7NdBIA4zJg" target="_blank"><img src="//img.youtube.com/vi/t7NdBIA4zJg/mqdefault.jpg" width="320" height="315" border="0"></a></div>', result
48
+ end
49
+
50
+ def test_short_with_params
51
+ result = auto_html("http://youtu.be/t7NdBIA4zJg?t=1s&hd=1") { youtube_image }
52
+ assert_equal '<div class="thumbnail youtube"><a href="https://www.youtube.com/watch?v=t7NdBIA4zJg" target="_blank"><img src="//img.youtube.com/vi/t7NdBIA4zJg/mqdefault.jpg" width="320" height="315" border="0"></a></div>', result
53
+ end
54
+
55
+ def test_transform_without_protocol
56
+ result = auto_html("www.youtube.com/watch?v=t7NdBIA4zJg") { youtube_image }
57
+ assert_equal '<div class="thumbnail youtube"><a href="https://www.youtube.com/watch?v=t7NdBIA4zJg" target="_blank"><img src="//img.youtube.com/vi/t7NdBIA4zJg/mqdefault.jpg" width="320" height="315" border="0"></a></div>', result
58
+ end
59
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: auto_html
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.3
4
+ version: 1.6.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-04-01 00:00:00.000000000 Z
12
+ date: 2014-04-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rinku
@@ -77,6 +77,7 @@ files:
77
77
  - lib/auto_html/filters/vimeo.rb
78
78
  - lib/auto_html/filters/worldstar.rb
79
79
  - lib/auto_html/filters/youtube.rb
80
+ - lib/auto_html/filters/youtube_image.rb
80
81
  - lib/auto_html/filters/youtube_js_api.rb
81
82
  - lib/auto_html/railtie.rb
82
83
  - lib/auto_html/rake_tasks.rb
@@ -108,6 +109,7 @@ files:
108
109
  - test/unit/filters/twitter_test.rb
109
110
  - test/unit/filters/vimeo_test.rb
110
111
  - test/unit/filters/worldstar_test.rb
112
+ - test/unit/filters/youtube_image_test.rb
111
113
  - test/unit/filters/youtube_js_api_test.rb
112
114
  - test/unit/filters/youtube_test.rb
113
115
  - test/unit/unit_test_helper.rb