auto_html 1.3.7 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -56,9 +56,9 @@ AutoHtml is highly customizable, and you can easily create new filters that will
56
56
  end
57
57
 
58
58
 
59
- ## Non-ActiveModel models
59
+ ## Non-ActiveRecord models
60
60
 
61
- AutoHtml uses standard ActiveModel API meaning 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:
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:
62
62
 
63
63
  class Post
64
64
  include Mongoid::Document
@@ -80,31 +80,12 @@ For filter list and options they support check: <http://github.com/dejan/auto_ht
80
80
 
81
81
  ## Install
82
82
 
83
- ### Important note on versions
84
-
85
- 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.
86
-
87
- for Rails <= 2.3.1 use auto_html 1.1.2<br/>
88
- for Rails >= 2.3.2 use the latest auto_html
89
-
90
- ### As a gem
91
-
92
- To enable the library in your Rails 2.1-2.3 project, use the gem configuration method in "config/environment.rb"
93
-
94
- Rails::Initializer.run do |config|
95
- config.gem 'auto_html'
96
- end
97
-
98
- In Rails 3.0 specify the gem in your Gemfile
83
+ Specify the gem in Gemfile of the project
99
84
 
100
85
  gem "auto_html"
101
86
 
102
- ### As a Rails plugin
103
-
104
- script/plugin install git://github.com/dejan/auto_html.git
105
-
106
87
 
107
88
  ## Credits
108
89
 
109
90
  Author: [Dejan Simic](http://github.com/dejan)<br/>
110
- 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), [Daniel Weinmann](https://github.com/danielweinmann)
91
+ 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), [Daniel Weinmann](https://github.com/danielweinmann), [Edgars Beigarts](ebeigarts)
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,9 @@ module AutoHtml
6
6
  def auto_html(raw, &proc)
7
7
  return "" if raw.blank?
8
8
  builder = Builder.new(raw)
9
- builder.instance_eval(&proc)
9
+ result = builder.instance_eval(&proc)
10
+ result.respond_to?(:html_safe) ?
11
+ result.html_safe :
12
+ result
10
13
  end
11
14
  end
@@ -1,5 +1,7 @@
1
- AutoHtml.add_filter(:image) do |text|
1
+ require 'tag_helper'
2
+
3
+ AutoHtml.add_filter(:image).with({:alt => ''}) do |text, options|
2
4
  text.gsub(/https?:\/\/.+\.(jpg|jpeg|bmp|gif|png)(\?\S+)?/i) do |match|
3
- %|<img src="#{match}" alt=""/>|
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
data/lib/auto_html.rb CHANGED
@@ -6,6 +6,11 @@ Dir["#{File.dirname(__FILE__) + '/auto_html/filters'}/**/*"].each do |filter|
6
6
  require "#{filter}"
7
7
  end
8
8
 
9
+ # if rails
9
10
  if defined?(ActiveRecord::Base)
10
11
  ActiveRecord::Base.send :include, AutoHtmlFor
12
+
13
+ module ActionView::Helpers::TextHelper
14
+ include AutoHtml
15
+ end
11
16
  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
@@ -14,27 +14,27 @@ class AutoHtmlTest < Test::Unit::TestCase
14
14
  end
15
15
 
16
16
  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
17
+ result = auto_html("Check the logo: http://rors.org/images/rails.png") { simple_format; image(:alt => nil) }
18
+ assert_equal '<p>Check the logo: <img src="http://rors.org/images/rails.png" /></p>', result
19
19
  end
20
20
 
21
21
  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
22
+ result = auto_html("Check the logo: http://rors.org/images/rails.png. Visit: http://rubyonrails.org") { simple_format; image(:alt => nil); link }
23
+ 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
24
  end
25
25
 
26
26
  def test_should_apply_simple_format_image_and_redcloth_and_link_filter
27
- 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; redcloth; link }
28
- 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> and <a href="http://guides.rubyonrails.org/">Read the Guides</a></p>', result
27
+ 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 }
28
+ 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
29
29
  end
30
30
 
31
31
  def test_should_return_blank_if_input_is_blank
32
- result = auto_html("") { simple_format; image; link }
32
+ result = auto_html("") { simple_format; image(:alt => nil); link }
33
33
  assert_equal "", result
34
34
  end
35
35
 
36
36
  def test_should_not_apply_simple_format_if_input_is_nil
37
- result = auto_html(nil) { simple_format; image; link }
37
+ result = auto_html(nil) { simple_format; image(:alt => nil); link }
38
38
  assert_equal "", result
39
39
  end
40
40
 
@@ -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,38 +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
43
  end
44
44
 
45
45
  def test_https
46
- result = auto_html('https://img.skitch.com/20100910-1wrbg5749xe29ya5t3s85bnaiy.png') { image }
47
- assert_equal '<img src="https://img.skitch.com/20100910-1wrbg5749xe29ya5t3s85bnaiy.png" alt=""/>', result
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
48
48
  end
49
49
 
50
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
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: auto_html
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 7
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
- - 3
9
- - 7
10
- version: 1.3.7
8
+ - 4
9
+ - 0
10
+ version: 1.4.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Dejan Simic
@@ -15,11 +15,11 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-12 00:00:00 +02:00
18
+ date: 2011-07-09 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- name: RedCloth
22
+ name: rinku
23
23
  prerelease: false
24
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
25
  none: false
@@ -32,6 +32,34 @@ dependencies:
32
32
  version: "0"
33
33
  type: :runtime
34
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
35
63
  description: Automatically transforms URIs (via domain) and includes the destination resource (Vimeo, YouTube movie, image, ...) in your document
36
64
  email: desimic@gmail.com
37
65
  executables: []