smart_slug 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +3 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +11 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +24 -0
- data/LICENSE +20 -0
- data/README.md +50 -0
- data/Rakefile +36 -0
- data/lib/smart_slug/version.rb +3 -0
- data/lib/smart_slug.rb +79 -0
- data/smart_slug.gemspec +21 -0
- data/spec/smart_slug_spec.rb +17 -0
- data/spec/spec_helper.rb +11 -0
- metadata +74 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0475abdf7a2d3214e0dbc41c7fa33485365a32a1
|
4
|
+
data.tar.gz: 7048c0867c23ea2894fd17485b89c9ecf3f45557
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4e760a6cdf1aa0f39b2a316860382c741ed5b031f5b47e14a769615de974fbd2f3bc266d103b54bc1df68f15c598ab118896462f93fb494ae70312e907fd6bf0
|
7
|
+
data.tar.gz: c156243209bc5b41e19973f34681f43c441d00e166542651309245650535509e49c9377e368b01b1efc709a9e63b9d47f085b19dec5c62573032b9abcb93a594
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
smart_slug
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.1.0
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
smart_slug (0.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.2.5)
|
10
|
+
rspec (2.14.1)
|
11
|
+
rspec-core (~> 2.14.0)
|
12
|
+
rspec-expectations (~> 2.14.0)
|
13
|
+
rspec-mocks (~> 2.14.0)
|
14
|
+
rspec-core (2.14.7)
|
15
|
+
rspec-expectations (2.14.5)
|
16
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
17
|
+
rspec-mocks (2.14.5)
|
18
|
+
|
19
|
+
PLATFORMS
|
20
|
+
ruby
|
21
|
+
|
22
|
+
DEPENDENCIES
|
23
|
+
rspec (= 2.14.1)
|
24
|
+
smart_slug!
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2014 Rafael Lima
|
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.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# Smart Slug [![Build Status](https://travis-ci.org/rafaelp/smart_slug.png?v=1)](https://travis-ci.org/rafaelp/smart_slug)
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
Add this lines to your Application's Gemfile:
|
6
|
+
|
7
|
+
gem 'smart_slug'
|
8
|
+
|
9
|
+
And then execute:
|
10
|
+
|
11
|
+
$ bundle
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
require 'smart_slug'
|
17
|
+
|
18
|
+
slug = SmartSlug.new(" Coração ")
|
19
|
+
=> #<SmartSlug:0x007ff0c20907a8 @original=" Coração ", @slug="coracao">
|
20
|
+
|
21
|
+
slug.to_s
|
22
|
+
=> "coracao"
|
23
|
+
|
24
|
+
slug == 'coracao'
|
25
|
+
=> true
|
26
|
+
```
|
27
|
+
|
28
|
+
## Versioning
|
29
|
+
|
30
|
+
Smart Slug follow the [Semantic Versioning](http://semver.org/).
|
31
|
+
|
32
|
+
## Issues
|
33
|
+
|
34
|
+
If you have problems, please create a [Github Issue](https://github.com/rafaelp/smart_slug/issues).
|
35
|
+
|
36
|
+
## Contributing
|
37
|
+
|
38
|
+
1. Fork it
|
39
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
40
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
41
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
42
|
+
5. Create new Pull Request
|
43
|
+
|
44
|
+
## Credits
|
45
|
+
|
46
|
+
Smart Slug was written by [Rafael Lima](http://rafael.adm.br).
|
47
|
+
|
48
|
+
## License
|
49
|
+
|
50
|
+
Smart Slug is Copyright © 2014 Rafael Lima. It is free software, and may be redistributed under the terms specified in the [LICENSE](https://github.com/rafaelp/smart_slug/blob/master/LICENSE) file.
|
data/Rakefile
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'rdoc/task'
|
9
|
+
rescue LoadError
|
10
|
+
require 'rdoc/rdoc'
|
11
|
+
require 'rake/rdoctask'
|
12
|
+
RDoc::Task = Rake::RDocTask
|
13
|
+
end
|
14
|
+
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
17
|
+
rdoc.title = 'Smart Slug'
|
18
|
+
rdoc.options << '--line-numbers'
|
19
|
+
rdoc.rdoc_files.include('README.rdoc')
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
+
end
|
22
|
+
|
23
|
+
Bundler::GemHelper.install_tasks
|
24
|
+
|
25
|
+
require 'rspec/core'
|
26
|
+
require 'rspec/core/rake_task'
|
27
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
28
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
29
|
+
end
|
30
|
+
|
31
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
32
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
33
|
+
spec.rcov = true
|
34
|
+
end
|
35
|
+
|
36
|
+
task :default => :spec
|
data/lib/smart_slug.rb
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
class SmartSlug
|
3
|
+
|
4
|
+
def initialize(val)
|
5
|
+
# Do not use @string = val to avoid changing the value of received object
|
6
|
+
@original = "#{val}"
|
7
|
+
@slug = slug
|
8
|
+
end
|
9
|
+
|
10
|
+
def ==(other)
|
11
|
+
begin
|
12
|
+
other = SmartSlug.new(other) unless other.kind_of?(SmartSlug)
|
13
|
+
rescue
|
14
|
+
return false
|
15
|
+
end
|
16
|
+
@slug == other.to_s
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_s
|
20
|
+
slug
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def slug
|
26
|
+
string = @original.dup
|
27
|
+
string.downcase!
|
28
|
+
string.strip!
|
29
|
+
string.gsub!(/[\/\.\:\@º]/, '')
|
30
|
+
string.gsub!(/[àáâãäåāă]/, 'a')
|
31
|
+
string.gsub!(/[ÀÁÂÃÄÅĀĂ]/, 'A')
|
32
|
+
string.gsub!(/æÆ/, 'ae')
|
33
|
+
string.gsub!(/[ďđ]/, 'd')
|
34
|
+
string.gsub!(/[ĎĐ]/, 'D')
|
35
|
+
string.gsub!(/[çćčĉċ]/, 'c')
|
36
|
+
string.gsub!(/[ÇĆČĈĊ]/, 'C')
|
37
|
+
string.gsub!(/[èéêëēęěĕė]/, 'e')
|
38
|
+
string.gsub!(/[ÈÉÊËĒĘĚĔĖ]/, 'E')
|
39
|
+
string.gsub!(/ƒƑ/, 'f')
|
40
|
+
string.gsub!(/[ĝğġģ]/, 'g')
|
41
|
+
string.gsub!(/[ĜĞĠĢ]/, 'G')
|
42
|
+
string.gsub!(/[ĥħ]/, 'h')
|
43
|
+
string.gsub!(/[ĤĦ]/, 'H')
|
44
|
+
string.gsub!(/[ììíîïīĩĭ]/, 'i')
|
45
|
+
string.gsub!(/[ÌÌÍÎÏĪĨĬ]/, 'I')
|
46
|
+
string.gsub!(/[įıij]/, 'j')
|
47
|
+
string.gsub!(/[ĵĮIJĴ]/, 'J')
|
48
|
+
string.gsub!(/[ķĸĶĸ]/, 'k')
|
49
|
+
string.gsub!(/[łľĺļŀ]/, 'l')
|
50
|
+
string.gsub!(/[ŁĽĹĻĿ]/, 'L')
|
51
|
+
string.gsub!(/[ñńňņʼnŋ]/, 'n')
|
52
|
+
string.gsub!(/[ÑŃŇŅʼnŊ]/, 'N')
|
53
|
+
string.gsub!(/[òóôõöøōőŏŏ]/, 'o')
|
54
|
+
string.gsub!(/[ÒÓÔÕÖØŌŐŎŎ]/, 'O')
|
55
|
+
string.gsub!(/œŒ/, 'oe')
|
56
|
+
string.gsub!(/ąĄ/, 'q')
|
57
|
+
string.gsub!(/[ŕřŗ]/, 'r')
|
58
|
+
string.gsub!(/[ŔŘŖ]/, 'R')
|
59
|
+
string.gsub!(/[śšşŝș]/, 's')
|
60
|
+
string.gsub!(/[ŚŠŞŜȘ]/, 'S')
|
61
|
+
string.gsub!(/[ťţŧț]/, 't')
|
62
|
+
string.gsub!(/[ŤŢŦȚ]/, 'T')
|
63
|
+
string.gsub!(/[ùúûüūůűŭũų]/, 'u')
|
64
|
+
string.gsub!(/[ÙÚÛÜŪŮŰŬŨŲ]/, 'U')
|
65
|
+
string.gsub!(/ŵ/, 'w')
|
66
|
+
string.gsub!(/Ŵ/, 'W')
|
67
|
+
string.gsub!(/[ýÿŷ]/, 'y')
|
68
|
+
string.gsub!(/[ÝŸŶ]/, 'Y')
|
69
|
+
string.gsub!(/[žżź]/, 'z')
|
70
|
+
string.gsub!(/[ŽŻŹ]/, 'Z')
|
71
|
+
string.gsub!(/[^a-z0-9_-]/i, '-')
|
72
|
+
string.gsub!(/_+/, '_')
|
73
|
+
string.gsub!(/ +/, '-')
|
74
|
+
string.gsub!(/^-+/, '')
|
75
|
+
string.gsub!(/-+/, '-')
|
76
|
+
string
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
data/smart_slug.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
# Maintain your gem's version:
|
5
|
+
require "smart_slug/version"
|
6
|
+
|
7
|
+
# Describe your gem and declare its dependencies:
|
8
|
+
Gem::Specification.new do |s|
|
9
|
+
s.name = "smart_slug"
|
10
|
+
s.version = SmartSlug::VERSION
|
11
|
+
s.authors = ["Rafael Lima"]
|
12
|
+
s.email = ["contato@rafael.adm.br"]
|
13
|
+
s.homepage = "http://github.com/rafaelp/smart_slug"
|
14
|
+
s.summary = "SmartSlug creates slugs removing accents from strings"
|
15
|
+
s.description = "SmartSlug creates slugs removing accents from strings"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split($\)
|
18
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
19
|
+
|
20
|
+
s.add_development_dependency "rspec", '2.14.1'
|
21
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe SmartSlug do
|
5
|
+
let(:smart_slug) { SmartSlug.new(' Coração Valente ')}
|
6
|
+
describe :to_s do
|
7
|
+
it { expect(smart_slug.to_s).to eq("coracao-valente") }
|
8
|
+
end
|
9
|
+
describe :== do
|
10
|
+
it { expect(smart_slug == 'coracao-valente').to be_true }
|
11
|
+
end
|
12
|
+
it "does not change variabled passed" do
|
13
|
+
var = "Coração"
|
14
|
+
expect(SmartSlug.new(var).to_s).to eq("coracao")
|
15
|
+
expect(var).to eq("Coração")
|
16
|
+
end
|
17
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: smart_slug
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rafael Lima
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-02-15 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.14.1
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.14.1
|
27
|
+
description: SmartSlug creates slugs removing accents from strings
|
28
|
+
email:
|
29
|
+
- contato@rafael.adm.br
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".gitignore"
|
35
|
+
- ".rspec"
|
36
|
+
- ".ruby-gemset"
|
37
|
+
- ".ruby-version"
|
38
|
+
- ".travis.yml"
|
39
|
+
- Gemfile
|
40
|
+
- Gemfile.lock
|
41
|
+
- LICENSE
|
42
|
+
- README.md
|
43
|
+
- Rakefile
|
44
|
+
- lib/smart_slug.rb
|
45
|
+
- lib/smart_slug/version.rb
|
46
|
+
- smart_slug.gemspec
|
47
|
+
- spec/smart_slug_spec.rb
|
48
|
+
- spec/spec_helper.rb
|
49
|
+
homepage: http://github.com/rafaelp/smart_slug
|
50
|
+
licenses: []
|
51
|
+
metadata: {}
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options: []
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
requirements: []
|
67
|
+
rubyforge_project:
|
68
|
+
rubygems_version: 2.2.0.rc.1
|
69
|
+
signing_key:
|
70
|
+
specification_version: 4
|
71
|
+
summary: SmartSlug creates slugs removing accents from strings
|
72
|
+
test_files:
|
73
|
+
- spec/smart_slug_spec.rb
|
74
|
+
- spec/spec_helper.rb
|