public
Description: Rails abstraction of word-based slugs for URLs, w/ or w/o leading numeric IDs.
Homepage: http://norbauer.com
Clone URL: git://github.com/norbauer/salty_slugs.git
Will now use Unicode sluggify logic if gem is found, otherwise will keep 
doign it the Iconv way.  Modified tests to support this
jfernandez (author)
Thu Jun 19 09:53:28 -0700 2008
commit  f3f6883071ab946ea48eb597e988bcb45710e238
tree    3e84bdc8894c855758ecef01401e83612d27fcba
parent  3f39fb0ac9002e8b463e64f9ab71e4171ce68aaa
...
1
2
 
 
 
 
 
3
4
...
 
 
1
2
3
4
5
6
7
0
@@ -1,3 +1,6 @@
0
-require "iconv"
0
-require "unicode"
0
+begin
0
+ require "unicode"
0
+rescue LoadError
0
+ require "iconv"
0
+end
0
 ActiveRecord::Base.send!(:extend, Slug)
0
\ No newline at end of file
...
37
38
39
40
41
 
 
 
 
 
 
 
 
 
 
 
 
42
43
44
...
37
38
39
 
 
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
0
@@ -37,8 +37,18 @@ module Slug
0
     
0
     def sluggify(text)
0
       return nil if text.blank?
0
- str = Unicode.normalize_KD(text).gsub(/[^\x00-\x7F]/n,'')
0
- str = str.gsub(/\W+/, '-').gsub(/^-+/,'').gsub(/-+$/,'').downcase
0
+ if defined?(Unicode)
0
+ str = Unicode.normalize_KD(text).gsub(/[^\x00-\x7F]/n,'')
0
+ str = str.gsub(/\W+/, '-').gsub(/^-+/,'').gsub(/-+$/,'').downcase
0
+ return str
0
+ else
0
+ str = Iconv.iconv('ascii//translit', 'utf-8', text).to_s
0
+ str.gsub!(/\W+/, ' ')
0
+ str.strip!
0
+ str.downcase!
0
+ str.gsub!(/\ +/, '-')
0
+ return str
0
+ end
0
     end
0
   end
0
   
...
70
71
72
73
 
 
74
75
76
...
70
71
72
 
73
74
75
76
77
0
@@ -70,7 +70,8 @@ class SlugTest < Test::Unit::TestCase
0
     slugs = {
0
       "This is just a title" => "this-is-just-a-title",
0
       "//\\?!(*)hai you! su!!c%%%%%k" => "hai-you-su-c-k",
0
- "ñæüéå" => "nuea",
0
+ # Use the correct expected string with Unicode support
0
+ "ñæüéå" => defined?(Unicode) ? "nuea" : "nae-u-ea",
0
       # Stolen from Ricks tests, as always.
0
       'This IS a Tripped out title!!.!1 (well/ not really)' => 'this-is-a-tripped-out-title-1-well-not-really',
0
       '////// meph1sto r0x ! \\\\\\' => 'meph1sto-r0x',

Comments

    No one has commented yet.