i76-has_slug 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,35 +1,35 @@
1
- class String
2
- # convert strings to slugs that are lowercase an only contain alphanumeric
3
- # characters, dashes and sometimes dots
4
- def to_slug
5
- # Transliterate
6
- slug = Unicode.normalize_KD(self).gsub(/[^\x00-\x7F]/n,'')
7
-
8
- # Convert to lowercase
9
- slug.downcase!
10
-
11
- # Change seperators (like spaces) to dashes
12
- slug.gsub!(/[+_,\.\/|;; ]/, '-')
13
-
14
- # Dot's should be saved only when they have letter or number on both sides
15
- # (this preserves file extensions)
16
- # slug.gsub!(/[^\w\d]\.+/, '-')
17
- # slug.gsub!(/\.+[^\w\d]/, '-')
18
-
19
- # Strip dots from begining and end
20
- slug.gsub!(/^\.+/, '')
21
- slug.gsub!(/\.+$/, '')
22
-
23
- # Change multiple succesive dashes to single dashe.
24
- slug.gsub!(/-+/, '-')
25
-
26
- # Strip dashes from begining and end
27
- slug.gsub!(/^-+/, '')
28
- slug.gsub!(/-+$/, '')
29
-
30
- # Remove everything that is not letter, number, dash or dot.
31
- slug.gsub!(/[^\w\d.-]/, '')
32
-
33
- slug
34
- end
35
- end
1
+ class String
2
+ # convert strings to slugs that are lowercase an only contain alphanumeric
3
+ # characters, dashes and sometimes dots
4
+ def to_slug
5
+ # Transliterate
6
+ slug = Unicode.normalize_KD(self).gsub(/[^\x00-\x7F]/n,'')
7
+
8
+ # Convert to lowercase
9
+ slug.downcase!
10
+
11
+ # Change seperators (like spaces) to dashes
12
+ slug.gsub!(/[+_',\.\/|;; ]/, '-')
13
+
14
+ # Dot's should be saved only when they have letter or number on both sides
15
+ # (this preserves file extensions)
16
+ # slug.gsub!(/[^\w\d]\.+/, '-')
17
+ # slug.gsub!(/\.+[^\w\d]/, '-')
18
+
19
+ # Strip dots from begining and end
20
+ slug.gsub!(/^\.+/, '')
21
+ slug.gsub!(/\.+$/, '')
22
+
23
+ # Change multiple succesive dashes to single dashe.
24
+ slug.gsub!(/-+/, '-')
25
+
26
+ # Strip dashes from begining and end
27
+ slug.gsub!(/^-+/, '')
28
+ slug.gsub!(/-+$/, '')
29
+
30
+ # Remove everything that is not letter, number, dash or dot.
31
+ slug.gsub!(/[^\w\d.-]/, '')
32
+
33
+ slug
34
+ end
35
+ end
@@ -0,0 +1,9 @@
1
+ require "#{File.dirname(__FILE__)}/../test_helper"
2
+
3
+ class SlugTest < Test::Unit::TestCase
4
+ context 'A Slug' do
5
+ should 'handle quotes well' do
6
+ assert_equal 'l-atelier', "l'Atelier".to_slug
7
+ end
8
+ end
9
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i76-has_slug
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom-Eric Gerritsen
@@ -78,3 +78,4 @@ test_files:
78
78
  - test/models/kitchen.rb
79
79
  - test/models/restaurant.rb
80
80
  - test/unit/has_slug_test.rb
81
+ - test/unit/slug_test.rb