actionview-encoded_mail_to 1.0.7 → 1.0.8

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7367e1bbaab46baf1d36789ecfb9555999dbbef8
4
- data.tar.gz: 86b92cc6ab525eea60f2a151e9367246870ce49a
3
+ metadata.gz: a8b0721d292877e6dda9b740676c558b44e5d5d3
4
+ data.tar.gz: 0fd2f8f2bdaff2157629e1adca5aa7d288da79ec
5
5
  SHA512:
6
- metadata.gz: dabcd630b11d7b0363ba7bdf69346c6594b10a7ffc73ee1ae3e700bb4316f198d03463a644d99b75f741795d30fc54ee07345b30b692718bb45aacbd09530443
7
- data.tar.gz: ac47e01b32a6623f645b79e157ff8e1e62589132e184decc95f0d4130ec94fef18b19de6fefdaa690fbb66fdecdda15a5c81d0a927a1b02aba6af9dab7f5d370
6
+ metadata.gz: bab2ea1803620e87b920b5aa6422d61b9a4a98ede91cebf438702107e806381da015a74d9ffa8068d589b16656c02013098a775d2981ce556f008300ebe0404b
7
+ data.tar.gz: c173894318bf4f37b9ea55e0407ed0b61f58b97b0e5f7941b37986befe22b63ae918ff1866d8ba1f22b9bcdb24e649a1c624d82e34ccaf70769bca14fd826663
data/.travis.yml CHANGED
@@ -1,7 +1,23 @@
1
1
  language: ruby
2
+ sudo: false
3
+ cache:
4
+ - bundler
2
5
  rvm:
3
- - 1.9.3
4
- - 2.0.0
5
- - 2.1
6
- - 2.2
6
+ - 2.0.0
7
+ - 2.1.10
8
+ - 2.2.5
9
+ - 2.3.1
10
+ before_install: gem update bundler
7
11
  script: bundle exec rake test
12
+ env:
13
+ matrix:
14
+ - RAILS_VERSION="~> 4.0.0"
15
+ - RAILS_VERSION="~> 4.1.0"
16
+ - RAILS_VERSION="~> 4.2.0"
17
+ - RAILS_VERSION="~> 5.0.0"
18
+ matrix:
19
+ exclude:
20
+ - rvm: 2.0.0
21
+ env: RAILS_VERSION="~> 5.0.0"
22
+ - rvm: 2.1.10
23
+ env: RAILS_VERSION="~> 5.0.0"
data/Gemfile CHANGED
@@ -1,3 +1,7 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
+
5
+ gem 'railties', ENV['RAILS_VERSION'] if ENV['RAILS_VERSION']
6
+ gem 'mime-types', '~> 2' if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.0')
7
+ gem 'rack', '~> 1' if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.2')
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  Deprecated support for email address obfuscation within the **mail_to** helper method. Restores the options `:encode`, `:replace_at`, and `:replace_dot`, which were removed from Rails in version 4.0.
5
5
 
6
- Any call to **mail_to** that _doesn't_ include any of these options will be passed through to the core **mail_to** helper (in [ActionView::Helpers::UrlHelper](https://github.com/rails/rails/blob/master/actionpack/lib/action_view/helpers/url_helper.rb)).
6
+ Any call to **mail_to** that _doesn't_ include any of these options will be passed through to the core **mail_to** helper (in [ActionView::Helpers::UrlHelper](https://github.com/rails/rails/blob/master/actionview/lib/action_view/helpers/url_helper.rb)).
7
7
 
8
8
  ## Installation
9
9
 
data/Rakefile CHANGED
@@ -4,4 +4,4 @@ require 'rake/testtask'
4
4
  Rake::TestTask.new do |t|
5
5
  t.libs << 'test'
6
6
  t.pattern = 'test/test_*.rb'
7
- end
7
+ end
@@ -12,7 +12,9 @@ Gem::Specification.new do |s|
12
12
 
13
13
  s.add_dependency 'rails'
14
14
  s.add_development_dependency 'minitest'
15
-
15
+
16
+ s.required_ruby_version = '>= 2.0.0'
17
+
16
18
  s.files = `git ls-files`.split("\n")
17
19
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
20
  s.require_paths = ["lib"]
@@ -1,120 +1,118 @@
1
1
  # encoding: utf-8
2
-
3
- module EncodedMailTo
4
- module ::ActionView
5
- module Helpers
6
- module UrlHelper
7
- # Creates a mailto link tag to the specified +email_address+, which is
8
- # also used as the name of the link unless +name+ is specified. Additional
9
- # HTML attributes for the link can be passed in +html_options+.
10
- #
11
- # +mail_to+ has several methods for hindering email harvesters and customizing
12
- # the email itself by passing special keys to +html_options+.
13
- #
14
- # ==== Options
15
- # * <tt>:encode</tt> - This key will accept the strings "javascript" or "hex".
16
- # Passing "javascript" will dynamically create and encode the mailto link then
17
- # eval it into the DOM of the page. This method will not show the link on
18
- # the page if the user has JavaScript disabled. Passing "hex" will hex
19
- # encode the +email_address+ before outputting the mailto link.
20
- # * <tt>:replace_at</tt> - When the link +name+ isn't provided, the
21
- # +email_address+ is used for the link label. You can use this option to
22
- # obfuscate the +email_address+ by substituting the @ sign with the string
23
- # given as the value.
24
- # * <tt>:replace_dot</tt> - When the link +name+ isn't provided, the
25
- # +email_address+ is used for the link label. You can use this option to
26
- # obfuscate the +email_address+ by substituting the . in the email with the
27
- # string given as the value.
28
- # * <tt>:subject</tt> - Preset the subject line of the email.
29
- # * <tt>:body</tt> - Preset the body of the email.
30
- # * <tt>:cc</tt> - Carbon Copy additional recipients on the email.
31
- # * <tt>:bcc</tt> - Blind Carbon Copy additional recipients on the email.
32
- #
33
- # ==== Examples
34
- # mail_to "me@domain.com"
35
- # # => <a href="mailto:me@domain.com">me@domain.com</a>
36
- #
37
- # mail_to "me@domain.com", "My email", encode: "javascript"
38
- # # => <script>eval(decodeURIComponent('%64%6f%63...%27%29%3b'))</script>
39
- #
40
- # mail_to "me@domain.com", "My email", encode: "hex"
41
- # # => <a href="mailto:%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d">My email</a>
42
- #
43
- # mail_to "me@domain.com", nil, replace_at: "_at_", replace_dot: "_dot_", class: "email"
44
- # # => <a href="mailto:me@domain.com" class="email">me_at_domain_dot_com</a>
45
- #
46
- # mail_to "me@domain.com", "My email", cc: "ccaddress@domain.com",
47
- # subject: "This is an example email"
48
- # # => <a href="mailto:me@domain.com?cc=ccaddress@domain.com&subject=This%20is%20an%20example%20email">My email</a>
49
- def mail_to_with_encoding(email_address, name = nil, html_options = {}, &block)
50
- html_options, name = name || {}, nil if block_given? && html_options.blank?
51
- html_options.stringify_keys!
52
- if %w[encode replace_at replace_dot].none?{ |option| html_options.has_key? option }
53
- mail_to_without_encoding email_address, name, html_options, &block
54
- else
55
- _mail_to_with_encoding email_address, name, html_options, &block
56
- end
2
+ module ActionView
3
+ module EncodedMailTo
4
+ module MailToWithEncoding
5
+ # Creates a mailto link tag to the specified +email_address+, which is
6
+ # also used as the name of the link unless +name+ is specified. Additional
7
+ # HTML attributes for the link can be passed in +html_options+.
8
+ #
9
+ # +mail_to+ has several methods for hindering email harvesters and customizing
10
+ # the email itself by passing special keys to +html_options+.
11
+ #
12
+ # ==== Options
13
+ # * <tt>:encode</tt> - This key will accept the strings "javascript" or "hex".
14
+ # Passing "javascript" will dynamically create and encode the mailto link then
15
+ # eval it into the DOM of the page. This method will not show the link on
16
+ # the page if the user has JavaScript disabled. Passing "hex" will hex
17
+ # encode the +email_address+ before outputting the mailto link.
18
+ # * <tt>:replace_at</tt> - When the link +name+ isn't provided, the
19
+ # +email_address+ is used for the link label. You can use this option to
20
+ # obfuscate the +email_address+ by substituting the @ sign with the string
21
+ # given as the value.
22
+ # * <tt>:replace_dot</tt> - When the link +name+ isn't provided, the
23
+ # +email_address+ is used for the link label. You can use this option to
24
+ # obfuscate the +email_address+ by substituting the . in the email with the
25
+ # string given as the value.
26
+ # * <tt>:subject</tt> - Preset the subject line of the email.
27
+ # * <tt>:body</tt> - Preset the body of the email.
28
+ # * <tt>:cc</tt> - Carbon Copy additional recipients on the email.
29
+ # * <tt>:bcc</tt> - Blind Carbon Copy additional recipients on the email.
30
+ #
31
+ # ==== Examples
32
+ # mail_to "me@domain.com"
33
+ # # => <a href="mailto:me@domain.com">me@domain.com</a>
34
+ #
35
+ # mail_to "me@domain.com", "My email", encode: "javascript"
36
+ # # => <script>eval(decodeURIComponent('%64%6f%63...%27%29%3b'))</script>
37
+ #
38
+ # mail_to "me@domain.com", "My email", encode: "hex"
39
+ # # => <a href="mailto:%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d">My email</a>
40
+ #
41
+ # mail_to "me@domain.com", nil, replace_at: "_at_", replace_dot: "_dot_", class: "email"
42
+ # # => <a href="mailto:me@domain.com" class="email">me_at_domain_dot_com</a>
43
+ #
44
+ # mail_to "me@domain.com", "My email", cc: "ccaddress@domain.com",
45
+ # subject: "This is an example email"
46
+ # # => <a href="mailto:me@domain.com?cc=ccaddress@domain.com&subject=This%20is%20an%20example%20email">My email</a>
47
+ def mail_to(email_address, name = nil, html_options = {}, &block)
48
+ html_options, name = name || {}, nil if block_given? && html_options.blank?
49
+ html_options.stringify_keys!
50
+ if %w[encode replace_at replace_dot].none?{ |option| html_options.has_key? option }
51
+ super email_address, name, html_options, &block
52
+ else
53
+ _mail_to_with_encoding email_address, name, html_options, &block
57
54
  end
58
- alias_method_chain :mail_to, :encoding
59
-
60
- private
61
-
62
- def _mail_to_with_encoding(email_address, name = nil, html_options = {}, &block)
63
- email_address = ERB::Util.html_escape(email_address)
55
+ end
64
56
 
65
- encode = html_options.delete("encode").to_s
57
+ private
66
58
 
67
- extras = %w{ cc bcc body subject }.map { |item|
68
- option = html_options.delete(item) || next
69
- ERB::Util.html_escape "#{item}=#{Rack::Utils.escape_path(option)}"
70
- }.compact
71
- extras = extras.empty? ? '' : '?' + extras.join('&')
59
+ def _mail_to_with_encoding(email_address, name = nil, html_options = {}, &block)
60
+ email_address = ERB::Util.html_escape(email_address)
72
61
 
73
- email_address_obfuscated = email_address.to_str
74
- email_address_obfuscated.gsub!(/@/, html_options.delete("replace_at")) if html_options.key?("replace_at")
75
- email_address_obfuscated.gsub!(/\./, html_options.delete("replace_dot")) if html_options.key?("replace_dot")
62
+ encode = html_options.delete("encode").to_s
76
63
 
77
- case encode
78
- when "javascript"
79
- string = ''
80
- set_attributes = ''
81
- html_options.merge("href" => "mailto:#{email_address}#{extras}".html_safe).each_pair do |name,value|
82
- set_attributes += "a.setAttribute('#{name}', '#{value}');"
83
- end
84
- script_id = rand(36**8).to_s(36)
85
- if block_given?
86
- block_content = capture(&block).gsub('\'', %q(\\\')).gsub(/\n/, ' ')
87
- link_content = "a.innerHTML='#{block_content}';"
88
- else
89
- link_content = "a.appendChild(document.createTextNode('#{name || email_address_obfuscated.html_safe}'));"
90
- end
91
- create_link = "var script = document.getElementById('mail_to-#{script_id}');" +
92
- "var a = document.createElement('a');" +
93
- "#{set_attributes}" +
94
- link_content +
95
- "script.parentNode.insertBefore(a,script);"
96
- create_link.each_byte do |c|
97
- string << sprintf("%%%x", c)
98
- end
99
- "<script id=\"mail_to-#{script_id}\">eval(decodeURIComponent('#{string}'))</script>".html_safe
100
- when "hex"
101
- email_address_encoded = email_address_obfuscated.unpack('C*').map {|c|
102
- sprintf("&#%d;", c)
103
- }.join
64
+ extras = %w{ cc bcc body subject }.map { |item|
65
+ option = html_options.delete(item) || next
66
+ ERB::Util.html_escape "#{item}=#{Rack::Utils.escape_path(option)}"
67
+ }.compact
68
+ extras = extras.empty? ? '' : '?' + extras.join('&')
104
69
 
105
- string = 'mailto:'.unpack('C*').map { |c|
106
- sprintf("&#%d;", c)
107
- }.join + email_address.unpack('C*').map { |c|
108
- char = c.chr
109
- char =~ /\w/ ? sprintf("%%%x", c) : char
110
- }.join
70
+ email_address_obfuscated = email_address.to_str
71
+ email_address_obfuscated.gsub!(/@/, html_options.delete("replace_at")) if html_options.key?("replace_at")
72
+ email_address_obfuscated.gsub!(/\./, html_options.delete("replace_dot")) if html_options.key?("replace_dot")
111
73
 
112
- content_tag "a", name || email_address_encoded.html_safe, html_options.merge("href" => "#{string}#{extras}".html_safe), &block
74
+ case encode
75
+ when "javascript"
76
+ string = ''
77
+ set_attributes = ''
78
+ html_options.merge("href" => "mailto:#{email_address}#{extras}".html_safe).each_pair do |name,value|
79
+ set_attributes += "a.setAttribute('#{name}', '#{value}');"
80
+ end
81
+ script_id = rand(36**8).to_s(36)
82
+ if block_given?
83
+ block_content = capture(&block).gsub('\'', %q(\\\')).gsub(/\n/, ' ')
84
+ link_content = "a.innerHTML='#{block_content}';"
113
85
  else
114
- content_tag "a", name || email_address_obfuscated.html_safe, html_options.merge("href" => "mailto:#{email_address}#{extras}".html_safe), &block
86
+ link_content = "a.appendChild(document.createTextNode('#{name || email_address_obfuscated.html_safe}'));"
115
87
  end
88
+ create_link = "var script = document.getElementById('mail_to-#{script_id}');" +
89
+ "var a = document.createElement('a');" +
90
+ "#{set_attributes}" +
91
+ link_content +
92
+ "script.parentNode.insertBefore(a,script);"
93
+ create_link.each_byte do |c|
94
+ string << sprintf("%%%x", c)
95
+ end
96
+ "<script id=\"mail_to-#{script_id}\">eval(decodeURIComponent('#{string}'))</script>".html_safe
97
+ when "hex"
98
+ email_address_encoded = email_address_obfuscated.unpack('C*').map {|c|
99
+ sprintf("&#%d;", c)
100
+ }.join
101
+
102
+ string = 'mailto:'.unpack('C*').map { |c|
103
+ sprintf("&#%d;", c)
104
+ }.join + email_address.unpack('C*').map { |c|
105
+ char = c.chr
106
+ char =~ /\w/ ? sprintf("%%%x", c) : char
107
+ }.join
108
+
109
+ content_tag "a", name || email_address_encoded.html_safe, html_options.merge("href" => "#{string}#{extras}".html_safe), &block
110
+ else
111
+ content_tag "a", name || email_address_obfuscated.html_safe, html_options.merge("href" => "mailto:#{email_address}#{extras}".html_safe), &block
116
112
  end
117
- end
113
+ end
118
114
  end
119
115
  end
120
116
  end
117
+
118
+ ActionView::Helpers::UrlHelper.send :prepend, ActionView::EncodedMailTo::MailToWithEncoding
@@ -1,5 +1,5 @@
1
1
  module ActionView
2
2
  module EncodedMailTo
3
- VERSION = "1.0.7"
3
+ VERSION = "1.0.8"
4
4
  end
5
5
  end
@@ -9,17 +9,11 @@ require 'action_view/helpers/url_helper'
9
9
  require 'action_view/encoded_mail_to/mail_to_with_encoding'
10
10
  require 'action_view/buffers'
11
11
 
12
- class TestActionViewEncodedMailTo < MiniTest::Test
12
+ class TestActionViewEncodedMailTo < MiniTest::Unit::TestCase
13
13
  include ActionView::Helpers::UrlHelper
14
14
 
15
15
  attr_accessor :output_buffer
16
16
 
17
- def test_initialization
18
- [:mail_to, :mail_to_with_encoding, :mail_to_without_encoding].each do |method|
19
- assert_includes ActionView::Helpers::UrlHelper.instance_methods, method
20
- end
21
- end
22
-
23
17
  def test_mail_to
24
18
  assert_equal %{<a href="mailto:nick@example.com">nick@example.com</a>}, mail_to("nick@example.com")
25
19
  assert_equal %{<a href="mailto:nick@example.com">Nick Reed</a>}, mail_to("nick@example.com", "Nick Reed")
@@ -35,7 +29,7 @@ class TestActionViewEncodedMailTo < MiniTest::Test
35
29
 
36
30
  def test_mail_to_without_encoding
37
31
  assert_equal mail_to("nick@example.com", "Nick Reed"),
38
- mail_to_without_encoding("nick@example.com", "Nick Reed")
32
+ "<a href=\"mailto:nick@example.com\">Nick Reed</a>"
39
33
  end
40
34
 
41
35
  def test_mail_to_with_javascript
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: actionview-encoded_mail_to
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.7
4
+ version: 1.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Reed
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-08 00:00:00.000000000 Z
11
+ date: 2016-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -67,7 +67,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
67
67
  requirements:
68
68
  - - ">="
69
69
  - !ruby/object:Gem::Version
70
- version: '0'
70
+ version: 2.0.0
71
71
  required_rubygems_version: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="