auto_html-whistlerbrk 2.0.0.pre

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +123 -0
  3. data/Rakefile +9 -0
  4. data/lib/auto_html.rb +17 -0
  5. data/lib/auto_html/auto_html_for.rb +64 -0
  6. data/lib/auto_html/base.rb +21 -0
  7. data/lib/auto_html/builder.rb +22 -0
  8. data/lib/auto_html/capistrano.rb +17 -0
  9. data/lib/auto_html/filter.rb +22 -0
  10. data/lib/auto_html/filters/dailymotion.rb +6 -0
  11. data/lib/auto_html/filters/flickr.rb +20 -0
  12. data/lib/auto_html/filters/gist.rb +8 -0
  13. data/lib/auto_html/filters/google_map.rb +19 -0
  14. data/lib/auto_html/filters/hashtag.rb +7 -0
  15. data/lib/auto_html/filters/html_escape.rb +9 -0
  16. data/lib/auto_html/filters/image.rb +16 -0
  17. data/lib/auto_html/filters/instagram.rb +10 -0
  18. data/lib/auto_html/filters/link.rb +16 -0
  19. data/lib/auto_html/filters/liveleak.rb +19 -0
  20. data/lib/auto_html/filters/metacafe.rb +13 -0
  21. data/lib/auto_html/filters/redcarpet.rb +4 -0
  22. data/lib/auto_html/filters/sanitize.rb +5 -0
  23. data/lib/auto_html/filters/simple_format.rb +12 -0
  24. data/lib/auto_html/filters/soundcloud.rb +19 -0
  25. data/lib/auto_html/filters/ted.rb +13 -0
  26. data/lib/auto_html/filters/twitter.rb +19 -0
  27. data/lib/auto_html/filters/vimeo.rb +15 -0
  28. data/lib/auto_html/filters/worldstar.rb +8 -0
  29. data/lib/auto_html/filters/youtube.rb +19 -0
  30. data/lib/auto_html/filters/youtube_image.rb +17 -0
  31. data/lib/auto_html/filters/youtube_js_api.rb +6 -0
  32. data/lib/auto_html/railtie.rb +10 -0
  33. data/lib/auto_html/rake_tasks.rb +27 -0
  34. data/lib/auto_html/task.rb +9 -0
  35. data/test/fixture_setup.rb +13 -0
  36. data/test/fixtures/database.yml +5 -0
  37. data/test/fixtures/schema.rb +20 -0
  38. data/test/functional/auto_html_for_options_test.rb +26 -0
  39. data/test/functional/auto_html_for_test.rb +56 -0
  40. data/test/functional/filter_test.rb +27 -0
  41. data/test/test_helper.rb +16 -0
  42. data/test/unit/auto_html_test.rb +37 -0
  43. data/test/unit/filters/dailymotion_test.rb +34 -0
  44. data/test/unit/filters/gist_test.rb +15 -0
  45. data/test/unit/filters/google_map_test.rb +24 -0
  46. data/test/unit/filters/hashtag_test.rb +25 -0
  47. data/test/unit/filters/html_escape_test.rb +15 -0
  48. data/test/unit/filters/image_test.rb +77 -0
  49. data/test/unit/filters/instagram_test.rb +35 -0
  50. data/test/unit/filters/link_test.rb +55 -0
  51. data/test/unit/filters/liveleak_test.rb +17 -0
  52. data/test/unit/filters/metacafe_test.rb +29 -0
  53. data/test/unit/filters/redcarpet_test.rb +38 -0
  54. data/test/unit/filters/sanitize_test.rb +36 -0
  55. data/test/unit/filters/simple_format_test.rb +15 -0
  56. data/test/unit/filters/soundcloud_test.rb +52 -0
  57. data/test/unit/filters/ted_test.rb +18 -0
  58. data/test/unit/filters/twitter_test.rb +45 -0
  59. data/test/unit/filters/vimeo_test.rb +64 -0
  60. data/test/unit/filters/worldstar_test.rb +27 -0
  61. data/test/unit/filters/youtube_image_test.rb +59 -0
  62. data/test/unit/filters/youtube_js_api_test.rb +30 -0
  63. data/test/unit/filters/youtube_test.rb +73 -0
  64. data/test/unit/unit_test_helper.rb +3 -0
  65. metadata +134 -0
@@ -0,0 +1,15 @@
1
+ require File.expand_path('../../unit_test_helper', __FILE__)
2
+
3
+ class GistTest < Minitest::Test
4
+
5
+ def test_transform
6
+ result = auto_html('https://gist.github.com/1710276') { gist }
7
+ assert_equal '<script type="text/javascript" src="https://gist.github.com/1710276.js"></script>', result
8
+ end
9
+
10
+ def test_transform_with_username
11
+ result = auto_html('https://gist.github.com/toctan/6547840') { gist }
12
+ assert_equal '<script type="text/javascript" src="https://gist.github.com/6547840.js"></script>', result
13
+ end
14
+
15
+ end
@@ -0,0 +1,24 @@
1
+ require File.expand_path('../../unit_test_helper', __FILE__)
2
+
3
+ class GoogleMapTest < Minitest::Test
4
+
5
+ def test_transform
6
+ result = auto_html('http://maps.google.co.kr/maps?q=%ED%8C%8C%ED%8A%B8%EB%84%88%EC%8A%A4%ED%83%80%EC%9B%8C+1%EC%B0%A8&hl=ko&ie=UTF8&ll=37.472942,126.884762&spn=0.00774,0.010053&sll=37.473027,126.88451&sspn=0.003887,0.005026&vpsrc=6&gl=kr&hq=%ED%8C%8C%ED%8A%B8%EB%84%88%EC%8A%A4%ED%83%80%EC%9B%8C+1%EC%B0%A8&t=m&z=17&iwloc=A') { google_map }
7
+ assert_equal '<iframe width="420" height="315" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="//maps.google.co.kr/maps?f=q&amp;source=s_q&amp;q=%ED%8C%8C%ED%8A%B8%EB%84%88%EC%8A%A4%ED%83%80%EC%9B%8C+1%EC%B0%A8&hl=ko&ie=UTF8&ll=37.472942,126.884762&spn=0.00774,0.010053&sll=37.473027,126.88451&sspn=0.003887,0.005026&vpsrc=6&gl=kr&hq=%ED%8C%8C%ED%8A%B8%EB%84%88%EC%8A%A4%ED%83%80%EC%9B%8C+1%EC%B0%A8&t=m&z=17&iwloc=A&amp;output=embed&amp;t=m&amp;z=18"></iframe><br /><small><a href="//maps.google.co.kr/maps?f=q&amp;source=embed&amp;q=%ED%8C%8C%ED%8A%B8%EB%84%88%EC%8A%A4%ED%83%80%EC%9B%8C+1%EC%B0%A8&hl=ko&ie=UTF8&ll=37.472942,126.884762&spn=0.00774,0.010053&sll=37.473027,126.88451&sspn=0.003887,0.005026&vpsrc=6&gl=kr&hq=%ED%8C%8C%ED%8A%B8%EB%84%88%EC%8A%A4%ED%83%80%EC%9B%8C+1%EC%B0%A8&t=m&z=17&iwloc=A" style="color:#000;text-align:left">View Larger Map</a></small>', result
8
+ end
9
+
10
+ def test_transform_2
11
+ result = auto_html('http://maps.google.com/maps?hl=en&q=newyork&gs_sm=e&gs_upl=917l917l0l1666l1l1l0l0l0l0l317l317l3-1l1l0&bav=on.2,or.r_gc.r_pw.,cf.osb&biw=1280&bih=679&um=1&ie=UTF-8&sa=N&tab=wl') { google_map }
12
+ assert_equal '<iframe width="420" height="315" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="//maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&q=newyork&gs_sm=e&gs_upl=917l917l0l1666l1l1l0l0l0l0l317l317l3-1l1l0&bav=on.2,or.r_gc.r_pw.,cf.osb&biw=1280&bih=679&um=1&ie=UTF-8&sa=N&tab=wl&amp;output=embed&amp;t=m&amp;z=18"></iframe><br /><small><a href="//maps.google.com/maps?f=q&amp;source=embed&amp;hl=en&q=newyork&gs_sm=e&gs_upl=917l917l0l1666l1l1l0l0l0l0l317l317l3-1l1l0&bav=on.2,or.r_gc.r_pw.,cf.osb&biw=1280&bih=679&um=1&ie=UTF-8&sa=N&tab=wl" style="color:#000;text-align:left">View Larger Map</a></small>', result
13
+ end
14
+
15
+ def test_show_info
16
+ result = auto_html('http://maps.google.com.br/maps?q=Joinville+-+Santa+Catarina') { google_map(:show_info => false) }
17
+ assert_equal '<iframe width="420" height="315" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="//maps.google.com.br/maps?f=q&amp;source=s_q&amp;q=Joinville+-+Santa+Catarina&amp;output=embed&amp;iwloc=near&amp;t=m&amp;z=18"></iframe><br /><small><a href="//maps.google.com.br/maps?f=q&amp;source=embed&amp;q=Joinville+-+Santa+Catarina" style="color:#000;text-align:left">View Larger Map</a></small>', result
18
+ end
19
+
20
+ def test_type_and_zoom
21
+ result = auto_html('http://maps.google.com.br/maps?q=Joinville+-+Santa+Catarina') { google_map(:type => :satellite, :zoom => 3) }
22
+ assert_equal '<iframe width="420" height="315" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="//maps.google.com.br/maps?f=q&amp;source=s_q&amp;q=Joinville+-+Santa+Catarina&amp;output=embed&amp;t=k&amp;z=3"></iframe><br /><small><a href="//maps.google.com.br/maps?f=q&amp;source=embed&amp;q=Joinville+-+Santa+Catarina" style="color:#000;text-align:left">View Larger Map</a></small>', result
23
+ end
24
+ end
@@ -0,0 +1,25 @@
1
+ require File.expand_path('../../unit_test_helper', __FILE__)
2
+
3
+ class HashtagTest < Minitest::Test
4
+
5
+ def test_transform
6
+ result = auto_html("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vel ipsum et leo adipiscing ultrices. Etiam ac elementum cras amet. #LoremIpsum") { hashtag }
7
+ assert_equal 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vel ipsum et leo adipiscing ultrices. Etiam ac elementum cras amet. <a href="http://twitter.com/search?q=%23LoremIpsum&f=realtime" class="hashtag" target="_blank">#LoremIpsum</a>', result
8
+ end
9
+
10
+ def test_transform_with_multiple_hashtags
11
+ result = auto_html("Lorem ipsum #dolor sit amet, consectetur adipiscing elit. Donec vel ipsum et leo #adipiscingUltrices. Etiam ac elementum cras amet.") { hashtag }
12
+ assert_equal 'Lorem ipsum <a href="http://twitter.com/search?q=%23dolor&f=realtime" class="hashtag" target="_blank">#dolor</a> sit amet, consectetur adipiscing elit. Donec vel ipsum et leo <a href="http://twitter.com/search?q=%23adipiscingUltrices.&f=realtime" class="hashtag" target="_blank">#adipiscingUltrices.</a> Etiam ac elementum cras amet.', result
13
+ end
14
+
15
+ def test_transform_with_twitter_source
16
+ result = auto_html("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vel ipsum et leo adipiscing ultrices. Etiam ac elementum cras amet. #LoremIpsum") { hashtag source: :twitter }
17
+ assert_equal 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vel ipsum et leo adipiscing ultrices. Etiam ac elementum cras amet. <a href="http://twitter.com/search?q=%23LoremIpsum&f=realtime" class="hashtag" target="_blank">#LoremIpsum</a>', result
18
+ end
19
+
20
+ def test_transform_with_facebook_source
21
+ result = auto_html("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vel ipsum et leo adipiscing ultrices. Etiam ac elementum cras amet. #LoremIpsum") { hashtag source: :facebook }
22
+ assert_equal 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vel ipsum et leo adipiscing ultrices. Etiam ac elementum cras amet. <a href="https://www.facebook.com/hashtag/LoremIpsum" class="hashtag" target="_blank">#LoremIpsum</a>', result
23
+ end
24
+
25
+ end
@@ -0,0 +1,15 @@
1
+ require File.expand_path('../../unit_test_helper', __FILE__)
2
+
3
+ class HtmlEscapeTest < Minitest::Test
4
+
5
+ def test_trasform
6
+ result = auto_html("<script>alert(0)</script>") { html_escape }
7
+ assert_equal "&lt;script&gt;alert(0)&lt;/script&gt;", result
8
+ end
9
+
10
+ def test_trasform2
11
+ result = auto_html("<div>test</div>") { html_escape }
12
+ assert_equal "&lt;div&gt;test&lt;/div&gt;", result
13
+ end
14
+
15
+ end
@@ -0,0 +1,77 @@
1
+ require File.expand_path('../../unit_test_helper', __FILE__)
2
+
3
+ class ImageTest < Minitest::Test
4
+
5
+ def test_transform
6
+ result = auto_html('http://rors.org/images/rails.png') { image({:alt => nil}) }
7
+ assert_equal '<img src="http://rors.org/images/rails.png" alt=""/>', result
8
+ end
9
+
10
+ def test_dont_transform
11
+ result = auto_html('http://blog.phusion.nl/2009/04/16/phusions-one-year-anniversary-gift-phusion-passenger-220/') { image }
12
+ assert_equal 'http://blog.phusion.nl/2009/04/16/phusions-one-year-anniversary-gift-phusion-passenger-220/', result
13
+ end
14
+
15
+ def test_dont_transform_a_formatted_image
16
+ result = auto_html('<img src="http://farm4.static.flickr.com/3459/3270173112_5099d3d730.jpg" alt=""/>'){ image({:alt => nil}) }
17
+ assert_equal '<img src="http://farm4.static.flickr.com/3459/3270173112_5099d3d730.jpg" alt=""/>', result
18
+ end
19
+
20
+ def test_transform2
21
+ result = auto_html('http://farm4.static.flickr.com/3459/3270173112_5099d3d730.jpg') { image({:alt => nil}) }
22
+ assert_equal '<img src="http://farm4.static.flickr.com/3459/3270173112_5099d3d730.jpg" alt=""/>', result
23
+ end
24
+
25
+ def test_transform3
26
+ result = auto_html('http://www.lockhartfineart.com/images/Rio_Grande_Frost.JPG') { image({:alt => nil}) }
27
+ assert_equal '<img src="http://www.lockhartfineart.com/images/Rio_Grande_Frost.JPG" alt=""/>', result
28
+ end
29
+
30
+ def test_transform4
31
+ result = auto_html('http://www.lockhartfineart.com/images/Rio_Grande_Frost.JPG') { image({:alt => nil}) }
32
+ assert_equal '<img src="http://www.lockhartfineart.com/images/Rio_Grande_Frost.JPG" alt=""/>', result
33
+ end
34
+
35
+ def test_transform5
36
+ result = auto_html('http://farm4.static.flickr.com/3664/3512431377_71b8d002ef.jpg?v=0') { image({:alt => nil}) }
37
+ assert_equal '<img src="http://farm4.static.flickr.com/3664/3512431377_71b8d002ef.jpg?v=0" alt=""/>', result
38
+ end
39
+
40
+ def test_transform6
41
+ result = auto_html('Do you like this logo http://rors.org/images/rails.png? Yeah?') { image({:alt => nil}) }
42
+ assert_equal 'Do you like this logo <img src="http://rors.org/images/rails.png" alt=""/>? Yeah?', result
43
+ end
44
+
45
+ def test_transform7
46
+ result = auto_html('http://tbn3.google.com/images?q=tbn:vS-jtEi9Xc8K6M:http://upload.wikimedia.org/wikipedia/commons/b/ba/Potturinn.jpeg') { image({:alt => nil}) }
47
+ assert_equal '<img src="http://tbn3.google.com/images?q=tbn:vS-jtEi9Xc8K6M:http://upload.wikimedia.org/wikipedia/commons/b/ba/Potturinn.jpeg" alt=""/>', result
48
+ end
49
+
50
+ def test_transform8
51
+ result = auto_html('Which do you prefer, this one http://www.lockhartfineart.com/images/Rio_Grande_Frost.JPG, or this one http://rors.org/images/rails.png?') { image({:alt => nil}) }
52
+ assert_equal 'Which do you prefer, this one <img src="http://www.lockhartfineart.com/images/Rio_Grande_Frost.JPG" alt=""/>, or this one <img src="http://rors.org/images/rails.png" alt=""/>?', result
53
+ end
54
+
55
+ def test_markdown_not_transformed
56
+ img_markdown = "![GOOG logo](http://www.google.com/images/srpr/logo11w.png)"
57
+ result = auto_html(img_markdown) { image }
58
+ assert_equal img_markdown, result
59
+ end
60
+
61
+ def test_image_tag_not_transformed
62
+ result = auto_html('<img src="http://img.skitch.com/20100910-1wrbg5749xe29ya5t3s85bnaiy.png" />') { image }
63
+ assert_equal '<img src="http://img.skitch.com/20100910-1wrbg5749xe29ya5t3s85bnaiy.png" />', result
64
+ end
65
+
66
+
67
+ def test_https
68
+ result = auto_html('https://img.skitch.com/20100910-1wrbg5749xe29ya5t3s85bnaiy.png') { image({:alt => nil}) }
69
+ assert_equal '<img src="https://img.skitch.com/20100910-1wrbg5749xe29ya5t3s85bnaiy.png" alt=""/>', result
70
+ end
71
+
72
+ def test_proxy_option
73
+ result = auto_html('http://img.skitch.com/20100910-1wrbg5749xe29ya5t3s85bnaiy.png') { image({:alt => nil,:proxy => "https://proxy/?url="}) }
74
+ assert_equal '<img src="https://proxy/?url=http://img.skitch.com/20100910-1wrbg5749xe29ya5t3s85bnaiy.png" alt=""/>', result
75
+ end
76
+
77
+ end
@@ -0,0 +1,35 @@
1
+ require File.expand_path('../../unit_test_helper', __FILE__)
2
+
3
+ class InstagramTest < Minitest::Test
4
+ def test_instagram_embed
5
+ result = auto_html('http://instagram.com/p/WsQTLAGvx7/') { instagram }
6
+ assert_equal '<iframe src="http://instagram.com/p/WsQTLAGvx7/embed" height="714" width="616" frameborder="0" scrolling="no"></iframe>', result
7
+ end
8
+
9
+ def test_instagram_embed_no_slash
10
+ result = auto_html('http://instagram.com/p/WsQTLAGvx7') { instagram }
11
+ assert_equal '<iframe src="http://instagram.com/p/WsQTLAGvx7/embed" height="714" width="616" frameborder="0" scrolling="no"></iframe>', result
12
+ end
13
+
14
+ # Filter was appending '/' to the end of all text,
15
+ # not just the URL this filter was affecting.
16
+ #
17
+ # Dumb.
18
+ def test_normal_text_not_transformed
19
+ expected = "Some random text\nHello Friends"
20
+ result = auto_html(expected) { instagram }
21
+ assert_equal(expected, result)
22
+ end
23
+
24
+ def test_prevent_html_transform
25
+ str = '<iframe src="http://instagram.com/p/WsQTLAGvx7/embed" height="714" width="616" frameborder="0" scrolling="no"></iframe>'
26
+
27
+ result = auto_html(str) { vimeo }
28
+
29
+ assert_equal(
30
+ str, result,
31
+ "Should not re-transform HTML with Instagram embeds"
32
+ )
33
+ end
34
+
35
+ end
@@ -0,0 +1,55 @@
1
+ require File.expand_path('../../unit_test_helper', __FILE__)
2
+
3
+ class LinkTest < Minitest::Test
4
+
5
+ def test_transform
6
+ result = auto_html("http://vukajlija.com") { link }
7
+ assert_equal '<a href="http://vukajlija.com" >http://vukajlija.com</a>', result
8
+ end
9
+
10
+ def test_transform_with_the_slash_at_the_end
11
+ result = auto_html("http://github.com/") { link }
12
+ assert_equal '<a href="http://github.com/" >http://github.com/</a>', result
13
+ end
14
+
15
+ def test_transform_with_param
16
+ result = auto_html('http://example.com/abc?query=ruby') { link }
17
+ assert_equal '<a href="http://example.com/abc?query=ruby" >http://example.com/abc?query=ruby</a>', result
18
+ end
19
+
20
+ def test_transform_with_param_and_trailing_dot
21
+ result = auto_html('http://example.com/abc?query=ruby.') { link }
22
+ assert_equal '<a href="http://example.com/abc?query=ruby" >http://example.com/abc?query=ruby</a>.', result
23
+ end
24
+
25
+ def test_transform_with_anchor_and_trailing_dot
26
+ result = auto_html('http://example.com/example#id=123.12.') { link }
27
+ assert_equal '<a href="http://example.com/example#id=123.12" >http://example.com/example#id=123.12</a>.', result
28
+ end
29
+
30
+ def test_transform_with_commas
31
+ result = auto_html('http://www.dw-world.de/dw/article/0,,4708386,00.html?maca=ser-rss-ser-all-1494-rdf') { link }
32
+ assert_equal '<a href="http://www.dw-world.de/dw/article/0,,4708386,00.html?maca=ser-rss-ser-all-1494-rdf" >http://www.dw-world.de/dw/article/0,,4708386,00.html?maca=ser-rss-ser-all-1494-rdf</a>', result
33
+ end
34
+
35
+ def test_transform_complex_url
36
+ url = 'http://www.google.com/#q=nikola+tesla&ct=tesla09&oi=ddle&fp=Xmf0jJ9P_V0'
37
+ # uses auto_link instead raw to support both Rails 2 & 3
38
+ assert_equal('<a href="http://www.google.com/#q=nikola+tesla&ct=tesla09&oi=ddle&fp=Xmf0jJ9P_V0" >http://www.google.com/#q=nikola+tesla&ct=tesla09&oi=ddle&fp=Xmf0jJ9P_V0</a>', auto_html(url) { link })
39
+ end
40
+
41
+ def test_transform_with_options
42
+ result = auto_html("http://rors.org") { link :target => "_blank" }
43
+ assert_equal '<a href="http://rors.org" target="_blank">http://rors.org</a>', result
44
+ end
45
+
46
+ def test_transform_with_short_link_name_option
47
+ result = auto_html("http://rors.org?some=params&and=more") { link :short_link_name => true }
48
+ assert_equal '<a href="http://rors.org?some=params&and=more" >http://rors.org</a>', result
49
+ end
50
+
51
+ def test_transform_with_short_link_name_option_false
52
+ result = auto_html("http://rors.org?some=params&and=more") { link :short_link_name => false }
53
+ assert_equal '<a href="http://rors.org?some=params&and=more" >http://rors.org?some=params&and=more</a>', result
54
+ end
55
+ end
@@ -0,0 +1,17 @@
1
+ require File.expand_path('../../unit_test_helper', __FILE__)
2
+
3
+ class LiveLeakTest < Minitest::Test
4
+
5
+ DIV_START = '<div class="video-container liveleak">'
6
+
7
+ def test_transform
8
+ result = auto_html('http://www.liveleak.com/view?i=BwNrmYRiX_o') { liveleak }
9
+ assert_equal %Q|#{DIV_START}<iframe width="420" height="315" src="http://www.liveleak.com/ll_embed?f=BwNrmYRiX_o" frameborder="0" allowfullscreen></iframe></div>|, result
10
+ end
11
+
12
+ def test_transform2
13
+ result = auto_html('http://www.liveleak.com/ll_embed?f=ef8304ab85e5') { liveleak }
14
+ assert_equal %Q|#{DIV_START}<iframe width="420" height="315" src="http://www.liveleak.com/ll_embed?f=ef8304ab85e5" frameborder="0" allowfullscreen></iframe></div>|, result
15
+ end
16
+
17
+ end
@@ -0,0 +1,29 @@
1
+ require File.expand_path('../../unit_test_helper', __FILE__)
2
+
3
+ class MetaCafeTest < Minitest::Test
4
+
5
+ def test_transform
6
+ result = auto_html("http://www.metacafe.com/watch/5440707/exclusive_tron_evolution_dev_diary_the_art_design") { metacafe }
7
+ assert_equal '<div style="background:#000000;width:440px;height:272px"><embed flashVars="playerVars=showStats=no|autoPlay=no" src="http://www.metacafe.com/fplayer/5440707/exclusive_tron_evolution_dev_diary_the_art_design.swf" width="440" height="272" wmode="transparent" allowFullScreen="true" allowScriptAccess="always" name="Metacafe_5440707" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed></div>', result
8
+ end
9
+
10
+ def test_transform_with_dimensions
11
+ result = auto_html("http://www.metacafe.com/watch/5440707/exclusive_tron_evolution_dev_diary_the_art_design") { metacafe(:width => 500, :height => 300) }
12
+ assert_equal '<div style="background:#000000;width:500px;height:300px"><embed flashVars="playerVars=showStats=no|autoPlay=no" src="http://www.metacafe.com/fplayer/5440707/exclusive_tron_evolution_dev_diary_the_art_design.swf" width="500" height="300" wmode="transparent" allowFullScreen="true" allowScriptAccess="always" name="Metacafe_5440707" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed></div>', result
13
+ end
14
+
15
+ def test_transform_with_show_stats
16
+ result = auto_html("http://www.metacafe.com/watch/5440707/exclusive_tron_evolution_dev_diary_the_art_design") { metacafe(:width => 500, :height => 300, :show_stats => true) }
17
+ assert_equal '<div style="background:#000000;width:500px;height:300px"><embed flashVars="playerVars=showStats=yes|autoPlay=no" src="http://www.metacafe.com/fplayer/5440707/exclusive_tron_evolution_dev_diary_the_art_design.swf" width="500" height="300" wmode="transparent" allowFullScreen="true" allowScriptAccess="always" name="Metacafe_5440707" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed></div>', result
18
+ end
19
+
20
+ def test_transform_with_autoplay
21
+ result = auto_html("http://www.metacafe.com/watch/5440707/exclusive_tron_evolution_dev_diary_the_art_design") { metacafe(:width => 500, :height => 300, :autoplay => true) }
22
+ assert_equal '<div style="background:#000000;width:500px;height:300px"><embed flashVars="playerVars=showStats=no|autoPlay=yes" src="http://www.metacafe.com/fplayer/5440707/exclusive_tron_evolution_dev_diary_the_art_design.swf" width="500" height="300" wmode="transparent" allowFullScreen="true" allowScriptAccess="always" name="Metacafe_5440707" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed></div>', result
23
+ end
24
+
25
+ def test_transform_with_options
26
+ result = auto_html("http://www.metacafe.com/watch/5440707/exclusive_tron_evolution_dev_diary_the_art_design") { metacafe(:width => 500, :height => 300, :show_stats => true, :autoplay => true) }
27
+ assert_equal '<div style="background:#000000;width:500px;height:300px"><embed flashVars="playerVars=showStats=yes|autoPlay=yes" src="http://www.metacafe.com/fplayer/5440707/exclusive_tron_evolution_dev_diary_the_art_design.swf" width="500" height="300" wmode="transparent" allowFullScreen="true" allowScriptAccess="always" name="Metacafe_5440707" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed></div>', result
28
+ end
29
+ end
@@ -0,0 +1,38 @@
1
+ require File.expand_path('../../unit_test_helper', __FILE__)
2
+
3
+ class RedcarpetTest < Minitest::Test
4
+
5
+ def test_transform_strong
6
+ result = auto_html("This is **my** text.") { redcarpet }
7
+ assert_equal '<p>This is <strong>my</strong> text.</p>'+"\n", result
8
+ end
9
+
10
+ def test_transform_title
11
+ result = auto_html("## This is a title ##") { redcarpet }
12
+ assert_equal '<h2>This is a title</h2>'+"\n", result
13
+ end
14
+
15
+ def test_transform_link
16
+ result = auto_html('[This is a link](http://example.org/)') { redcarpet }
17
+ assert_equal '<p><a href="http://example.org/">This is a link</a></p>'+"\n", result
18
+ end
19
+
20
+ class LinksInNewWindow < ::Redcarpet::Render::HTML
21
+ def link(link, title, content)
22
+ "<a href=\"#{link}\" target=\"_blank\">#{content}</a>"
23
+ end
24
+ end
25
+
26
+ def test_transform_link_target_blank
27
+ result = auto_html('[This is a link](http://example.org/)') { redcarpet(:renderer => LinksInNewWindow) }
28
+ assert_equal '<p><a href="http://example.org/" target="_blank">This is a link</a></p>'+"\n", result
29
+ end
30
+
31
+ def test_options
32
+ result = auto_html('http://example.org/') { redcarpet }
33
+ assert_equal '<p>http://example.org/</p>'+"\n", result
34
+
35
+ result = auto_html('http://example.org/') { redcarpet(:markdown_options => { :autolink => true }) }
36
+ assert_equal '<p><a href="http://example.org/">http://example.org/</a></p>'+"\n", result
37
+ end
38
+ end
@@ -0,0 +1,36 @@
1
+ require File.expand_path('../../unit_test_helper', __FILE__)
2
+
3
+ class SanitizeTest < Minitest::Test
4
+
5
+ def test_trasform
6
+ result = auto_html("<script>alert(0)</script>") { sanitize }
7
+ assert_equal "", result
8
+ end
9
+
10
+ def test_trasform2
11
+ result = auto_html("<div>test</div>") { sanitize }
12
+ assert_equal "<div>test</div>", result
13
+ end
14
+
15
+ def test_trasform3
16
+ result = auto_html("<div>test</div>") { sanitize :tags => %w(div) }
17
+ assert_equal "<div>test</div>", result
18
+ end
19
+
20
+ def test_trasform4
21
+ result = auto_html("<div>test</div>") { sanitize :tags => %w(p) }
22
+ assert_equal "test", result
23
+ end
24
+
25
+ def test_trasform5
26
+ result = auto_html("<a rel='nofollow'>test</div>") { sanitize :tags => %w(a), :attributes => %w(href)}
27
+ assert_equal "<a>test", result
28
+ #
29
+ # from Rails doc:
30
+ #
31
+ # Please note that sanitizing user-provided text does not
32
+ # guarantee that the resulting markup is valid.
33
+ #
34
+ end
35
+
36
+ end
@@ -0,0 +1,15 @@
1
+ require File.expand_path('../../unit_test_helper', __FILE__)
2
+
3
+ class SimpleFormatTest < Minitest::Test
4
+
5
+ def test_transform
6
+ result = auto_html('Hey check out my blog => http://rors.org') { simple_format }
7
+ assert_equal '<p>Hey check out my blog => http://rors.org</p>', result
8
+ end
9
+
10
+ def test_trasform2
11
+ result = auto_html('Hey check out my code => http://github.com/dejan') { simple_format }
12
+ assert_equal '<p>Hey check out my code => http://github.com/dejan</p>', result
13
+ end
14
+
15
+ end
@@ -0,0 +1,52 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path('../../unit_test_helper', __FILE__)
4
+ require 'fakeweb'
5
+
6
+ class SoundcloudTest < Minitest::Test
7
+ def test_transform_url_with_www
8
+ result = auto_html('http://www.soundcloud.com/forss/flickermood') { soundcloud }
9
+ assert_equal '<iframe width="100%" height="166" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url=http://www.soundcloud.com/forss/flickermood&show_artwork=false&show_comments=false&auto_play=false&color=915f33&theme_color=00FF00"></iframe>', result
10
+ end
11
+
12
+ def test_transform_url_without_www
13
+ result = auto_html('http://soundcloud.com/forss/flickermood') { soundcloud }
14
+ assert_equal '<iframe width="100%" height="166" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url=http://soundcloud.com/forss/flickermood&show_artwork=false&show_comments=false&auto_play=false&color=915f33&theme_color=00FF00"></iframe>', result
15
+ end
16
+
17
+ def test_transform_url_without_protocol
18
+ result = auto_html('soundcloud.com/forss/flickermood') { soundcloud }
19
+ assert_equal '<iframe width="100%" height="166" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url=http://soundcloud.com/forss/flickermood&show_artwork=false&show_comments=false&auto_play=false&color=915f33&theme_color=00FF00"></iframe>', result
20
+ end
21
+
22
+ def test_transform_url_with_ssl
23
+ result = auto_html('https://soundcloud.com/forss/flickermood') { soundcloud }
24
+ assert_equal '<iframe width="100%" height="166" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url=https://soundcloud.com/forss/flickermood&show_artwork=false&show_comments=false&auto_play=false&color=915f33&theme_color=00FF00"></iframe>', result
25
+ end
26
+
27
+ def test_transform_url_with_options
28
+ result = auto_html('http://www.soundcloud.com/forss/flickermood') { soundcloud(:width => '50%', :height => '100', :auto_play => true, :show_comments => true) }
29
+ assert_equal '<iframe width="50%" height="100" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url=http://www.soundcloud.com/forss/flickermood&show_artwork=false&show_comments=true&auto_play=true&color=915f33&theme_color=00FF00"></iframe>', result
30
+ end
31
+
32
+
33
+ def test_can_handle_urls_in_html_1
34
+ txt = %Q{
35
+ http://blog.nu-soulmag.com/wp-content/uploads/2014/02/013-520x245.jpg\n<p>WATCH: Wedding Bells - http://youtu.be/HM04bKL4oq4</p>\n<p>Director - <strong>Peter Marsden</strong> \nProducer - <strong>Christina Kernohan</strong> \nStylist - <strong>Eclair Fifi</strong> \nFull Credits Within Film</p>\n<p>LISTEN: "Wedding Bells" (Zane Lowe BBC Radio 1 debut) - https://soundcloud.com/cashmerecat/wedding_bells</p>\n<p><strong>LuckyMe</strong> are proud to present: Wedding Bells; Cashmere Cat's attempt at a perfect thing in an imperfect world.</p>\n<p>soundcloud.com/cashmerecat https://twitter.com/CASHMERECAT https://www.facebook.com/cashmerecatofficial‎</p>
36
+ }
37
+ assert_silent do
38
+ result = auto_html(txt) { soundcloud }
39
+ end
40
+ end
41
+
42
+ def test_can_handle_urls_in_html_2
43
+ txt = %Q{
44
+ http://www.deepbeep.com.br/wp-content/uploads/2014/02/duck-sauce.jpg\n<p>A-Track e Van Helden: big as the world</p>\n<p>Já se vão quase 3 anos de “Barbra Streisand”, o hit-meme da dupla <strong>Duck Sauce</strong> aka Van Helden & A-Trak. E a boa notícia é que a discografia desses patos talentosos da música eletrônica bem-humorada segue abastecida, agora com um momento mais glamouroso e maduro, o EP “Duck Droppings”, que saiu agora em 2014.<span></span></p>\n<p>De download gratuito, para abastecer sem milongas o case alheio, esses <em>droppings</em> novos da dupla americana já haviam aparecido em seus sets e são um bom trabalho de transformar samples loopados de disco e música negra em house music acelerada (128 BPM), com um ar <em>french touch</em> saudoso que lembra rádios FMs do fim dos anos 90.</p>\n<p>Falando em FM, “Louie The First” sampleia a clássica “Brother Louie”, do Hot Chocolate, clássico de rádios animadas mundo afora. “Mondo” é nosso destaque do EP, com sua guitarra suingada correndo junto do beat e mais sample disco. </p>\n<p>Em outras notícias, A-Trak também sacou beats para o rapper veterano Cam’ron. É o EP “Federal Reserve”, ainda sem audição completa, mas com uma maravilhosa artwork de grafite que lembra o estilo paulistano e faixa boa onda “Humprey” – ouça aqui.</p>\n<p> </p>\n<p>soundcloud.com/ducksaucenyc quackisback.com</p>
45
+ }
46
+ assert_silent do
47
+ result = auto_html(txt) { soundcloud }
48
+ end
49
+ end
50
+
51
+
52
+ end