rails_autolink 1.0.6 → 1.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,7 @@
1
+ === 1.0.7 / 2012-04-27
2
+
3
+ * Added support for non-latin characters in autolinked urls
4
+
1
5
  === 1.0.6 / 2012-03-12
2
6
 
3
7
  * Added sanitize_options arg
@@ -1,5 +1,5 @@
1
1
  module RailsAutolink
2
- VERSION = '1.0.6'
2
+ VERSION = '1.0.7'
3
3
 
4
4
  class Railtie < ::Rails::Railtie
5
5
  initializer 'rails_autolink' do |app|
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module RailsAutolink
2
4
  require 'active_support/core_ext/object/blank'
3
5
  require 'active_support/core_ext/array/extract_options'
@@ -80,6 +82,8 @@ module RailsAutolink
80
82
 
81
83
  BRACKETS = { ']' => '[', ')' => '(', '}' => '{' }
82
84
 
85
+ WORD_PATTERN = RUBY_VERSION < '1.9' ? '\w' : '\p{Word}'
86
+
83
87
  # Turns all urls into clickable links. If a block is given, each url
84
88
  # is yielded and the result is used as the link text.
85
89
  def auto_link_urls(text, html_options = {}, options = {})
@@ -93,7 +97,7 @@ module RailsAutolink
93
97
  href
94
98
  else
95
99
  # don't include trailing punctuation character as part of the URL
96
- while href.sub!(/[^\w\/-]$/, '')
100
+ while href.sub!(/[^#{WORD_PATTERN}\/-]$/, '')
97
101
  punctuation.push $&
98
102
  if opening = BRACKETS[punctuation.last] and href.scan(opening).size > href.scan(punctuation.last).size
99
103
  href << punctuation.pop
@@ -149,4 +153,4 @@ module RailsAutolink
149
153
  end
150
154
  end
151
155
  end
152
- end
156
+ end
@@ -298,6 +298,7 @@ class TestRailsAutolink < MiniTest::Unit::TestCase
298
298
  http://connect.oraclecorp.com/search?search[q]=green+france&search[type]=Group
299
299
  http://of.openfoundry.org/projects/492/download#4th.Release.3
300
300
  http://maps.google.co.uk/maps?f=q&q=the+london+eye&ie=UTF8&ll=51.503373,-0.11939&spn=0.007052,0.012767&z=16&iwloc=A
301
+ http://около.кола/колокола
301
302
  )
302
303
 
303
304
  urls.each do |url|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_autolink
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,11 +11,11 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-03-12 00:00:00.000000000 Z
14
+ date: 2012-04-27 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rails
18
- requirement: &2152957660 !ruby/object:Gem::Requirement
18
+ requirement: &2151842080 !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ~>
@@ -23,10 +23,10 @@ dependencies:
23
23
  version: '3.1'
24
24
  type: :runtime
25
25
  prerelease: false
26
- version_requirements: *2152957660
26
+ version_requirements: *2151842080
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: minitest
29
- requirement: &2152956620 !ruby/object:Gem::Requirement
29
+ requirement: &2151839760 !ruby/object:Gem::Requirement
30
30
  none: false
31
31
  requirements:
32
32
  - - ~>
@@ -34,10 +34,10 @@ dependencies:
34
34
  version: '2.11'
35
35
  type: :development
36
36
  prerelease: false
37
- version_requirements: *2152956620
37
+ version_requirements: *2151839760
38
38
  - !ruby/object:Gem::Dependency
39
39
  name: rdoc
40
- requirement: &2152955520 !ruby/object:Gem::Requirement
40
+ requirement: &2151836700 !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
43
  - - ~>
@@ -45,10 +45,10 @@ dependencies:
45
45
  version: '3.10'
46
46
  type: :development
47
47
  prerelease: false
48
- version_requirements: *2152955520
48
+ version_requirements: *2151836700
49
49
  - !ruby/object:Gem::Dependency
50
50
  name: hoe
51
- requirement: &2152954180 !ruby/object:Gem::Requirement
51
+ requirement: &2151834680 !ruby/object:Gem::Requirement
52
52
  none: false
53
53
  requirements:
54
54
  - - ~>
@@ -56,7 +56,7 @@ dependencies:
56
56
  version: '2.13'
57
57
  type: :development
58
58
  prerelease: false
59
- version_requirements: *2152954180
59
+ version_requirements: *2151834680
60
60
  description: ! 'This is an extraction of the `auto_link` method from rails. The `auto_link`
61
61
 
62
62
  method was removed from Rails in version Rails 3.1. This gem is meant to
@@ -82,7 +82,6 @@ files:
82
82
  - lib/rails_autolink.rb
83
83
  - lib/rails_autolink/helpers.rb
84
84
  - test/test_rails_autolink.rb
85
- - test/test_loco.rb
86
85
  - .gemtest
87
86
  homepage: http://github.com/tenderlove/rails_autolink
88
87
  licenses: []
@@ -111,5 +110,4 @@ signing_key:
111
110
  specification_version: 3
112
111
  summary: This is an extraction of the `auto_link` method from rails
113
112
  test_files:
114
- - test/test_loco.rb
115
113
  - test/test_rails_autolink.rb
@@ -1,64 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require "minitest/autorun"
4
- require "rails"
5
- require "rails_autolink/helpers"
6
- require 'erb'
7
- require 'cgi'
8
- require 'active_support/core_ext/class/attribute_accessors'
9
- require 'action_pack'
10
- require 'action_view/helpers/capture_helper'
11
- require 'action_view/helpers/sanitize_helper'
12
- require 'action_view/helpers/url_helper'
13
- require 'action_view/helpers/tag_helper'
14
- require 'active_support/core_ext/module/attribute_accessors'
15
- require 'active_support/core_ext/string/encoding'
16
- require 'action_dispatch/testing/assertions'
17
- require 'action_view/helpers/text_helper'
18
- require 'action_view/helpers/output_safety_helper'
19
-
20
- class TestRailsAutolink < MiniTest::Unit::TestCase
21
- include ActionView::Helpers::CaptureHelper
22
- include ActionView::Helpers::TextHelper
23
- include ActionView::Helpers::SanitizeHelper
24
- include ActionView::Helpers::TagHelper
25
- include ActionView::Helpers::UrlHelper
26
- include ActionView::Helpers::OutputSafetyHelper
27
- include ActionDispatch::Assertions::DomAssertions
28
-
29
-
30
- def test_loco
31
- t = "OOOOOOOOOOOOOOOOOOOOOOO <h1>textile<a href=\"http://ruby-lang.org\" class='asdasd' target='_blank' >Ruby</a>\n</h1> otro link: www.hola.com"
32
- assert_equal "loco", auto_link(t, :link=> 'urls', :sanitize_options => {:attributes => ["target", "class"], :tags=>[]}, :html=> {:target => '_blank', :mememe=> 'MEM'})
33
- end
34
-
35
- private
36
- def generate_result(link_text, href = nil, escape = false)
37
- href ||= link_text
38
- if escape
39
- %{<a href="#{CGI::escapeHTML href}">#{CGI::escapeHTML link_text}</a>}
40
- else
41
- %{<a href="#{href}">#{link_text}</a>}
42
- end
43
- end
44
-
45
- # from ruby core
46
- def build_message(head, template=nil, *arguments)
47
- template &&= template.chomp
48
- template.gsub(/\?/) { mu_pp(arguments.shift) }
49
- end
50
-
51
- # Temporarily replaces KCODE for the block
52
- def with_kcode(kcode)
53
- if RUBY_VERSION < '1.9'
54
- old_kcode, $KCODE = $KCODE, kcode
55
- begin
56
- yield
57
- ensure
58
- $KCODE = old_kcode
59
- end
60
- else
61
- yield
62
- end
63
- end
64
- end