auto_html 1.6.3 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +65 -94
  3. data/Rakefile +8 -7
  4. data/lib/auto_html/emoji.rb +24 -0
  5. data/lib/auto_html/html_escape.rb +12 -0
  6. data/lib/auto_html/image.rb +23 -0
  7. data/lib/auto_html/link.rb +33 -0
  8. data/lib/auto_html/markdown.rb +17 -0
  9. data/lib/auto_html/pipeline.rb +18 -0
  10. data/lib/auto_html/simple_format.rb +23 -0
  11. data/lib/auto_html/tag_helper.rb +38 -0
  12. data/lib/auto_html.rb +11 -15
  13. data/spec/auto_html/emoji_spec.rb +9 -0
  14. data/spec/auto_html/html_escape_spec.rb +10 -0
  15. data/spec/auto_html/image_spec.rb +41 -0
  16. data/spec/auto_html/link_spec.rb +53 -0
  17. data/spec/auto_html/markdown_spec.rb +9 -0
  18. data/spec/auto_html/pipeline_spec.rb +26 -0
  19. data/spec/auto_html/simple_format_spec.rb +18 -0
  20. data/spec/auto_html/tag_helper_spec.rb +30 -0
  21. data/spec/spec_helper.rb +13 -0
  22. metadata +114 -92
  23. data/lib/auto_html/auto_html_for.rb +0 -64
  24. data/lib/auto_html/base.rb +0 -18
  25. data/lib/auto_html/builder.rb +0 -21
  26. data/lib/auto_html/capistrano.rb +0 -17
  27. data/lib/auto_html/filter.rb +0 -22
  28. data/lib/auto_html/filters/dailymotion.rb +0 -6
  29. data/lib/auto_html/filters/flickr.rb +0 -20
  30. data/lib/auto_html/filters/gist.rb +0 -8
  31. data/lib/auto_html/filters/google_map.rb +0 -19
  32. data/lib/auto_html/filters/google_video.rb +0 -6
  33. data/lib/auto_html/filters/hashtag.rb +0 -7
  34. data/lib/auto_html/filters/html_escape.rb +0 -9
  35. data/lib/auto_html/filters/image.rb +0 -16
  36. data/lib/auto_html/filters/instagram.rb +0 -10
  37. data/lib/auto_html/filters/link.rb +0 -16
  38. data/lib/auto_html/filters/liveleak.rb +0 -19
  39. data/lib/auto_html/filters/metacafe.rb +0 -13
  40. data/lib/auto_html/filters/redcarpet.rb +0 -4
  41. data/lib/auto_html/filters/sanitize.rb +0 -5
  42. data/lib/auto_html/filters/simple_format.rb +0 -12
  43. data/lib/auto_html/filters/soundcloud.rb +0 -21
  44. data/lib/auto_html/filters/ted.rb +0 -13
  45. data/lib/auto_html/filters/twitter.rb +0 -19
  46. data/lib/auto_html/filters/vimeo.rb +0 -15
  47. data/lib/auto_html/filters/worldstar.rb +0 -8
  48. data/lib/auto_html/filters/youtube.rb +0 -19
  49. data/lib/auto_html/filters/youtube_js_api.rb +0 -6
  50. data/lib/auto_html/railtie.rb +0 -10
  51. data/lib/auto_html/rake_tasks.rb +0 -27
  52. data/lib/auto_html/task.rb +0 -9
  53. data/test/fixture_setup.rb +0 -13
  54. data/test/fixtures/database.yml +0 -5
  55. data/test/fixtures/schema.rb +0 -20
  56. data/test/functional/auto_html_for_options_test.rb +0 -26
  57. data/test/functional/auto_html_for_test.rb +0 -56
  58. data/test/functional/filter_test.rb +0 -27
  59. data/test/test_helper.rb +0 -9
  60. data/test/unit/auto_html_test.rb +0 -37
  61. data/test/unit/filters/dailymotion_test.rb +0 -20
  62. data/test/unit/filters/gist_test.rb +0 -15
  63. data/test/unit/filters/google_map_test.rb +0 -24
  64. data/test/unit/filters/hashtag_test.rb +0 -25
  65. data/test/unit/filters/html_escape_test.rb +0 -15
  66. data/test/unit/filters/image_test.rb +0 -65
  67. data/test/unit/filters/instagram_test.rb +0 -8
  68. data/test/unit/filters/link_test.rb +0 -55
  69. data/test/unit/filters/liveleak_test.rb +0 -15
  70. data/test/unit/filters/metacafe_test.rb +0 -29
  71. data/test/unit/filters/redcarpet_test.rb +0 -38
  72. data/test/unit/filters/sanitize_test.rb +0 -36
  73. data/test/unit/filters/simple_format_test.rb +0 -15
  74. data/test/unit/filters/soundcloud_test.rb +0 -29
  75. data/test/unit/filters/ted_test.rb +0 -18
  76. data/test/unit/filters/twitter_test.rb +0 -45
  77. data/test/unit/filters/vimeo_test.rb +0 -50
  78. data/test/unit/filters/worldstar_test.rb +0 -14
  79. data/test/unit/filters/youtube_js_api_test.rb +0 -30
  80. data/test/unit/filters/youtube_test.rb +0 -59
  81. data/test/unit/unit_test_helper.rb +0 -3
@@ -1,19 +0,0 @@
1
- AutoHtml.add_filter(:twitter).with({}) do |text, options|
2
- require 'uri'
3
- require 'net/http'
4
-
5
- regex = %r{(?<!href=")https://twitter\.com(/#!)?/[A-Za-z0-9_]{1,15}/status(es)?/\d+(/?)}
6
-
7
- text.gsub(regex) do |match|
8
- params = { :url => match }.merge(options)
9
-
10
- uri = URI("https://api.twitter.com/1/statuses/oembed.json")
11
- uri.query = URI.encode_www_form(params)
12
-
13
- http = Net::HTTP.new(uri.host, uri.port)
14
- http.use_ssl = true
15
-
16
- response = JSON.parse(http.get(uri.request_uri).body)
17
- response["html"]
18
- end
19
- end
@@ -1,15 +0,0 @@
1
- AutoHtml.add_filter(:vimeo).with(:width => 440, :height => 248, :show_title => false, :show_byline => false, :show_portrait => false) do |text, options|
2
- text.gsub(/https?:\/\/(www.)?vimeo\.com\/([A-Za-z0-9._%-]*)((\?|#)\S+)?/) do
3
- vimeo_id = $2
4
- width = options[:width]
5
- height = options[:height]
6
- show_title = "title=0" unless options[:show_title]
7
- show_byline = "byline=0" unless options[:show_byline]
8
- show_portrait = "portrait=0" unless options[:show_portrait]
9
- frameborder = options[:frameborder] || 0
10
- query_string_variables = [show_title, show_byline, show_portrait].compact.join("&")
11
- query_string = "?" + query_string_variables unless query_string_variables.empty?
12
-
13
- %{<iframe src="//player.vimeo.com/video/#{vimeo_id}#{query_string}" width="#{width}" height="#{height}" frameborder="#{frameborder}"></iframe>}
14
- end
15
- end
@@ -1,8 +0,0 @@
1
- AutoHtml.add_filter(:worldstar).with(:width => 448, :height => 374) do |text,options|
2
- text.gsub(/http:\/\/www\.worldstarhiphop\.com\/videos\/video\.php\?v\=(wshh[A-Za-z0-9]+)/) do
3
- video_id = $1
4
- width = options[:width]
5
- height = options[:height]
6
- %{<object width="#{width}" height="#{height}"><param name="movie" value="http://www.worldstarhiphop.com/videos/e/16711680/#{video_id}"><param name="allowFullScreen" value="true"></param><embed src="http://www.worldstarhiphop.com/videos/e/16711680/#{video_id}" type="application/x-shockwave-flash" allowFullscreen="true" width="#{width}" height="#{height}"></embed></object>}
7
- end
8
- end
@@ -1,19 +0,0 @@
1
- AutoHtml.add_filter(:youtube).with(:width => 420, :height => 315, :frameborder => 0, :wmode => nil, :autoplay => false, :hide_related => false) do |text, options|
2
- regex = /(https?:\/\/)?(www.)?(youtube\.com\/watch\?v=|youtu\.be\/|youtube\.com\/watch\?feature=player_embedded&v=)([A-Za-z0-9_-]*)(\&\S+)?(\?\S+)?/
3
- text.gsub(regex) do
4
- youtube_id = $4
5
- width = options[:width]
6
- height = options[:height]
7
- frameborder = options[:frameborder]
8
- wmode = options[:wmode]
9
- autoplay = options[:autoplay]
10
- hide_related = options[:hide_related]
11
- src = "//www.youtube.com/embed/#{youtube_id}"
12
- params = []
13
- params << "wmode=#{wmode}" if wmode
14
- params << "autoplay=1" if autoplay
15
- params << "rel=0" if hide_related
16
- src += "?#{params.join '&'}" unless params.empty?
17
- %{<div class="video youtube"><iframe width="#{width}" height="#{height}" src="#{src}" frameborder="#{frameborder}" allowfullscreen></iframe></div>}
18
- end
19
- end
@@ -1,6 +0,0 @@
1
- AutoHtml.add_filter(:youtube_js_api).with(:width => 390, :height => 250) do |text, options|
2
- text.gsub(/https?:\/\/(www.)?youtube\.com\/watch\?v=([A-Za-z0-9._%-]*)(\&\S+)?/) do
3
- youtube_id = $2
4
- %{<object width="#{options[:width]}" height="#{options[:height]}"><param name="movie" value="//www.youtube.com/v/#{youtube_id}?enablejsapi=1&playerapiid=ytplayer"></param><param name="wmode" value="transparent"></param><param name="allowscriptaccess" value="always"></param><embed src="//www.youtube.com/v/#{youtube_id}?enablejsapi=1&playerapiid=ytplayer" type="application/x-shockwave-flash" wmode="transparent" width="#{options[:width]}" height="#{options[:height]}" allowscriptaccess="always"></embed></object>}
5
- end
6
- end
@@ -1,10 +0,0 @@
1
- require 'auto_html'
2
- require 'rails'
3
-
4
- module AutoHtml
5
- class Railtie < Rails::Railtie
6
- rake_tasks do
7
- require "auto_html/rake_tasks"
8
- end
9
- end
10
- end
@@ -1,27 +0,0 @@
1
- require 'auto_html/task'
2
-
3
- # Rake task for rebuilding cached in DB auto_html columns values
4
- # Usage: rake auto_html:rebuild CLASS=[your model]
5
- # Where [your model] is the name of model which contains auto_html_for columns
6
-
7
- namespace :auto_html do
8
- desc "Rebuild auto_html columns"
9
- task :rebuild => :environment do
10
-
11
- klass = AutoHtml::Task.obtain_class.constantize
12
- suffix = AutoHtmlFor.auto_html_for_options[:htmlized_attribute_suffix]
13
- column_names = klass.respond_to?(:column_names) ? klass.column_names : klass.fields.keys
14
- observed_attributes = column_names.select { |c| c=~/#{suffix}$/ }.map { |c| c.gsub(/#{suffix}$/, '')}
15
-
16
- i = 0
17
- klass.find_each do |item|
18
- observed_attributes.each do |field|
19
- item.send("#{field}=", item.send(field))
20
- end
21
- item.save
22
- i += 1
23
- end
24
-
25
- puts "Done! Processed #{i} items."
26
- end
27
- end
@@ -1,9 +0,0 @@
1
- module AutoHtml
2
- module Task
3
- def self.obtain_class
4
- class_name = ENV['CLASS'] || ENV['class']
5
- raise "Must specify CLASS" unless class_name
6
- class_name
7
- end
8
- end
9
- end
@@ -1,13 +0,0 @@
1
- module FixtureSetup
2
- fixtures_dir = File.dirname(__FILE__) + '/fixtures'
3
- connections = YAML.load_file("#{fixtures_dir}/database.yml")
4
- ActiveRecord::Base.establish_connection(connections['sqlite3'])
5
- ActiveRecord::Migration.verbose = false
6
- load "#{fixtures_dir}/schema.rb"
7
-
8
- def setup
9
- fixtures_dir = File.dirname(__FILE__) + '/fixtures'
10
- ActiveRecord::Migration.verbose = false
11
- load "#{fixtures_dir}/schema.rb"
12
- end
13
- end
@@ -1,5 +0,0 @@
1
- sqlite3:
2
- adapter: sqlite3
3
- database: test.sqlite3
4
- pool: 5
5
- timeout: 5000
@@ -1,20 +0,0 @@
1
- ActiveRecord::Schema.define(:version => Time.now.to_i) do
2
- create_table "articles", :force => true do |t|
3
- t.column "title", :string
4
- t.column "body", :text
5
- t.column "body_html", :text
6
- t.column "created_at", :datetime
7
- t.column "updated_at", :datetime
8
- end
9
-
10
- create_table "users", :force => true do |t|
11
- t.column "name", :string
12
- t.column "bio", :text
13
- end
14
-
15
- create_table "posts", :force => true do |t|
16
- t.column "topic_id", :integer
17
- t.column "user_id", :integer
18
- t.column "content", :text
19
- end
20
- end
@@ -1,26 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
- require File.expand_path('../../fixture_setup', __FILE__)
3
-
4
- # store default so we can revert so that other tests use default option
5
- default_suffix = AutoHtmlFor.auto_html_for_options[:htmlized_attribute_suffix]
6
- AutoHtmlFor.auto_html_for_options[:htmlized_attribute_suffix] = '_htmlized'
7
-
8
- class Post < ActiveRecord::Base
9
- auto_html_for :content do
10
- simple_format
11
- end
12
- end
13
-
14
- class AutoHtmlForOptionsTest < Test::Unit::TestCase
15
- include FixtureSetup
16
-
17
- def test_transform_after_save
18
- @article = Post.new(:content => 'Yo!')
19
- assert_equal '<p>Yo!</p>', @article.content_htmlized
20
- @article.save!
21
- assert_equal '<p>Yo!</p>', @article.content_htmlized
22
- end
23
- end
24
-
25
- # reverting to default so that other tests use default option
26
- AutoHtmlFor.auto_html_for_options[:htmlized_attribute_suffix] = default_suffix
@@ -1,56 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
- require File.expand_path('../../fixture_setup', __FILE__)
3
-
4
- class Article < ActiveRecord::Base
5
- auto_html_for :body do
6
- html_escape
7
- youtube(:width => 400, :height => 250)
8
- image
9
- link(:target => "_blank")
10
- simple_format
11
- end
12
-
13
- alias_attribute :plain_body, :body
14
- auto_html_for :plain_body do
15
- html_escape
16
- end
17
- end
18
-
19
- class AutoHtmlForTest < Test::Unit::TestCase
20
- include FixtureSetup
21
-
22
- def test_transform_on_initialization
23
- @article = Article.new(:body => 'Yo!')
24
- assert_equal '<p>Yo!</p>', @article.body_html
25
- end
26
-
27
- def test_html_safe
28
- return unless "".respond_to?(:html_safe?)
29
- @article = Article.new(:body => 'Yo!')
30
- assert @article.body_html.html_safe?
31
- end
32
-
33
- def test_transform_after_save
34
- @article = Article.new(:body => 'Yo!')
35
- @article.save!
36
- assert_equal '<p>Yo!</p>', @article.body_html
37
- end
38
-
39
- def test_transform_of_nil
40
- @article = Article.new(:body => nil)
41
- @article.save!
42
- assert_equal '', @article.body_html
43
- end
44
-
45
- def test_transform_after_update
46
- @article = Article.create!(:body => 'Yo!')
47
- @article.update_attributes(:body => 'http://vukajlija.com')
48
- @article.save!
49
- assert_equal '<p><a href="http://vukajlija.com" target="_blank">http://vukajlija.com</a></p>', @article.body_html
50
- end
51
-
52
- def test_transform_of_alias_attribute
53
- @article = Article.new(:body => 'Hello there.')
54
- assert_equal 'Hello there.', @article.plain_body_html
55
- end
56
- end
@@ -1,27 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
- require File.expand_path('../../fixture_setup', __FILE__)
3
-
4
- AutoHtml.add_filter(:foo) do |text|
5
- nil
6
- end
7
-
8
- AutoHtml.add_filter(:bar) do |text|
9
- "bar"
10
- end
11
-
12
- class User < ActiveRecord::Base
13
- auto_html_for :bio do
14
- foo
15
- foo
16
- bar
17
- end
18
- end
19
-
20
- class FilterTest < Test::Unit::TestCase
21
- include FixtureSetup
22
-
23
- def test_transform_after_save
24
- @article = User.new(:bio => 'in progress...')
25
- assert_equal 'bar', @article.bio_html
26
- end
27
- end
data/test/test_helper.rb DELETED
@@ -1,9 +0,0 @@
1
- require 'rubygems'
2
-
3
- require 'test/unit'
4
- require 'active_record'
5
- require 'action_view'
6
- require 'active_support/core_ext/class'
7
-
8
- require File.dirname(__FILE__) + '/../init'
9
-
@@ -1,37 +0,0 @@
1
- require File.expand_path('../unit_test_helper', __FILE__)
2
-
3
-
4
- class AutoHtmlTest < Test::Unit::TestCase
5
-
6
- def test_should_be_raw_input_when_no_filters_provided
7
- input = "Hey check out my blog => http://rors.org"
8
- result = auto_html(input) { }
9
- assert_equal result, input
10
- end
11
-
12
- def test_should_apply_simple_format_filter
13
- result = auto_html("Hey check out my blog => http://rors.org") { simple_format }
14
- assert_equal "<p>Hey check out my blog => http://rors.org</p>", result
15
- end
16
-
17
- def test_should_apply_simple_format_and_image_filter
18
- result = auto_html("Check the logo: http://rors.org/images/rails.png") { simple_format; image(:alt => nil) }
19
- assert_equal '<p>Check the logo: <img src="http://rors.org/images/rails.png" alt=""/></p>', result
20
- end
21
-
22
- def test_should_apply_simple_format_image_and_link_filter
23
- result = auto_html("Check the logo: http://rors.org/images/rails.png. Visit: http://rubyonrails.org") { simple_format; image(:alt => nil); link }
24
- assert_equal '<p>Check the logo: <img src="http://rors.org/images/rails.png" alt=""/>. Visit: <a href="http://rubyonrails.org" >http://rubyonrails.org</a></p>', result
25
- end
26
-
27
- def test_should_return_blank_if_input_is_blank
28
- result = auto_html("") { simple_format; image(:alt => nil); link }
29
- assert_equal "", result
30
- end
31
-
32
- def test_should_not_apply_simple_format_if_input_is_nil
33
- result = auto_html(nil) { simple_format; image(:alt => nil); link }
34
- assert_equal "", result
35
- end
36
-
37
- end
@@ -1,20 +0,0 @@
1
- require File.expand_path('../../unit_test_helper', __FILE__)
2
-
3
- class DailyMotionTest < Test::Unit::TestCase
4
-
5
- def test_transform
6
- result = auto_html("http://www.dailymotion.com/en/featured/video/xag4p2_tempsmorttv-episode-01_shortfilms") { dailymotion }
7
- assert_equal '<object type="application/x-shockwave-flash" data="http://www.dailymotion.com/swf/xag4p2_tempsmorttv-episode-01_shortfilms&related=0" width="480" height="360"><param name="movie" value="http://www.dailymotion.com/swf/xag4p2_tempsmorttv-episode-01_shortfilms&related=0"></param><param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="always"></param><a href="http://www.dailymotion.com/video/xag4p2_tempsmorttv-episode-01_shortfilms?embed=1"><img src="http://www.dailymotion.com/thumbnail/video/xag4p2_tempsmorttv-episode-01_shortfilms" width="480" height="360"/></a></object>', result
8
- end
9
-
10
- def test_transform_with_tweaked_width
11
- result = auto_html("http://www.dailymotion.com/related/x9cyf6/video/x9tinl_happy-tree-friends-as-you-wish-part_fun") { dailymotion :width => 500 }
12
- assert_equal '<object type="application/x-shockwave-flash" data="http://www.dailymotion.com/swf/x9tinl_happy-tree-friends-as-you-wish-part_fun&related=0" width="500" height="360"><param name="movie" value="http://www.dailymotion.com/swf/x9tinl_happy-tree-friends-as-you-wish-part_fun&related=0"></param><param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="always"></param><a href="http://www.dailymotion.com/video/x9tinl_happy-tree-friends-as-you-wish-part_fun?embed=1"><img src="http://www.dailymotion.com/thumbnail/video/x9tinl_happy-tree-friends-as-you-wish-part_fun" width="500" height="360"/></a></object>', result
13
- end
14
-
15
- def test_transform_with_options
16
- result = auto_html("http://www.dailymotion.com/video/xakv5i") { dailymotion(:width => 500, :height => 300) }
17
- assert_equal '<object type="application/x-shockwave-flash" data="http://www.dailymotion.com/swf/xakv5i&related=0" width="500" height="300"><param name="movie" value="http://www.dailymotion.com/swf/xakv5i&related=0"></param><param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="always"></param><a href="http://www.dailymotion.com/video/xakv5i?embed=1"><img src="http://www.dailymotion.com/thumbnail/video/xakv5i" width="500" height="300"/></a></object>', result
18
- end
19
-
20
- end
@@ -1,15 +0,0 @@
1
- require File.expand_path('../../unit_test_helper', __FILE__)
2
-
3
- class GistTest < Test::Unit::TestCase
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
@@ -1,24 +0,0 @@
1
- require File.expand_path('../../unit_test_helper', __FILE__)
2
-
3
- class GoogleMapTest < Test::Unit::TestCase
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
@@ -1,25 +0,0 @@
1
- require File.expand_path('../../unit_test_helper', __FILE__)
2
-
3
- class HashtagTest < Test::Unit::TestCase
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
@@ -1,15 +0,0 @@
1
- require File.expand_path('../../unit_test_helper', __FILE__)
2
-
3
- class HtmlEscapeTest < Test::Unit::TestCase
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
@@ -1,65 +0,0 @@
1
- require File.expand_path('../../unit_test_helper', __FILE__)
2
-
3
- class ImageTest < Test::Unit::TestCase
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_https
56
- result = auto_html('https://img.skitch.com/20100910-1wrbg5749xe29ya5t3s85bnaiy.png') { image({:alt => nil}) }
57
- assert_equal '<img src="https://img.skitch.com/20100910-1wrbg5749xe29ya5t3s85bnaiy.png" alt=""/>', result
58
- end
59
-
60
- def test_proxy_option
61
- result = auto_html('http://img.skitch.com/20100910-1wrbg5749xe29ya5t3s85bnaiy.png') { image({:alt => nil,:proxy => "https://proxy/?url="}) }
62
- assert_equal '<img src="https://proxy/?url=http://img.skitch.com/20100910-1wrbg5749xe29ya5t3s85bnaiy.png" alt=""/>', result
63
- end
64
-
65
- end
@@ -1,8 +0,0 @@
1
- require File.expand_path('../../unit_test_helper', __FILE__)
2
-
3
- class InstagramTest < Test::Unit::TestCase
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
- end
@@ -1,55 +0,0 @@
1
- require File.expand_path('../../unit_test_helper', __FILE__)
2
-
3
- class LinkTest < Test::Unit::TestCase
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
@@ -1,15 +0,0 @@
1
- require File.expand_path('../../unit_test_helper', __FILE__)
2
-
3
- class LiveLeakTest < Test::Unit::TestCase
4
-
5
- def test_transform
6
- result = auto_html('http://www.liveleak.com/view?i=BwNrmYRiX_o') { liveleak }
7
- assert_equal '<iframe width="420" height="315" src="http://www.liveleak.com/ll_embed?f=BwNrmYRiX_o" frameborder="0" allowfullscreen></iframe>', result
8
- end
9
-
10
- def test_transform2
11
- result = auto_html('http://www.liveleak.com/ll_embed?f=ef8304ab85e5') { liveleak }
12
- assert_equal '<iframe width="420" height="315" src="http://www.liveleak.com/ll_embed?f=ef8304ab85e5" frameborder="0" allowfullscreen></iframe>', result
13
- end
14
-
15
- end
@@ -1,29 +0,0 @@
1
- require File.expand_path('../../unit_test_helper', __FILE__)
2
-
3
- class MetaCafeTest < Test::Unit::TestCase
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