jekyll-autolink_email 0.0.1 → 0.0.2

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: 0019bccfada298555f99392c9d5b73f427d24b39
4
- data.tar.gz: ee46f617ac3026408ed00f7441a67a2998c3b1f7
3
+ metadata.gz: 5f9e63257e1769963049d9b057bb626bff07abce
4
+ data.tar.gz: 05aa71d54151a148ab8b007bd68d0dc516243010
5
5
  SHA512:
6
- metadata.gz: fc7a834e8b6b33651ea6e1074d2b1a7063b19e0cd23c5b7506085acbb53861fce848c920ab94b22c42efdb2e6ff3e45dfe71a97d4d3ae66da2ebcdc4c25ff419
7
- data.tar.gz: 6da9fd6374a040d909f0e2e4189e677419e19dec975e5aa520f55ebb51c7899039f8d08b86137b027cf17651dd4f3b22beb83ae9e8a4768884f6d1ec02e55e51
6
+ metadata.gz: e38b22b9d087b7cf6b17e56fdd4bf482a41c98b3249d8641b61f3c7d6921937142a00635266d5ec408f3c9e564a50cb329afb6a400aaa72c01d3983d5ee9d8a9
7
+ data.tar.gz: 36e72819a05ff183f8ce05837692fb5cbf1f9feaeb92e8946571d88d3073cf0e4a892a1453fdb0d44b693023fa19c4fa9e520e2dd92d18f386d3a80b8b7ed398
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Jekyll::AutolinkEmail
2
2
 
3
- Autolink emails for your Jekyll Site.
3
+ Autolink emails for your Jekyll site.
4
4
 
5
5
  ## Installation
6
6
 
@@ -31,10 +31,14 @@ autolink_email:
31
31
  skip_tags: ['div'] # tags to skip
32
32
  ```
33
33
 
34
+ Jekyll::AutolinkEmail also provides a `escape: true` option. Turning this on will html encode the email address and url encode the link to prevent spam.
35
+
34
36
  ## Contributing
35
37
 
36
- 1. Fork it ( https://github.com/[my-github-username]/jekyll-autolink/fork )
38
+ 1. Fork it ( https://github.com/ivantsepp/jekyll-autolink_email/fork )
37
39
  2. Create your feature branch (`git checkout -b my-new-feature`)
38
40
  3. Commit your changes (`git commit -am 'Add some feature'`)
39
41
  4. Push to the branch (`git push origin my-new-feature`)
40
42
  5. Create a new Pull Request
43
+
44
+ You should also check out [Jemoji](https://github.com/jekyll/jemoji) and [Jekyll Mentions](https://github.com/jekyll/jekyll-mentions) as those gems were the source of inspiration for this gem.
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "jekyll-autolink_email"
7
- spec.version = "0.0.1"
7
+ spec.version = "0.0.2"
8
8
  spec.authors = ["Ivan Tse"]
9
9
  spec.email = ["ivan.tse1@gmail.com"]
10
10
  spec.summary = "Autolink emails for your Jekyll site."
@@ -4,10 +4,18 @@ require 'rinku'
4
4
  module Jekyll
5
5
  class AutolinkEmail < Jekyll::Generator
6
6
 
7
+ HTML_ENTITIES = {
8
+ '@' => '&#064;',
9
+ '.' => '&#046;'
10
+ }
11
+
12
+ attr_accessor :email_addresses
13
+
7
14
  safe true
8
15
 
9
16
  def initialize(config)
10
17
  config['autolink_email'] ||= {}
18
+ self.email_addresses = []
11
19
  end
12
20
 
13
21
  def generate(site)
@@ -19,7 +27,34 @@ module Jekyll
19
27
  private
20
28
 
21
29
  def autolinkify(page)
22
- page.content = Rinku.auto_link(page.content, :email_addresses, link_attr, skip_tags)
30
+ page.content = Rinku.auto_link(page.content, :email_addresses, link_attr, skip_tags) do |email_address|
31
+ if escape?
32
+ email_addresses << email_address.dup
33
+ html_encode(email_address)
34
+ else
35
+ email_address
36
+ end
37
+ end
38
+ url_encode_email_addresses(page.content) if escape?
39
+ end
40
+
41
+ def html_encode(email_address)
42
+ HTML_ENTITIES.each do |char, code|
43
+ email_address.gsub!(char, code)
44
+ end
45
+ email_address
46
+ end
47
+
48
+ # A hack since Rinku doesn't offer a hook into changing what the link is
49
+ def url_encode_email_addresses(content)
50
+ content.gsub!(/mailto:(#{email_addresses.join('|')})/) do |m|
51
+ m[$1] = ERB::Util.url_encode($1)
52
+ m
53
+ end
54
+ end
55
+
56
+ def escape?
57
+ @site.config['autolink_email']['escape']
23
58
  end
24
59
 
25
60
  def link_attr
@@ -48,5 +48,13 @@ class Jekyll::AutolinkEmailTest < Minitest::Test
48
48
  @autolink_email.generate(@site)
49
49
  assert_equal '<div>ivan.tse1@gmail.com</div>', @page.content
50
50
  end
51
+
52
+ should 'escape email' do
53
+ @site.config['autolink_email']['escape'] = true
54
+ escaped_email_link = '<div><a href="mailto:ivan.tse1%40gmail.com">ivan&#046;tse1&#064;gmail&#046;com</a></div>'
55
+ @autolink_email.instance_variable_set(:@site, @site)
56
+ @autolink_email.send(:autolinkify, @page)
57
+ assert_equal escaped_email_link, @page.content
58
+ end
51
59
  end
52
60
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-autolink_email
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Tse
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-12 00:00:00.000000000 Z
11
+ date: 2014-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll