dejan-auto_html 1.1.2 → 1.2.0

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.
@@ -1,3 +1,9 @@
1
+ == 1.2.0, released 2009-09-26
2
+
3
+ * link filter now uses Rails' link discovery engine. Closes: http://github.com/dejan/auto_html/issues#issue/2 and http://github.com/dejan/auto_html/issues#issue/3 if Rails 2.3+ is in use.
4
+ * added dailymotion filter
5
+ * added sanitize filter
6
+
1
7
  == 1.1.2, released 2009-09-24
2
8
 
3
9
  * link filter fix. Closes: http://github.com/dejan/auto_html/issues#issue/2
@@ -1,6 +1,6 @@
1
1
  = auto_html
2
2
 
3
- Rails plugin for embedding rich content by converting provided URL's to appropriate HTML blocks for links, images, youtube, vimeo, google video and more.
3
+ Rails plugin for transforming urls to appropriate resource (image, link, YouTube, Vimeo video,...). Check out the {live demo}[http://auto_html.rors.org].
4
4
 
5
5
 
6
6
  == Synopsis
@@ -54,6 +54,7 @@ Plugin is highly customizable, and you can easily create new filters that will t
54
54
  == Bundled filters
55
55
 
56
56
  For filter list and options they support check: http://github.com/dejan/auto_html/tree/master/lib/auto_html/filters
57
+ NOTE: auto_html uses Rails' engine for discovering links. There are some bugs with that engine in versions under Rails 2.3.
57
58
 
58
59
 
59
60
  == Install
@@ -63,7 +64,7 @@ For filter list and options they support check: http://github.com/dejan/auto_htm
63
64
  To enable the library in your Rails 2.1 (or greater) project, use the gem configuration method in "config/environment.rb"
64
65
 
65
66
  Rails::Initializer.run do |config|
66
- config.gem 'dejan-auto_html', :version => '~> 1.1.0', :lib => 'auto_html', :source => 'http://gems.github.com'
67
+ config.gem 'dejan-auto_html', :version => '~> 1.1.2', :lib => 'auto_html', :source => 'http://gems.github.com'
67
68
  end
68
69
 
69
70
  === As a Rails plugin
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 1
3
- :minor: 1
4
- :patch: 2
3
+ :minor: 2
4
+ :patch: 0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{auto_html}
8
- s.version = "1.1.2"
8
+ s.version = "1.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Dejan Simic"]
12
- s.date = %q{2009-09-24}
12
+ s.date = %q{2009-09-26}
13
13
  s.description = %q{Automatically transforms urls (via domain) and includes the destination resource (Vimeo, YouTube movie, image, ...) in your document}
14
14
  s.email = %q{desimic@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -28,10 +28,12 @@ Gem::Specification.new do |s|
28
28
  "lib/auto_html/base.rb",
29
29
  "lib/auto_html/builder.rb",
30
30
  "lib/auto_html/filter.rb",
31
+ "lib/auto_html/filters/dailymotion.rb",
31
32
  "lib/auto_html/filters/google_video.rb",
32
33
  "lib/auto_html/filters/html_escape.rb",
33
34
  "lib/auto_html/filters/image.rb",
34
35
  "lib/auto_html/filters/link.rb",
36
+ "lib/auto_html/filters/sanitize.rb",
35
37
  "lib/auto_html/filters/simple_format.rb",
36
38
  "lib/auto_html/filters/vimeo.rb",
37
39
  "lib/auto_html/filters/youtube.rb",
@@ -43,10 +45,12 @@ Gem::Specification.new do |s|
43
45
  "test/functional/auto_html_for_test.rb",
44
46
  "test/test_helper.rb",
45
47
  "test/unit/auto_html_test.rb",
48
+ "test/unit/filters/dailymotion_test.rb",
46
49
  "test/unit/filters/google_video_test.rb",
47
50
  "test/unit/filters/html_escape_test.rb",
48
51
  "test/unit/filters/image_test.rb",
49
52
  "test/unit/filters/link_test.rb",
53
+ "test/unit/filters/sanitize_test.rb",
50
54
  "test/unit/filters/simple_format_test.rb",
51
55
  "test/unit/filters/vimeo_test.rb",
52
56
  "test/unit/filters/youtube_test.rb",
@@ -64,10 +68,12 @@ Gem::Specification.new do |s|
64
68
  "test/functional/auto_html_for_test.rb",
65
69
  "test/test_helper.rb",
66
70
  "test/unit/auto_html_test.rb",
71
+ "test/unit/filters/dailymotion_test.rb",
67
72
  "test/unit/filters/google_video_test.rb",
68
73
  "test/unit/filters/html_escape_test.rb",
69
74
  "test/unit/filters/image_test.rb",
70
75
  "test/unit/filters/link_test.rb",
76
+ "test/unit/filters/sanitize_test.rb",
71
77
  "test/unit/filters/simple_format_test.rb",
72
78
  "test/unit/filters/vimeo_test.rb",
73
79
  "test/unit/filters/youtube_test.rb",
@@ -0,0 +1,6 @@
1
+ AutoHtml.add_filter(:dailymotion).with(:width => 480, :height => 360) do |text, options|
2
+ text.gsub(/http:\/\/www\.dailymotion\.com.*\/video\/(.+)_*/) do
3
+ video_id = $1
4
+ %{<object type="application/x-shockwave-flash" data="http://www.dailymotion.com/swf/#{video_id}&related=0" width="#{options[:width]}" height="#{options[:height]}"><param name="movie" value="http://www.dailymotion.com/swf/#{video_id}&related=0"></param><param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="always"></param><a href="http://www.dailymotion.com/video/#{video_id}?embed=1"><img src="http://www.dailymotion.com/thumbnail/video/#{video_id}" width="#{options[:width]}" height="#{options[:height]}"/></a></object>}
5
+ end
6
+ end
@@ -1,48 +1,5 @@
1
- # major portion of code in here is copied/adjusted from
2
- # ActionView::Helpers::TagHelper and
3
- # ActionView::Helpers::TextHelper
4
- #
5
- AutoHtml.add_filter(:link).with({}) do |text, options|
6
-
7
- def tag_options(options)
8
- unless options.blank?
9
- attrs = []
10
- attrs = options.map { |key, value| %(#{key}="#{value}") }
11
- " #{attrs.sort * ' '}" unless attrs.empty?
12
- end
13
- end
1
+ require 'action_view'
14
2
 
15
- def auto_link_re
16
- %r{
17
- ( # leading text
18
- <\w+.*?>| # leading HTML tag, or
19
- [^=!:'"/]| # leading punctuation, or
20
- ^ # beginning of line
21
- )
22
- (
23
- (?:https?://)| # protocol spec, or
24
- (?:www\.) # www.*
25
- )
26
- (
27
- [-\w]+ # subdomain or domain
28
- (?:\.[-\w]+)* # remaining subdomains or domain
29
- (?::\d+)? # port
30
- (?:/(?:[~\w\+@%=\(\)-]|(?:[,.;:'][^\s$]))*)* # path
31
- (?:[\?|\#][\w\+@%&=.;:-]+)? # query string
32
- (?:\#[\w\-]*)? # trailing anchor
33
- )
34
- ([[:punct:]]|<|$|) # trailing text
35
- }x
36
- end
37
-
38
- extra_options = tag_options(options.stringify_keys) || ""
39
- text.gsub(auto_link_re) do
40
- all, a, b, c, d = $&, $1, $2, $3, $4
41
- if a =~ /<a\s/i # don't replace URL's that are already linked
42
- all
43
- else
44
- text = b + c
45
- %(#{a}<a href="#{b=="www."?"http://www.":b}#{c}"#{extra_options}>#{text}</a>#{d})
46
- end
47
- end
3
+ AutoHtml.add_filter(:link).with({}) do |text, options|
4
+ ActionView::Base.new.auto_link(text, :all, options)
48
5
  end
@@ -0,0 +1,6 @@
1
+ require 'action_controller'
2
+ require 'cgi'
3
+
4
+ AutoHtml.add_filter(:sanitize).with({}) do |text, options|
5
+ HTML::WhiteListSanitizer.new.sanitize(text, options)
6
+ end
@@ -0,0 +1,20 @@
1
+ require File.dirname(__FILE__) + '/../unit_test_helper'
2
+
3
+ class GoogleVideoTest < 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
@@ -7,14 +7,29 @@ class LinkTest < Test::Unit::TestCase
7
7
  assert_equal '<a href="http://vukajlija.com">http://vukajlija.com</a>', result
8
8
  end
9
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
+
10
15
  def test_transform_with_param
11
- result = auto_html('http://google.com/abc?query=ruby') { link }
12
- assert_equal '<a href="http://google.com/abc?query=ruby">http://google.com/abc?query=ruby</a>', result
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
13
28
  end
14
29
 
15
30
  def test_transform_with_params
16
31
  result = auto_html('http://www.youtube.com/watch?v=s5C5Zk4kobo&feature=related') { link }
17
- assert_equal '<a href="http://www.youtube.com/watch?v=s5C5Zk4kobo&feature=related">http://www.youtube.com/watch?v=s5C5Zk4kobo&feature=related</a>', result
32
+ assert_equal '<a href="http://www.youtube.com/watch?v=s5C5Zk4kobo&amp;feature=related">http://www.youtube.com/watch?v=s5C5Zk4kobo&amp;feature=related</a>', result
18
33
  end
19
34
 
20
35
  def test_transform_with_commas
@@ -24,7 +39,7 @@ class LinkTest < Test::Unit::TestCase
24
39
 
25
40
  def test_transform_complex_url
26
41
  result = auto_html("http://www.google.com/#q=nikola+tesla&ct=tesla09&oi=ddle&fp=Xmf0jJ9P_V0") { link }
27
- 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>', result
42
+ 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>', result
28
43
  end
29
44
 
30
45
  def test_transform_with_options
@@ -0,0 +1,36 @@
1
+ require File.dirname(__FILE__) + '/../unit_test_helper'
2
+
3
+ class SanitizeTest < Test::Unit::TestCase
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dejan-auto_html
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dejan Simic
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-24 00:00:00 -07:00
12
+ date: 2009-09-26 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -34,10 +34,12 @@ files:
34
34
  - lib/auto_html/base.rb
35
35
  - lib/auto_html/builder.rb
36
36
  - lib/auto_html/filter.rb
37
+ - lib/auto_html/filters/dailymotion.rb
37
38
  - lib/auto_html/filters/google_video.rb
38
39
  - lib/auto_html/filters/html_escape.rb
39
40
  - lib/auto_html/filters/image.rb
40
41
  - lib/auto_html/filters/link.rb
42
+ - lib/auto_html/filters/sanitize.rb
41
43
  - lib/auto_html/filters/simple_format.rb
42
44
  - lib/auto_html/filters/vimeo.rb
43
45
  - lib/auto_html/filters/youtube.rb
@@ -49,10 +51,12 @@ files:
49
51
  - test/functional/auto_html_for_test.rb
50
52
  - test/test_helper.rb
51
53
  - test/unit/auto_html_test.rb
54
+ - test/unit/filters/dailymotion_test.rb
52
55
  - test/unit/filters/google_video_test.rb
53
56
  - test/unit/filters/html_escape_test.rb
54
57
  - test/unit/filters/image_test.rb
55
58
  - test/unit/filters/link_test.rb
59
+ - test/unit/filters/sanitize_test.rb
56
60
  - test/unit/filters/simple_format_test.rb
57
61
  - test/unit/filters/vimeo_test.rb
58
62
  - test/unit/filters/youtube_test.rb
@@ -91,10 +95,12 @@ test_files:
91
95
  - test/functional/auto_html_for_test.rb
92
96
  - test/test_helper.rb
93
97
  - test/unit/auto_html_test.rb
98
+ - test/unit/filters/dailymotion_test.rb
94
99
  - test/unit/filters/google_video_test.rb
95
100
  - test/unit/filters/html_escape_test.rb
96
101
  - test/unit/filters/image_test.rb
97
102
  - test/unit/filters/link_test.rb
103
+ - test/unit/filters/sanitize_test.rb
98
104
  - test/unit/filters/simple_format_test.rb
99
105
  - test/unit/filters/vimeo_test.rb
100
106
  - test/unit/filters/youtube_test.rb