autolinks 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 51d03f82d7621ef0b4475994d54dbe4aee9ac871
4
+ data.tar.gz: 3c781e34ecde513af3635fcc7352674d97b12e3a
5
+ SHA512:
6
+ metadata.gz: d0e7b056e40c2e3771b2e1b7bebcf485f8e825580d6375e286351d34c90ecb7ff69a89b04474f138eda167896cdf706cf063457ef135b9039b2162bc7f389541
7
+ data.tar.gz: 59d6ec4ac3c12511d695e1e9bd06e20c2e745e5f8cc910370404d5dd57749f12e3d16ac1089b6ccf9314bd761a527ac1477d94bd49327f58b99363f95c3082a3
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.gitignore ADDED
@@ -0,0 +1,49 @@
1
+ # rcov generated
2
+ coverage
3
+ coverage.data
4
+
5
+ # rdoc generated
6
+ rdoc
7
+
8
+ # yard generated
9
+ doc
10
+ .yardoc
11
+
12
+ # bundler
13
+ .bundle
14
+
15
+ # jeweler generated
16
+ pkg
17
+
18
+ # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
19
+ #
20
+ # * Create a file at ~/.gitignore
21
+ # * Include files you want ignored
22
+ # * Run: git config --global core.excludesfile ~/.gitignore
23
+ #
24
+ # After doing this, these files will be ignored in all your git projects,
25
+ # saving you from having to 'pollute' every project you touch with them
26
+ #
27
+ # Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
28
+ #
29
+ # For MacOS:
30
+ #
31
+ #.DS_Store
32
+
33
+ # For TextMate
34
+ #*.tmproj
35
+ #tmtags
36
+
37
+ # For emacs:
38
+ #*~
39
+ #\#*
40
+ #.\#*
41
+
42
+ # For vim:
43
+ #*.swp
44
+
45
+ # For redcar:
46
+ #.redcar
47
+
48
+ # For rubinius:
49
+ #*.rbc
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ autolinks
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.0.0
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'rake'
4
+
5
+ # Specify your gem's dependencies in virility.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,34 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ autolinks (0.1.0)
5
+ sanitize
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.2.4)
11
+ ffaker (1.16.2)
12
+ mini_portile (0.5.1)
13
+ nokogiri (1.6.0)
14
+ mini_portile (~> 0.5.0)
15
+ rake (10.1.0)
16
+ rspec (2.14.1)
17
+ rspec-core (~> 2.14.0)
18
+ rspec-expectations (~> 2.14.0)
19
+ rspec-mocks (~> 2.14.0)
20
+ rspec-core (2.14.4)
21
+ rspec-expectations (2.14.0)
22
+ diff-lcs (>= 1.1.3, < 2.0)
23
+ rspec-mocks (2.14.1)
24
+ sanitize (2.0.6)
25
+ nokogiri (>= 1.4.4)
26
+
27
+ PLATFORMS
28
+ ruby
29
+
30
+ DEPENDENCIES
31
+ autolinks!
32
+ ffaker
33
+ rake
34
+ rspec (~> 2.6)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 mindtonic
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = autolinks
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to autolinks
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
+ * Fork the project.
10
+ * Start a feature/bugfix branch.
11
+ * Commit and push until you are happy with your contribution.
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2013 mindtonic. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "autolinks"
18
+ gem.homepage = "http://github.com/mindtonic/autolinks"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{TODO: one-line summary of your gem}
21
+ gem.description = %Q{TODO: longer description of your gem}
22
+ gem.email = "mindtonic@gmail.com"
23
+ gem.authors = ["mindtonic"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ # require 'rcov/rcovtask'
36
+ # Rcov::RcovTask.new do |test|
37
+ # test.libs << 'test'
38
+ # test.pattern = 'test/**/test_*.rb'
39
+ # test.verbose = true
40
+ # test.rcov_opts << '--exclude "gems/*"'
41
+ # end
42
+
43
+ task :default => :test
44
+
45
+ require 'rdoc/task'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "autolinks #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/autolinks.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'autolinks/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ # Details
8
+ gem.name = "autolinks"
9
+ gem.version = Autolinks::VERSION
10
+ gem.authors = ["Jay Sanders"]
11
+ gem.email = ["mindtonic@gmail.com"]
12
+ gem.description = "Autolinks automatically replaces urls, emails, twitter handles and hashtags with html links"
13
+ gem.summary = "Autolinks automatically replaces urls, emails, twitter handles and hashtags with html links"
14
+ gem.homepage = "http://github.com/mindtonic/autolinks"
15
+ gem.license = "MIT"
16
+ # Files
17
+ gem.files = `git ls-files`.split($/)
18
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
19
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
20
+ gem.require_paths = ["lib"]
21
+ # Development
22
+ gem.add_development_dependency "rspec", "~> 2.6"
23
+ gem.add_development_dependency "ffaker"
24
+ # Dependencies
25
+ gem.add_dependency "sanitize"
26
+ end
data/lib/autolinks.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'sanitize'
2
+ require 'autolinks/regex'
3
+ require 'autolinks/parser'
@@ -0,0 +1,39 @@
1
+ module Autolinks
2
+ class Parser
3
+ attr_reader :text
4
+
5
+ def text=(text)
6
+ @text = Sanitize.clean(text)
7
+ end
8
+
9
+ def self.parse(text)
10
+ parser = Parser.new
11
+ parser.text = text
12
+ parser.parse
13
+ end
14
+
15
+ def parse
16
+ replace_url
17
+ replace_handle
18
+ replace_email
19
+ replace_hashtag
20
+ @text
21
+ end
22
+
23
+ def replace_handle
24
+ @text.gsub!(Regex.handle_name, '<a href="http://twitter.com/\1" target="_blank">@\1</a>')
25
+ end
26
+
27
+ def replace_url
28
+ @text.gsub!(Regex.http_address, '<a href="http://\1" target="_blank">\1</a>')
29
+ end
30
+
31
+ def replace_email
32
+ @text.gsub!(Regex.email, '<a href="mailto:\1" target="_blank">\1</a>')
33
+ end
34
+
35
+ def replace_hashtag
36
+ @text.gsub!(Regex.hashtag_name, '<a href="http://twitter.com/search?q=%23\1" target="_blank">#\1</a>')
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,31 @@
1
+ module Autolinks
2
+ class Regex
3
+ def self.handle
4
+ /\B@\w+/i
5
+ end
6
+
7
+ def self.handle_name
8
+ /\B@(\w+)/i
9
+ end
10
+
11
+ def self.http
12
+ /(https?:\/\/[\S]+\.[a-z\/\.]+)/i
13
+ end
14
+
15
+ def self.http_address
16
+ /https?:\/\/([\S]+\.[a-z\/\.]+)/i
17
+ end
18
+
19
+ def self.hashtag
20
+ /(\B#\w+)/i
21
+ end
22
+
23
+ def self.hashtag_name
24
+ /\B#(\w+)/i
25
+ end
26
+
27
+ def self.email
28
+ /(\b[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}\b)/i
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ module Autolinks
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,5 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Autolinks do
4
+ pending "write it"
5
+ end
@@ -0,0 +1,71 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Autolinks::Regex do
4
+ describe "handle" do
5
+ it "should match the handles in the Test String" do
6
+ Autolinks::TEST_STRING.scan(Autolinks::Regex.handle).flatten.should == ["@thishandle", "@thisotherhandle"]
7
+ end
8
+
9
+ it "should match the handles in the Test String" do
10
+ "Follow @mindtonic for more info".scan(Autolinks::Regex.handle).flatten.should == ["@mindtonic"]
11
+ end
12
+ end
13
+
14
+ describe "handle_name" do
15
+ it "should match the handles in the Test String without the @" do
16
+ Autolinks::TEST_STRING.scan(Autolinks::Regex.handle_name).flatten.should == ["thishandle", "thisotherhandle"]
17
+ end
18
+
19
+ it "should match the handles in the Test String without the @" do
20
+ "Follow @mindtonic for more info".scan(Autolinks::Regex.handle_name).flatten.should == ["mindtonic"]
21
+ end
22
+ end
23
+
24
+ describe "http" do
25
+ it "should match the complete urls in the Test String" do
26
+ Autolinks::TEST_STRING.scan(Autolinks::Regex.http).flatten.should == ["http://google.com", "http://google.com/", "http://google.co.uk"]
27
+ end
28
+ end
29
+
30
+ describe "http_address" do
31
+ it "should match the complete urls in the Test String" do
32
+ Autolinks::TEST_STRING.scan(Autolinks::Regex.http_address).flatten.should == ["google.com", "google.com/", "google.co.uk"]
33
+ end
34
+ end
35
+
36
+ describe "hashtag" do
37
+ it "should match the hashtags in the Test String" do
38
+ Autolinks::TEST_STRING.scan(Autolinks::Regex.hashtag).flatten.should == %w{#communicates #hashtags #marked #content #1}
39
+ end
40
+
41
+ it "should match the hashtags in the Test String" do
42
+ "Follow @mindtonic for more #info".scan(Autolinks::Regex.hashtag).flatten.should == ["#info"]
43
+ end
44
+ end
45
+
46
+ describe "hashtag_name" do
47
+ it "should match the hashtags in the Test String without the #" do
48
+ Autolinks::TEST_STRING.scan(Autolinks::Regex.hashtag_name).flatten.should == %w{communicates hashtags marked content 1}
49
+ end
50
+
51
+ it "should match the hashtags in the Test String without the #" do
52
+ "Follow @mindtonic for more #info".scan(Autolinks::Regex.hashtag_name).flatten.should == ["info"]
53
+ end
54
+ end
55
+
56
+ describe "email" do
57
+ it "should match the email in the Test String" do
58
+ Autolinks::TEST_STRING.scan(Autolinks::Regex.email).flatten.should == ["email@email.com"]
59
+ end
60
+
61
+ ["mindtonic@gmail.com", "testing@example.co.uk", "my.email@example.com"].each do |email|
62
+ it "should match #{email}" do
63
+ email.scan(Autolinks::Regex.email).flatten.should == [email]
64
+ end
65
+ end
66
+
67
+ it "should not match emails if there are not any" do
68
+ Faker::Lorem.paragraph.scan(Autolinks::Regex.handle_name).flatten.should == []
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,26 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'ffaker'
5
+ require 'autolinks'
6
+
7
+ # Requires supporting files with custom matchers and macros, etc,
8
+ # in ./support/ and its subdirectories.
9
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
10
+
11
+ RSpec.configure do |config|
12
+ config.filter_run :focus => true
13
+ config.run_all_when_everything_filtered = true
14
+ config.mock_with :rspec
15
+ end
16
+
17
+ #
18
+ # Constants for Testing
19
+ #
20
+
21
+ module Autolinks
22
+ TEST_STRING = "@thishandle #communicates with @thisotherhandle ...
23
+ This is a test string with some #hashtags and other types of #marked #content....
24
+ winning! We're #1! email@email.com. We're also going to test some URL's: http://google.com,
25
+ or http://google.com/, or google.com, or http://google.co.uk, or google.co.uk"
26
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: autolinks
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jay Sanders
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '2.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '2.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: ffaker
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: sanitize
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Autolinks automatically replaces urls, emails, twitter handles and hashtags
56
+ with html links
57
+ email:
58
+ - mindtonic@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - .document
64
+ - .gitignore
65
+ - .rspec
66
+ - .ruby-gemset
67
+ - .ruby-version
68
+ - Gemfile
69
+ - Gemfile.lock
70
+ - LICENSE.txt
71
+ - README.rdoc
72
+ - Rakefile
73
+ - autolinks.gemspec
74
+ - lib/autolinks.rb
75
+ - lib/autolinks/parser.rb
76
+ - lib/autolinks/regex.rb
77
+ - lib/autolinks/version.rb
78
+ - spec/autolinks_spec.rb
79
+ - spec/regex_spec.rb
80
+ - spec/spec_helper.rb
81
+ homepage: http://github.com/mindtonic/autolinks
82
+ licenses:
83
+ - MIT
84
+ metadata: {}
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubyforge_project:
101
+ rubygems_version: 2.0.3
102
+ signing_key:
103
+ specification_version: 4
104
+ summary: Autolinks automatically replaces urls, emails, twitter handles and hashtags
105
+ with html links
106
+ test_files:
107
+ - spec/autolinks_spec.rb
108
+ - spec/regex_spec.rb
109
+ - spec/spec_helper.rb