jekyll-email-protect 1.0.0 → 1.0.1

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: 49aef42f85f248f6e7b00229d4c40fcd5f4fabb1
4
- data.tar.gz: 7ba84f7328c3cf57aebf83a172c92309d684b657
3
+ metadata.gz: 1d273a3c3ef11a835e9c6c770f06f81c249f665f
4
+ data.tar.gz: 14cb77041dc95e53c7cf295b4490f0bf2c790a09
5
5
  SHA512:
6
- metadata.gz: a204a430f683104401d26ff7f4edbbf0f5a216744123fe3c05fedc68b26de9aa1d7e0ea4ebf5b83f1d3e6d99ca1165978c317504d9b1bc49cdcecb7d9ab134d8
7
- data.tar.gz: 3d4dcea9eba4e0ba44dc3b7e5e54c9db1d6c70bf74ee6513e14628967b89214df7e69a4312c4cf29cd0b5f9167e15da03e8faaf3e5b32fc322f34e8e1bfd54ef
6
+ metadata.gz: 0e8f95d5593a7e33e1394f18c984f7adaa7a6e86e124ed78394433aee209f0115618cbbdcd35f43ecc8a4ed000cd55492ba32c544de42265ed14f9f228833ef6
7
+ data.tar.gz: afa24eb781878a66dac1d1099007cb5620a36ecfad3fa933f7e6fed553cb02cd260298550ea467311fe7e24b6cb0379a31794cb0609eaf970710adf23f280c9e
data/README.md CHANGED
@@ -34,7 +34,17 @@ gems:
34
34
  In your markup, simply use the `protect_email` liquid filter made available through this plugin:
35
35
 
36
36
  ```
37
- {{ 'example@example.com' | protect_email }}
37
+ {{ 'example@example.com' | encode_email }}
38
+ ```
39
+
40
+ The above code will yield `%65%78%61%6D%70%6C%65@%65%78%61%6D%70%6C%65.%63%6F%6D`. Only use this filter within the `href` attribute of a given link.
41
+
42
+ ## Example
43
+
44
+ The following example shows how this plugin can be used to protect the `site`'s email address:
45
+
46
+ ```
47
+ <a href="mailto:{{ site.email | protect_email }}" title="Contact me">Contact me</a>
38
48
  ```
39
49
 
40
50
  # Contribute
@@ -1,9 +1,17 @@
1
- require 'addressable/uri'
2
-
3
1
  module JekyllEmailProtect
4
2
  module EmailProtectionFilter
5
- def protect_email(email)
6
- Addressable::URI.encode_component(email, /[^\.@]/)
3
+
4
+ # Percent-encode alphanumeric characters of an email address
5
+ def encode_email(input)
6
+ input.to_s.chars.inject("") do |result, char|
7
+ if char =~ /\p{Alnum}/
8
+ char.bytes.inject(result) do |result, byte|
9
+ result << '%%%02X' % byte
10
+ end
11
+ else
12
+ result << char
13
+ end
14
+ end
7
15
  end
8
16
  end
9
17
  end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe(JekyllEmailProtect::EmailProtectionFilter) do
4
+ let(:output) do
5
+ doc = doc_with_content(content)
6
+ doc.content = content
7
+ doc.output = Jekyll::Renderer.new(doc.site, doc).run
8
+ end
9
+
10
+ context "simple example address" do
11
+ let(:email) { "example@example.com" }
12
+ let(:content) { "{{ '#{email}' | encode_email }}" }
13
+
14
+ it "produces the correct percent-encoded email" do
15
+ expect(output).to match(/%65%78%61%6D%70%6C%65@%65%78%61%6D%70%6C%65\.%63%6F%6D/)
16
+ end
17
+ end
18
+
19
+ context "example address with plus and dash" do
20
+ let(:email) { "example-person+spam@example.com" }
21
+ let(:content) { "{{ '#{email}' | encode_email }}" }
22
+
23
+ it "produces the correct percent-encoded email" do
24
+ expect(output).to match(/%65%78%61%6D%70%6C%65\-%70%65%72%73%6F%6E\+%73%70%61%6D@%65%78%61%6D%70%6C%65\.%63%6F%6D/)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,42 @@
1
+ TEST_DIR = File.dirname(__FILE__)
2
+ TMP_DIR = File.expand_path("../tmp", TEST_DIR)
3
+
4
+ require 'jekyll'
5
+ require File.expand_path("../lib/jekyll-email-protect.rb", TEST_DIR)
6
+ Jekyll.logger.log_level = :error
7
+ STDERR.reopen(test(?e, '/dev/null') ? '/dev/null' : 'NUL:')
8
+
9
+ RSpec.configure do |config|
10
+ config.run_all_when_everything_filtered = true
11
+ config.filter_run :focus
12
+ config.order = 'random'
13
+
14
+ def tmp_dir(*files)
15
+ File.join(TMP_DIR, *files)
16
+ end
17
+
18
+ def source_dir(*files)
19
+ tmp_dir('source', *files)
20
+ end
21
+
22
+ def dest_dir(*files)
23
+ tmp_dir('dest', *files)
24
+ end
25
+
26
+ def doc_with_content(content, opts = {})
27
+ my_site = site
28
+ Jekyll::Document.new(source_dir('_test/doc.md'), {site: my_site, collection: collection(my_site)})
29
+ end
30
+
31
+ def collection(site, label = 'test')
32
+ Jekyll::Collection.new(site, label)
33
+ end
34
+
35
+ def site(opts = {})
36
+ conf = Jekyll::Utils.deep_merge_hashes(Jekyll::Configuration::DEFAULTS, opts.merge({
37
+ "source" => source_dir,
38
+ "destination" => dest_dir
39
+ }))
40
+ Jekyll::Site.new(conf)
41
+ end
42
+ end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-email-protect
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vincent Wochnik
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-20 00:00:00.000000000 Z
11
+ date: 2015-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: addressable
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - '>='
18
- - !ruby/object:Gem::Version
19
- version: 2.3.8
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - '>='
25
- - !ruby/object:Gem::Version
26
- version: 2.3.8
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: jekyll
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -40,20 +26,6 @@ dependencies:
40
26
  version: '3.0'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: rspec
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ~>
46
- - !ruby/object:Gem::Version
47
- version: '3.0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ~>
53
- - !ruby/object:Gem::Version
54
- version: '3.0'
55
- - !ruby/object:Gem::Dependency
56
- name: rake
57
29
  requirement: !ruby/object:Gem::Requirement
58
30
  requirements:
59
31
  - - '>='
@@ -90,6 +62,8 @@ files:
90
62
  - lib/jekyll-email-protect.rb
91
63
  - README.md
92
64
  - LICENSE.md
65
+ - spec/protect_email_filter_spec.rb
66
+ - spec/spec_helper.rb
93
67
  homepage: https://github.com/vwochnik/jekyll-email-protect
94
68
  licenses:
95
69
  - MIT
@@ -102,7 +76,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
102
76
  requirements:
103
77
  - - '>='
104
78
  - !ruby/object:Gem::Version
105
- version: '0'
79
+ version: 1.9.3
106
80
  required_rubygems_version: !ruby/object:Gem::Requirement
107
81
  requirements:
108
82
  - - '>='
@@ -115,4 +89,6 @@ signing_key:
115
89
  specification_version: 4
116
90
  summary: This plugin provides a simple liquid filter which converts emails into percent-encoded
117
91
  strings.
118
- test_files: []
92
+ test_files:
93
+ - spec/protect_email_filter_spec.rb
94
+ - spec/spec_helper.rb