spamspanify 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --format nested
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in spamspanify.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Corné Verbruggen
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # Spamspanify
2
+
3
+ Extends the String class with a {String#spamspanify} method that converts email
4
+ addresses in the string into [SpamSpan](http://www.spamspan.com) HTML markup.
5
+ This HTML markup can then easily be transformed in a clickable mailto link in
6
+ the browser by using the SpanSpan javascript library.
7
+
8
+ __Note:__ Currently only paranoia levels 1 and 3 are supported.
9
+ See the [SpamSpan website](http://www.spamspan.com) for info on paranoia
10
+ levels.
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ gem 'spamspanify'
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install spamspanify
25
+
26
+ ## Usage
27
+
28
+ Simply call the {String#spamspanify} method on a string.
29
+
30
+ ## Contributing
31
+
32
+ 1. Fork it
33
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
34
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
35
+ 4. Push to the branch (`git push origin my-new-feature`)
36
+ 5. Create new Pull Request
37
+
38
+ ## License
39
+
40
+ Spamspanify is released under a MIT License
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,10 @@
1
+ class String
2
+ # Converts plain email addresses and mailto links into SpamSpan markup.
3
+ #
4
+ # @param [Integer] paranoia_level SpamSpan paranoia level
5
+ # @return [String] the input with all plain email addresses converted to
6
+ # SpamSpam markup
7
+ def spamspanify paranoia_level = 1
8
+ Spamspanify.all(self, paranoia_level)
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module Spamspanify
2
+ class ParanoiaLevelNotSupportedError < StandardError; end
3
+ end
@@ -0,0 +1,3 @@
1
+ module Spamspanify
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,74 @@
1
+ require "spamspanify/version"
2
+ require "spamspanify/core_ext/string"
3
+ require "spamspanify/exceptions"
4
+
5
+ module Spamspanify
6
+ EMAIL_REGEXP = /([\w|\-\.])+@([\w|\-\.])+\w+/
7
+ MAILTO_REGEXP = /<a\s*href=(\'|\")mailto:#{ EMAIL_REGEXP }(\'|\").*<\/a>/
8
+
9
+ module_function
10
+
11
+ # Converts plain email addresses and mailto links in the input into SpamSpan
12
+ # markup.
13
+ #
14
+ # @param [String] input
15
+ # @param [Integer] paranoia_level SpamSpan paranoia level
16
+ # @return [String] the input with all plain email addresses converted to
17
+ # SpamSpam markup
18
+ def all input, paranoia_level = 1
19
+ plain_email_addresses(mailto_links(input, paranoia_level), paranoia_level)
20
+ end
21
+
22
+ # Converts all plain email addresses in the input into SpamSpan markup.
23
+ #
24
+ # @param [String] input
25
+ # @param [Integer] paranoia_level SpamSpan paranoia level
26
+ # @return [String] the input with all plain email addresses converted to
27
+ # SpamSpam markup
28
+ def plain_email_addresses input, paranoia_level = 1
29
+ input.gsub(EMAIL_REGEXP) do |email|
30
+ create_markup(email, paranoia_level)
31
+ end
32
+ end
33
+
34
+ # Converts all HTML mailto links in the input into SpamSpan markup.
35
+ #
36
+ # @param [String] input
37
+ # @param [Integer] paranoia_level SpamSpan paranoia level
38
+ # @return [String] the input with all plain email addresses converted to
39
+ # SpamSpam markup
40
+ def mailto_links input, paranoia_level = 1
41
+ input.gsub(MAILTO_REGEXP) do |mailto|
42
+ create_markup(mailto[EMAIL_REGEXP], paranoia_level)
43
+ end
44
+ end
45
+
46
+ # Creates SpanSpam HTML markup.
47
+ #
48
+ # @param [String] email_address
49
+ # @param [Integer] paranoia_level
50
+ # @return [String] SpamSpan HTML markup
51
+ # @raise [Spamspanify::ParanoiaLevelNotSupportedError] when a not supported
52
+ # paranoia level is requested
53
+ def create_markup email_address, paranoia_level = 1
54
+ user, domain = email_address.split("@")
55
+ case paranoia_level
56
+ when 1
57
+ "<span class='spamspan'><span class='u'>#{ user }</span>@<span class='d'>"\
58
+ "#{ domain }</span></span>"
59
+ when 3
60
+ "<span class='spamspan'><span class='u'>#{ undotify(user) }</span> [at] "\
61
+ "<span class='d'>#{ undotify(domain) }</span></span>"
62
+ else
63
+ Raise ParanoiaLevelNotSupportError
64
+ end
65
+ end
66
+
67
+ # Converts every "." in a string into " [dot] "
68
+ #
69
+ # @param [String] input
70
+ # @return [String] the input with each dot replaced by " [dot] "
71
+ def undotify input
72
+ input.gsub ".", " [dot] "
73
+ end
74
+ end
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'spamspanify/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "spamspanify"
8
+ gem.version = Spamspanify::VERSION
9
+ gem.authors = ["Corné Verbruggen"]
10
+ gem.email = ["corne@g-majeur.nl"]
11
+ gem.description = %q{
12
+ Spamspanify extends the String class with a spamspanify method that
13
+ replaces all email addresses in a string with HTML markup that can be
14
+ handled by the SpamSpan javascript library.
15
+ }
16
+ gem.summary = "Transforms email addresses in a string into SpamSpam markup"
17
+ gem.homepage = "https://github.com/g-majeur/spamspanify"
18
+
19
+ gem.files = `git ls-files`.split($/)
20
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
21
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
22
+ gem.require_paths = ["lib"]
23
+
24
+ gem.add_development_dependency "rake"
25
+ gem.add_development_dependency "rspec", "~> 2.12"
26
+ gem.add_development_dependency "yard", "~> 0.8.3"
27
+ end
@@ -0,0 +1,27 @@
1
+ require "spec_helper"
2
+
3
+ describe Spamspanify do
4
+
5
+ describe "replaces an email address in a string with SpamSpan markup" do
6
+ let(:s){ "Email b.flat@minor.com please." }
7
+
8
+ it "of paranoia level 1" do
9
+ expect(s.spamspanify(1)).to eq "Email <span class='spamspan'><span class='u'>b.flat</span>@<span class='d'>minor.com</span></span> please."
10
+ end
11
+
12
+ it "of paranoia level 3" do
13
+ expect(s.spamspanify(3)).to eq "Email <span class='spamspan'><span class='u'>b [dot] flat</span> [at] <span class='d'>minor [dot] com</span></span> please."
14
+ end
15
+ end
16
+
17
+ it "does not include a dot as the last character of an address" do
18
+ s = "Email major.seven@a-flat.com."
19
+ expect(s.spamspanify).to eq "Email <span class='spamspan'><span class="\
20
+ "'u'>major.seven</span>@<span class='d'>a-flat.com</span></span>."
21
+ end
22
+
23
+ it "should transform html <a href='mailto:..> links as well", focus: true do
24
+ s = "Email <a href='mailto:b.flat@minor.com'>B.Flat</a> please."
25
+ expect(s.spamspanify(1)).to eq "Email <span class='spamspan'><span class='u'>b.flat</span>@<span class='d'>minor.com</span></span> please."
26
+ end
27
+ end
@@ -0,0 +1,6 @@
1
+ require "rspec"
2
+ require "spamspanify"
3
+
4
+ RSpec.configure do |config|
5
+
6
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spamspanify
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Corné Verbruggen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '2.12'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '2.12'
46
+ - !ruby/object:Gem::Dependency
47
+ name: yard
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 0.8.3
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.8.3
62
+ description: ! "\n Spamspanify extends the String class with a spamspanify method
63
+ that\n replaces all email addresses in a string with HTML markup that can be\n
64
+ \ handled by the SpamSpan javascript library.\n "
65
+ email:
66
+ - corne@g-majeur.nl
67
+ executables: []
68
+ extensions: []
69
+ extra_rdoc_files: []
70
+ files:
71
+ - .gitignore
72
+ - .rspec
73
+ - Gemfile
74
+ - LICENSE.txt
75
+ - README.md
76
+ - Rakefile
77
+ - lib/spamspanify.rb
78
+ - lib/spamspanify/core_ext/string.rb
79
+ - lib/spamspanify/exceptions.rb
80
+ - lib/spamspanify/version.rb
81
+ - spamspanify.gemspec
82
+ - spec/spamspanify_spec.rb
83
+ - spec/spec_helper.rb
84
+ homepage: https://github.com/g-majeur/spamspanify
85
+ licenses: []
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ requirements: []
103
+ rubyforge_project:
104
+ rubygems_version: 1.8.24
105
+ signing_key:
106
+ specification_version: 3
107
+ summary: Transforms email addresses in a string into SpamSpam markup
108
+ test_files:
109
+ - spec/spamspanify_spec.rb
110
+ - spec/spec_helper.rb
111
+ has_rdoc: