marcosinger-auto_html 1.3.5 → 1.3.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -47,7 +47,7 @@ If you need to display preview, no problem. Have something like this as action i
47
47
  render :text => comment.body_html
48
48
  end
49
49
 
50
- Plugin is highly customizable, and you can easily create new filters that will transform user input any way you like. For instance, this is the image filter that comes bundled with plugin:
50
+ AutoHtml is highly customizable, and you can easily create new filters that will transform user input any way you like. For instance, this is the image filter that comes bundled with plugin:
51
51
 
52
52
  AutoHtml.add_filter(:image) do |text|
53
53
  text.gsub(/http:\/\/.+\.(jpg|jpeg|bmp|gif|png)(\?\S+)?/i) do |match|
@@ -56,39 +56,36 @@ Plugin is highly customizable, and you can easily create new filters that will t
56
56
  end
57
57
 
58
58
 
59
+ ## Non-ActiveRecord models
59
60
 
60
- ## Bundled filters
61
-
62
- For filter list and options they support check: <http://github.com/dejan/auto_html/tree/master/lib/auto_html/filters>
61
+ AutoHtml uses standard ActiveModel API, which means that you can include AutoHtmlFor module (that automates transformation of the field) in any non-ActiveRecord model that uses ActiveModel. Here's working [mongoid](http://mongoid.org/) example:
63
62
 
63
+ class Post
64
+ include Mongoid::Document
65
+ include AutoHtmlFor
64
66
 
65
- ## Install
67
+ field :body
66
68
 
67
- ### Important note on versions
69
+ auto_html_for :body do
70
+ simple_format
71
+ link
72
+ end
73
+ end
68
74
 
69
- As from version 1.2.0 auto_html uses Rails' engine for discovering links. There are some bugs with that engine in versions under Rails 2.3.2. so it's recommended you use auto_html 1.1.2 in that case, since internal engine is used in that version.
70
75
 
71
- for Rails <= 2.3.1 use auto_html 1.1.2<br/>
72
- for Rails >= 2.3.2 use the latest auto_html
76
+ ## Bundled filters
73
77
 
74
- ### As a gem
78
+ For filter list and options they support check: <http://github.com/dejan/auto_html/tree/master/lib/auto_html/filters>
75
79
 
76
- To enable the library in your Rails 2.1-2.3 project, use the gem configuration method in "config/environment.rb"
77
80
 
78
- Rails::Initializer.run do |config|
79
- config.gem 'auto_html'
80
- end
81
+ ## Install
81
82
 
82
- In Rails 3.0 specify the gem in your Gemfile
83
+ Specify the gem in Gemfile of the project
83
84
 
84
85
  gem "auto_html"
85
86
 
86
- ### As a Rails plugin
87
-
88
- script/plugin install git://github.com/dejan/auto_html.git
89
-
90
87
 
91
88
  ## Credits
92
89
 
93
90
  Author: [Dejan Simic](http://github.com/dejan)<br/>
94
- Contributors: [Claudio Perez Gamayo](http://github.com/crossblaim), [Matt Polito](http://github.com/mattpolito), [Ryan Heneise](http://github.com/mysmallidea), [Caleb Wright](http://github.com/fabrikagency), [Derrick Camerino](https://github.com/robustdj)
91
+ Contributors: [Claudio Perez Gamayo](https://github.com/crossblaim), [Matt Polito](https://github.com/mattpolito), [Ryan Heneise](https://github.com/mysmallidea), [Caleb Wright](https://github.com/fabrikagency), [Derrick Camerino](https://github.com/robustdj), [Daniel Weinmann](https://github.com/danielweinmann), [Edgars Beigarts](https://github.com/ebeigarts), [Henning Thies](https://github.com/henningthies), [rbq](https://github.com/rbq)
data/Rakefile CHANGED
@@ -10,7 +10,7 @@ end
10
10
 
11
11
  desc 'Test with recent versions of Rails'
12
12
  task :test_with_recent do
13
- versions = ['2.3.8', '3.0.3']
13
+ versions = ['2.1.0', '2.2.2', '2.3.8', '3.0.3', '3.0.9']
14
14
  versions.each do |v|
15
15
  puts "\n###### TESTING WITH RAILS #{v}"
16
16
  ENV['RAILS_VERSION'] = v
@@ -6,6 +6,15 @@ Dir["#{File.dirname(__FILE__) + '/auto_html/filters'}/**/*"].each do |filter|
6
6
  require "#{filter}"
7
7
  end
8
8
 
9
- if defined? ActiveRecord::Base
9
+ # if defined? ActiveRecord::Base
10
+ # ActiveRecord::Base.send :include, AutoHtmlFor
11
+ # end
12
+
13
+ # if rails
14
+ if defined?(ActiveRecord::Base)
10
15
  ActiveRecord::Base.send :include, AutoHtmlFor
16
+
17
+ module ActionView::Helpers::TextHelper
18
+ include AutoHtml
19
+ end
11
20
  end
@@ -26,15 +26,18 @@ module AutoHtmlFor
26
26
  raw_attrs = { raw_attrs => AutoHtmlFor.auto_html_for_options[:htmlized_attribute_suffix] } unless raw_attrs.is_a?(Hash)
27
27
 
28
28
  raw_attrs.each do |raw_attr, suffix|
29
- define_method("#{raw_attr}#{suffix}=") do |val|
30
- write_attribute("#{raw_attr}#{suffix}", val)
29
+ method_name = "#{raw_attr}#{suffix}"
30
+
31
+ define_method("#{method_name}=") do |val|
32
+ # att_ - hack for mongoid > 2.1
33
+ write_attribute("attr_#{method_name}", val)
31
34
  end
32
- define_method("#{raw_attr}#{suffix}") do
33
- read_attribute("#{raw_attr}#{suffix}") || send("auto_html_prepare_#{raw_attr}#{suffix}")
35
+ define_method("#{method_name}") do
36
+ # att_ - hack for mongoid > 2.1
37
+ read_attribute("attr_#{method_name}") || send("auto_html_prepare_#{method_name}")
34
38
  end
35
- define_method("auto_html_prepare_#{raw_attr}#{suffix}") do
36
- self.send(raw_attr.to_s + suffix + "=",
37
- auto_html(self.send(raw_attr), &proc))
39
+ define_method("auto_html_prepare_#{method_name}") do
40
+ self.send(raw_attr.to_s + suffix + "=", auto_html(self.send(raw_attr), &proc))
38
41
  end
39
42
  end
40
43
  end
@@ -1,4 +1,6 @@
1
1
  module AutoHtml
2
+ extend self
3
+
2
4
  def self.add_filter(name, &block)
3
5
  AutoHtml::Builder.add_filter(name, &block)
4
6
  end
@@ -6,6 +8,9 @@ module AutoHtml
6
8
  def auto_html(raw, &proc)
7
9
  return "" if raw.blank?
8
10
  builder = Builder.new(raw)
9
- builder.instance_eval(&proc)
11
+ result = builder.instance_eval(&proc)
12
+ return raw if result.nil?
13
+ result.respond_to?(:html_safe) ? result.html_safe : result
10
14
  end
15
+
11
16
  end
@@ -1,5 +1,7 @@
1
- AutoHtml.add_filter(:image) do |text|
2
- text.gsub(/http:\/\/.+\.(jpg|jpeg|bmp|gif|png)(\?\S+)?/i) do |match|
3
- %|<img src="#{match}" alt=""/>|
1
+ require 'tag_helper'
2
+
3
+ AutoHtml.add_filter(:image).with({:alt => ''}) do |text, options|
4
+ text.gsub(/https?:\/\/.+\.(jpg|jpeg|bmp|gif|png)(\?\S+)?/i) do |match|
5
+ TagHelper.image_tag(match, options)
4
6
  end
5
7
  end
@@ -1,5 +1,6 @@
1
- require 'action_view'
1
+ require 'rinku'
2
+ require 'tag_helper'
2
3
 
3
4
  AutoHtml.add_filter(:link).with({}) do |text, options|
4
- ActionView::Base.new.auto_link(text, :html => options, :sanitize => false)
5
+ Rinku.auto_link(text, :all, TagHelper.attributes(options))
5
6
  end
@@ -0,0 +1,9 @@
1
+ require 'redcarpet'
2
+
3
+ AutoHtml.add_filter(:redcarpet).with({}) do |text, options|
4
+ result = Redcarpet.new(text).to_html
5
+ if options and options[:target] and options[:target].to_sym == :_blank
6
+ result.gsub!(/<a/,'<a target="_blank"')
7
+ end
8
+ result
9
+ end
@@ -0,0 +1,9 @@
1
+ require 'redcloth'
2
+
3
+ AutoHtml.add_filter(:redcloth).with({}) do |text, options|
4
+ result = RedCloth.new(text).to_html
5
+ if options and options[:target] and options[:target].to_sym == :_blank
6
+ result.gsub!(/<a/,'<a target="_blank"')
7
+ end
8
+ result
9
+ end
@@ -1,7 +1,7 @@
1
1
  AutoHtml.add_filter(:youtube).with(:width => 390, :height => 250, :frameborder => 0) do |text, options|
2
- regex = /http:\/\/(www.)?youtube\.com\/watch\?v=([A-Za-z0-9._%-]*)(\&\S+)?/
2
+ regex = /http:\/\/(www.)?youtube\.com\/watch\?v=([A-Za-z0-9._%-]*)(\&\S+)?|http:\/\/(www.)?youtu\.be\/([A-Za-z0-9._%-]*)?/
3
3
  text.gsub(regex) do
4
- youtube_id = $2
4
+ youtube_id = $2 || $5
5
5
  width = options[:width]
6
6
  height = options[:height]
7
7
  frameborder = options[:frameborder]
@@ -40,6 +40,6 @@ class AutoHtmlForOptionsTest < Test::Unit::TestCase
40
40
  @article.save!
41
41
 
42
42
  assert_equal %'<iframe src=\"http://player.vimeo.com/video/14074949?title=0&byline=0&portrait=0\" width=\"440\" height=\"248\" frameborder=\"0\"></iframe>', @article.body_to_html
43
- assert_equal 'http://b.vimeocdn.com/ts/937/359/93735969_200.jpg', @article.body_to_image
43
+ assert_equal 'http://b.vimeocdn.com/ts/819/560/81956031_200.jpg', @article.body_to_image
44
44
  end
45
45
  end
@@ -6,7 +6,7 @@ class Article < ActiveRecord::Base
6
6
  html_escape
7
7
  youtube(:width => 400, :height => 250)
8
8
  image
9
- link(:target => "_blank", :rel => "nofollow")
9
+ link(:target => "_blank")
10
10
  simple_format
11
11
  end
12
12
  end
@@ -19,6 +19,12 @@ class AutoHtmlForTest < Test::Unit::TestCase
19
19
  assert_equal '<p>Yo!</p>', @article.body_html
20
20
  end
21
21
 
22
+ def test_html_safe
23
+ return unless "".respond_to?(:html_safe?)
24
+ @article = Article.new(:body => 'Yo!')
25
+ assert @article.body_html.html_safe?
26
+ end
27
+
22
28
  def test_transform_after_save
23
29
  @article = Article.new(:body => 'Yo!')
24
30
  @article.save!
@@ -35,6 +41,6 @@ class AutoHtmlForTest < Test::Unit::TestCase
35
41
  @article = Article.create!(:body => 'Yo!')
36
42
  @article.update_attributes(:body => 'http://vukajlija.com')
37
43
  @article.save!
38
- assert_equal '<p><a href="http://vukajlija.com" rel="nofollow" target="_blank">http://vukajlija.com</a></p>', @article.body_html
44
+ assert_equal '<p><a href="http://vukajlija.com" target="_blank">http://vukajlija.com</a></p>', @article.body_html
39
45
  end
40
46
  end
@@ -3,9 +3,10 @@ require File.expand_path('../unit_test_helper', __FILE__)
3
3
 
4
4
  class AutoHtmlTest < Test::Unit::TestCase
5
5
 
6
- def test_should_be_nil_no_filters_provided
7
- result = auto_html("Hey check out my blog => http://rors.org") { }
8
- assert_nil result
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
9
10
  end
10
11
 
11
12
  def test_should_apply_simple_format_filter
@@ -14,22 +15,27 @@ class AutoHtmlTest < Test::Unit::TestCase
14
15
  end
15
16
 
16
17
  def test_should_apply_simple_format_and_image_filter
17
- result = auto_html("Check the logo: http://rors.org/images/rails.png") { simple_format; image }
18
- assert_equal '<p>Check the logo: <img src="http://rors.org/images/rails.png" alt=""/></p>', result
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" /></p>', result
19
20
  end
20
21
 
21
22
  def test_should_apply_simple_format_image_and_link_filter
22
- result = auto_html("Check the logo: http://rors.org/images/rails.png. Visit: http://rubyonrails.org") { simple_format; image; link }
23
- 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
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" />. Visit: <a href="http://rubyonrails.org" >http://rubyonrails.org</a></p>', result
24
25
  end
25
26
 
27
+ def test_should_apply_simple_format_image_and_redcloth_and_link_filter
28
+ result = auto_html('Check the logo: http://rors.org/images/rails.png. Visit: http://rubyonrails.org and "Read the Guides":http://guides.rubyonrails.org/') { simple_format; image(:alt => nil); redcloth; link }
29
+ assert_equal '<p>Check the logo: <img src="http://rors.org/images/rails.png" />. Visit: <a href="http://rubyonrails.org" >http://rubyonrails.org</a> and <a href="http://guides.rubyonrails.org/">Read the Guides</a></p>', result
30
+ end
31
+
26
32
  def test_should_return_blank_if_input_is_blank
27
- result = auto_html("") { simple_format; image; link }
33
+ result = auto_html("") { simple_format; image(:alt => nil); link }
28
34
  assert_equal "", result
29
35
  end
30
36
 
31
37
  def test_should_not_apply_simple_format_if_input_is_nil
32
- result = auto_html(nil) { simple_format; image; link }
38
+ result = auto_html(nil) { simple_format; image(:alt => nil); link }
33
39
  assert_equal "", result
34
40
  end
35
41
 
@@ -3,8 +3,8 @@ require File.expand_path('../../unit_test_helper', __FILE__)
3
3
  class ImageTest < Test::Unit::TestCase
4
4
 
5
5
  def test_transform
6
- result = auto_html('http://rors.org/images/rails.png') { image }
7
- assert_equal '<img src="http://rors.org/images/rails.png" alt=""/>', result
6
+ result = auto_html('http://rors.org/images/rails.png') { image({:alt => nil}) }
7
+ assert_equal '<img src="http://rors.org/images/rails.png" />', result
8
8
  end
9
9
 
10
10
  def test_dont_transform
@@ -13,33 +13,38 @@ class ImageTest < Test::Unit::TestCase
13
13
  end
14
14
 
15
15
  def test_transform2
16
- result = auto_html('http://farm4.static.flickr.com/3459/3270173112_5099d3d730.jpg') { image }
17
- assert_equal '<img src="http://farm4.static.flickr.com/3459/3270173112_5099d3d730.jpg" alt=""/>', result
16
+ result = auto_html('http://farm4.static.flickr.com/3459/3270173112_5099d3d730.jpg') { image({:alt => nil}) }
17
+ assert_equal '<img src="http://farm4.static.flickr.com/3459/3270173112_5099d3d730.jpg" />', result
18
18
  end
19
19
 
20
20
  def test_transform3
21
- result = auto_html('http://www.lockhartfineart.com/images/Rio_Grande_Frost.JPG') { image }
22
- assert_equal '<img src="http://www.lockhartfineart.com/images/Rio_Grande_Frost.JPG" alt=""/>', result
21
+ result = auto_html('http://www.lockhartfineart.com/images/Rio_Grande_Frost.JPG') { image({:alt => nil}) }
22
+ assert_equal '<img src="http://www.lockhartfineart.com/images/Rio_Grande_Frost.JPG" />', result
23
23
  end
24
24
 
25
25
  def test_transform4
26
- result = auto_html('http://www.lockhartfineart.com/images/Rio_Grande_Frost.JPG') { image }
27
- assert_equal '<img src="http://www.lockhartfineart.com/images/Rio_Grande_Frost.JPG" alt=""/>', result
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" />', result
28
28
  end
29
29
 
30
30
  def test_transform5
31
- result = auto_html('http://farm4.static.flickr.com/3664/3512431377_71b8d002ef.jpg?v=0') { image }
32
- assert_equal '<img src="http://farm4.static.flickr.com/3664/3512431377_71b8d002ef.jpg?v=0" alt=""/>', result
31
+ result = auto_html('http://farm4.static.flickr.com/3664/3512431377_71b8d002ef.jpg?v=0') { image({:alt => nil}) }
32
+ assert_equal '<img src="http://farm4.static.flickr.com/3664/3512431377_71b8d002ef.jpg?v=0" />', result
33
33
  end
34
34
 
35
35
  def test_transform6
36
- result = auto_html('Do you like this logo http://rors.org/images/rails.png? Yeah?') { image }
37
- assert_equal 'Do you like this logo <img src="http://rors.org/images/rails.png" alt=""/>? Yeah?', result
36
+ result = auto_html('Do you like this logo http://rors.org/images/rails.png? Yeah?') { image({:alt => nil}) }
37
+ assert_equal 'Do you like this logo <img src="http://rors.org/images/rails.png" />? Yeah?', result
38
38
  end
39
39
 
40
40
  def test_transform7
41
- result = auto_html('http://tbn3.google.com/images?q=tbn:vS-jtEi9Xc8K6M:http://upload.wikimedia.org/wikipedia/commons/b/ba/Potturinn.jpeg') { image }
42
- 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
41
+ 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}) }
42
+ assert_equal '<img src="http://tbn3.google.com/images?q=tbn:vS-jtEi9Xc8K6M:http://upload.wikimedia.org/wikipedia/commons/b/ba/Potturinn.jpeg" />', result
43
+ end
44
+
45
+ def test_https
46
+ result = auto_html('https://img.skitch.com/20100910-1wrbg5749xe29ya5t3s85bnaiy.png') { image({:alt => nil}) }
47
+ assert_equal '<img src="https://img.skitch.com/20100910-1wrbg5749xe29ya5t3s85bnaiy.png" />', result
43
48
  end
44
49
 
45
50
  end
@@ -4,49 +4,43 @@ class LinkTest < Test::Unit::TestCase
4
4
 
5
5
  def test_transform
6
6
  result = auto_html("http://vukajlija.com") { link }
7
- assert_equal '<a href="http://vukajlija.com">http://vukajlija.com</a>', result
7
+ assert_equal '<a href="http://vukajlija.com" >http://vukajlija.com</a>', result
8
8
  end
9
9
 
10
10
  def test_transform_with_the_slash_at_the_end
11
11
  result = auto_html("http://github.com/") { link }
12
- assert_equal '<a href="http://github.com/">http://github.com/</a>', result
12
+ assert_equal '<a href="http://github.com/" >http://github.com/</a>', result
13
13
  end
14
14
 
15
15
  def test_transform_with_param
16
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
17
+ assert_equal '<a href="http://example.com/abc?query=ruby" >http://example.com/abc?query=ruby</a>', result
18
18
  end
19
19
 
20
20
  def test_transform_with_param_and_trailing_dot
21
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
22
+ assert_equal '<a href="http://example.com/abc?query=ruby" >http://example.com/abc?query=ruby</a>.', result
23
23
  end
24
24
 
25
25
  def test_transform_with_anchor_and_trailing_dot
26
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_params
31
- url = 'http://www.youtube.com/watch?v=s5C5Zk4kobo&feature=related'
32
- # uses auto_link instead raw to support both Rails 2 & 3
33
- assert_equal(ActionView::Base.new.auto_link(url), auto_html(url) { link })
27
+ assert_equal '<a href="http://example.com/example#id=123.12" >http://example.com/example#id=123.12</a>.', result
34
28
  end
35
29
 
36
30
  def test_transform_with_commas
37
31
  result = auto_html('http://www.dw-world.de/dw/article/0,,4708386,00.html?maca=ser-rss-ser-all-1494-rdf') { link }
38
- 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
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
39
33
  end
40
34
 
41
35
  def test_transform_complex_url
42
36
  url = 'http://www.google.com/#q=nikola+tesla&ct=tesla09&oi=ddle&fp=Xmf0jJ9P_V0'
43
37
  # uses auto_link instead raw to support both Rails 2 & 3
44
- assert_equal(ActionView::Base.new.auto_link(url), auto_html(url) { link })
38
+ assert_equal('<a href="http://www.google.com/#q=nikola+tesla&amp;ct=tesla09&amp;oi=ddle&amp;fp=Xmf0jJ9P_V0" >http://www.google.com/#q=nikola+tesla&amp;ct=tesla09&amp;oi=ddle&amp;fp=Xmf0jJ9P_V0</a>', auto_html(url) { link })
45
39
  end
46
40
 
47
41
  def test_transform_with_options
48
- result = auto_html("http://rors.org") { link :rel => "nofollow", :target => "_blank" }
49
- assert_equal '<a href="http://rors.org" rel="nofollow" target="_blank">http://rors.org</a>', result
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
50
44
  end
51
45
 
52
46
  end
@@ -0,0 +1,25 @@
1
+ require File.expand_path('../../unit_test_helper', __FILE__)
2
+
3
+ class RedcarpetTest < Test::Unit::TestCase
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
+ def test_transform_link_target_blank
21
+ result = auto_html('[This is a link](http://example.org/)') { redcarpet :target => :_blank }
22
+ assert_equal '<p><a target="_blank" href="http://example.org/">This is a link</a></p>'+"\n", result
23
+ end
24
+
25
+ end
@@ -0,0 +1,25 @@
1
+ require File.expand_path('../../unit_test_helper', __FILE__)
2
+
3
+ class RedClothTest < Test::Unit::TestCase
4
+
5
+ def test_transform_strong
6
+ result = auto_html("This is *my* text.") { redcloth }
7
+ assert_equal '<p>This is <strong>my</strong> text.</p>', result
8
+ end
9
+
10
+ def test_transform_title
11
+ result = auto_html("h2. This is a title") { redcloth }
12
+ assert_equal '<h2>This is a title</h2>', result
13
+ end
14
+
15
+ def test_transform_link
16
+ result = auto_html('"This is a link (This is a title)":http://www.textism.com') { redcloth }
17
+ assert_equal '<p><a href="http://www.textism.com" title="This is a title">This is a link</a></p>', result
18
+ end
19
+
20
+ def test_transform_link_target_blank
21
+ result = auto_html('"This is a link (This is a title)":http://www.textism.com') { redcloth :target => :_blank }
22
+ assert_equal '<p><a target="_blank" href="http://www.textism.com" title="This is a title">This is a link</a></p>', result
23
+ end
24
+
25
+ end
@@ -31,5 +31,12 @@ class YouTubeTest < Test::Unit::TestCase
31
31
  assert_equal '<iframe class="youtube-player" type="text/html" width="300" height="255" src="http://www.youtube.com/embed/BwNrmYRiX_o" frameborder="1">
32
32
  </iframe>', result
33
33
  end
34
+
35
+
36
+ def test_transform_with_short_url
37
+ result = auto_html('http://www.youtu.be/BwNrmYRiX_o') { youtube }
38
+ assert_equal '<iframe class="youtube-player" type="text/html" width="390" height="250" src="http://www.youtube.com/embed/BwNrmYRiX_o" frameborder="0">
39
+ </iframe>', result
40
+ end
34
41
 
35
42
  end
metadata CHANGED
@@ -1,8 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: marcosinger-auto_html
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 23
4
5
  prerelease:
5
- version: 1.3.5
6
+ segments:
7
+ - 1
8
+ - 3
9
+ - 6
10
+ version: 1.3.6
6
11
  platform: ruby
7
12
  authors:
8
13
  - "Marco Ant\xC3\xB4nio Singer"
@@ -11,20 +16,80 @@ autorequire:
11
16
  bindir: bin
12
17
  cert_chain: []
13
18
 
14
- date: 2011-04-11 00:00:00 -03:00
15
- default_executable:
19
+ date: 2011-10-03 00:00:00 Z
16
20
  dependencies:
17
21
  - !ruby/object:Gem::Dependency
18
- name: hpricot
22
+ name: rinku
19
23
  prerelease: false
20
24
  requirement: &id001 !ruby/object:Gem::Requirement
21
25
  none: false
22
26
  requirements:
23
27
  - - ">="
24
28
  - !ruby/object:Gem::Version
25
- version: 0.8.4
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
26
33
  type: :runtime
27
34
  version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: tag_helper
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :runtime
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: RedCloth
51
+ prerelease: false
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ type: :runtime
62
+ version_requirements: *id003
63
+ - !ruby/object:Gem::Dependency
64
+ name: redcarpet
65
+ prerelease: false
66
+ requirement: &id004 !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ hash: 3
72
+ segments:
73
+ - 0
74
+ version: "0"
75
+ type: :runtime
76
+ version_requirements: *id004
77
+ - !ruby/object:Gem::Dependency
78
+ name: hpricot
79
+ prerelease: false
80
+ requirement: &id005 !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ hash: 55
86
+ segments:
87
+ - 0
88
+ - 8
89
+ - 4
90
+ version: 0.8.4
91
+ type: :runtime
92
+ version_requirements: *id005
28
93
  description: Automatically transforms URIs (via domain) and includes the destination resource (Vimeo, YouTube movie, image, ...) in your document
29
94
  email:
30
95
  - markaum@gmail.com
@@ -47,6 +112,8 @@ files:
47
112
  - lib/auto_html/filters/image.rb
48
113
  - lib/auto_html/filters/link.rb
49
114
  - lib/auto_html/filters/metacafe.rb
115
+ - lib/auto_html/filters/redcarpet.rb
116
+ - lib/auto_html/filters/redcloth.rb
50
117
  - lib/auto_html/filters/sanitize.rb
51
118
  - lib/auto_html/filters/simple_format.rb
52
119
  - lib/auto_html/filters/vimeo.rb
@@ -69,6 +136,8 @@ files:
69
136
  - test/unit/filters/image_test.rb
70
137
  - test/unit/filters/link_test.rb
71
138
  - test/unit/filters/metacafe_test.rb
139
+ - test/unit/filters/redcarpet_test.rb
140
+ - test/unit/filters/redcloth_test.rb
72
141
  - test/unit/filters/sanitize_test.rb
73
142
  - test/unit/filters/simple_format_test.rb
74
143
  - test/unit/filters/vimeo_image_test.rb
@@ -78,7 +147,6 @@ files:
78
147
  - test/unit/filters/youtube_test.rb
79
148
  - test/unit/unit_test_helper.rb
80
149
  - README.md
81
- has_rdoc: true
82
150
  homepage: http://github.com/marcosinger/auto_html
83
151
  licenses: []
84
152
 
@@ -92,17 +160,23 @@ required_ruby_version: !ruby/object:Gem::Requirement
92
160
  requirements:
93
161
  - - ">="
94
162
  - !ruby/object:Gem::Version
163
+ hash: 3
164
+ segments:
165
+ - 0
95
166
  version: "0"
96
167
  required_rubygems_version: !ruby/object:Gem::Requirement
97
168
  none: false
98
169
  requirements:
99
170
  - - ">="
100
171
  - !ruby/object:Gem::Version
172
+ hash: 3
173
+ segments:
174
+ - 0
101
175
  version: "0"
102
176
  requirements: []
103
177
 
104
178
  rubyforge_project:
105
- rubygems_version: 1.5.2
179
+ rubygems_version: 1.8.10
106
180
  signing_key:
107
181
  specification_version: 3
108
182
  summary: Transform URIs to appropriate markup