actionview-encoded_mail_to 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1889e7f329fc1788237954b905303c8ea5e42270
4
- data.tar.gz: 54405ecf947dec7c922eff82ff3560258d89a7e0
3
+ metadata.gz: 81457ed404f7ef4ac2b924a13a7eed04c20e4916
4
+ data.tar.gz: 4b42593a0733d6142d036ba1d987fa6930adc864
5
5
  SHA512:
6
- metadata.gz: f47a5712d7a7287c6c296ba93bec885fa1c5b64a506222369a207af21934bbd76137d2e8eb28ee3926f2daa2895c472c99d497aae24f0e613bb5f9577446b171
7
- data.tar.gz: 7e29b7714b642b5c06f5d9753e3879e91ba0af4b27265d2cfe417dd018610aace5c17ef18a04068da8c116779846dd2b3e77c4ad729c26658e6379cfeb812860
6
+ metadata.gz: 3ddbf2557c87e7b1debd014e21ab2e678411c6293a9ed67064770fbb0a816af3565d48f682d7036f3949499d09cce9be370cd49e46627d95b49a9f6491412194
7
+ data.tar.gz: 8b4ce8561cc71163f7372d86fe5e1d5fed55328cb7701c94f8e4825ff927efeeffb69a8f369b271225607a76ee0af8ec3ea6b6803cbc59f77d0febb710a1f1c4
@@ -46,19 +46,19 @@ module EncodedMailTo
46
46
  # mail_to "me@domain.com", "My email", cc: "ccaddress@domain.com",
47
47
  # subject: "This is an example email"
48
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 = {})
49
+ def mail_to_with_encoding(email_address, name = nil, html_options = {}, &block)
50
50
  html_options.stringify_keys!
51
51
  if %w[encode replace_at replace_dot].none?{ |option| html_options.has_key? option }
52
- mail_to_without_encoding email_address, name, html_options
52
+ mail_to_without_encoding email_address, name, html_options, &block
53
53
  else
54
- _mail_to_with_encoding email_address, name, html_options
54
+ _mail_to_with_encoding email_address, name, html_options, &block
55
55
  end
56
56
  end
57
57
  alias_method_chain :mail_to, :encoding
58
58
 
59
59
  private
60
60
 
61
- def _mail_to_with_encoding(email_address, name = nil, html_options = {})
61
+ def _mail_to_with_encoding(email_address, name = nil, html_options = {}, &block)
62
62
  email_address = ERB::Util.html_escape(email_address)
63
63
 
64
64
  encode = html_options.delete("encode").to_s
@@ -81,10 +81,16 @@ module EncodedMailTo
81
81
  set_attributes += "a.setAttribute('#{name}', '#{value}');"
82
82
  end
83
83
  script_id = rand(36**8).to_s(36)
84
+ if block_given?
85
+ block_content = capture(&block).gsub('\'', %q(\\\')).gsub(/\n/, ' ')
86
+ link_content = "a.innerHTML='#{block_content}';"
87
+ else
88
+ link_content = "a.appendChild(document.createTextNode('#{name || email_address_obfuscated.html_safe}'));"
89
+ end
84
90
  create_link = "var script = document.getElementById('mail_to-#{script_id}');" +
85
91
  "var a = document.createElement('a');" +
86
92
  "#{set_attributes}" +
87
- "a.appendChild(document.createTextNode('#{name || email_address_obfuscated.html_safe}'));" +
93
+ link_content +
88
94
  "script.parentNode.insertBefore(a,script);"
89
95
  create_link.each_byte do |c|
90
96
  string << sprintf("%%%x", c)
@@ -102,9 +108,9 @@ module EncodedMailTo
102
108
  char =~ /\w/ ? sprintf("%%%x", c) : char
103
109
  }.join
104
110
 
105
- content_tag "a", name || email_address_encoded.html_safe, html_options.merge("href" => "#{string}#{extras}".html_safe)
111
+ content_tag "a", name || email_address_encoded.html_safe, html_options.merge("href" => "#{string}#{extras}".html_safe), &block
106
112
  else
107
- content_tag "a", name || email_address_obfuscated.html_safe, html_options.merge("href" => "mailto:#{email_address}#{extras}".html_safe)
113
+ content_tag "a", name || email_address_obfuscated.html_safe, html_options.merge("href" => "mailto:#{email_address}#{extras}".html_safe), &block
108
114
  end
109
115
  end
110
116
  end
@@ -1,5 +1,5 @@
1
1
  module ActionView
2
2
  module EncodedMailTo
3
- VERSION = "1.0.3"
3
+ VERSION = "1.0.4"
4
4
  end
5
5
  end
@@ -6,10 +6,13 @@ require 'action_pack'
6
6
  require 'action_view/helpers/capture_helper'
7
7
  require 'action_view/helpers/url_helper'
8
8
  require 'action_view/encoded_mail_to/mail_to_with_encoding'
9
+ require 'action_view/buffers'
9
10
 
10
11
  class TestActionViewEncodedMailTo < MiniTest::Unit::TestCase
11
12
  include ActionView::Helpers::UrlHelper
12
13
 
14
+ attr_accessor :output_buffer
15
+
13
16
  def test_initialization
14
17
  [:mail_to, :mail_to_with_encoding, :mail_to_without_encoding].each do |method|
15
18
  assert_includes ActionView::Helpers::UrlHelper.instance_methods, method
@@ -44,6 +47,16 @@ class TestActionViewEncodedMailTo < MiniTest::Unit::TestCase
44
47
  )
45
48
  end
46
49
 
50
+ def test_mail_to_with_javascript_and_block
51
+ output = mail_to("me@example.com", nil, encode: "javascript") do
52
+ "<i class='icon-mail'></i>".html_safe
53
+ end
54
+ assert_match(
55
+ /<script id=\"mail_to-\S+\">eval\(decodeURIComponent\('%76%61%72%20%73%63%72%69%70%74%20%3d%20%64%6f%63%75%6d%65%6e%74%2e%67%65%74%45%6c%65%6d%65%6e%74%42%79%49%64%28%27%6d%61%69%6c%5f%74%6f%2d\S+%27%29%3b%76%61%72%20%61%20%3d%20%64%6f%63%75%6d%65%6e%74%2e%63%72%65%61%74%65%45%6c%65%6d%65%6e%74%28%27%61%27%29%3b%61%2e%73%65%74%41%74%74%72%69%62%75%74%65%28%27%68%72%65%66%27%2c%20%27%6d%61%69%6c%74%6f%3a%6d%65%40%65%78%61%6d%70%6c%65%2e%63%6f%6d%27%29%3b%61%2e%69%6e%6e%65%72%48%54%4d%4c%3d%27%3c%69%20%63%6c%61%73%73%3d%5c%27%69%63%6f%6e%2d%6d%61%69%6c%5c%27%3e%3c%2f%69%3e%27%3b%73%63%72%69%70%74%2e%70%61%72%65%6e%74%4e%6f%64%65%2e%69%6e%73%65%72%74%42%65%66%6f%72%65%28%61%2c%73%63%72%69%70%74%29%3b'\)\)<\/script>/,
56
+ output
57
+ )
58
+ end
59
+
47
60
  def test_multiple_mail_to_with_javascript
48
61
  first = mail_to("me@domain.com", "My email", encode: "javascript")
49
62
  second = mail_to("me@domain.com", "My email", encode: "javascript")
@@ -83,6 +96,16 @@ class TestActionViewEncodedMailTo < MiniTest::Unit::TestCase
83
96
  )
84
97
  end
85
98
 
99
+ def test_mail_to_with_hex_and_block
100
+ output = mail_to("me@example.com", nil, encode: "hex") {
101
+ "<i class='icon-cog'></i> Contact Us".html_safe
102
+ }
103
+ assert_equal(
104
+ %{<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;%6d%65@%65%78%61%6d%70%6c%65.%63%6f%6d\"><i class='icon-cog'></i> Contact Us</a>},
105
+ output
106
+ )
107
+ end
108
+
86
109
  def test_mail_to_with_replace_options
87
110
  assert_equal(
88
111
  %{<a href="mailto:me@domain.com">me(at)domain(dot)com</a>},
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.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Reed
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-10 00:00:00.000000000 Z
11
+ date: 2013-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -75,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
75
  version: '0'
76
76
  requirements: []
77
77
  rubyforge_project:
78
- rubygems_version: 2.0.0
78
+ rubygems_version: 2.0.3
79
79
  signing_key:
80
80
  specification_version: 4
81
81
  summary: Deprecated support for email address obfuscation within the mail_to helper