public
Description: ActiveRecord plugin for automatically converting fields to permalinks.
Clone URL: git://github.com/technoweenie/permalink_fu.git
Search Repo:
Turn "fööbär" into "foobar", not "f-o-ob-ar". As a desired side-effect, "fo
o!!1" becomes "foo1" rather than "foo-1".

This is under OS X, by the way. I believe iconv can behave slightly 
differently on different platforms.
henrik (author)
Thu May 22 08:39:22 -0700 2008
commit  c5cd3ada8c5def22bb38175d01412ed442b51a50
tree    b8a8a43ab271c8bc96c82ecadd5d362010b7c5bb
parent  56121670fcc3bc3a62827762628b4ba88f4caa46
...
12
13
14
15
 
16
17
18
 
19
20
21
...
12
13
14
 
15
16
17
 
18
19
20
21
0
@@ -12,10 +12,10 @@ module PermalinkFu
0
     
0
     def escape(str)
0
       s = ((translation_to && translation_from) ? Iconv.iconv(translation_to, translation_from, str) : str).to_s
0
- s.gsub!(/\W+/, ' ') # all non-word chars to spaces
0
+ s.gsub!(/[^\w -]+/, '') # strip unwanted characters
0
       s.strip! # ohh la la
0
       s.downcase! #
0
- s.gsub!(/\ +/, '-') # spaces to dashes, preferred separator char everywhere
0
+ s.gsub!(/[ -]+/, '-') # separate by single dashes
0
       s
0
     end
0
   end
...
132
133
134
135
 
136
137
138
 
 
139
140
141
...
132
133
134
 
135
136
137
 
138
139
140
141
142
0
@@ -132,10 +132,11 @@ end
0
 
0
 class PermalinkFuTest < Test::Unit::TestCase
0
   @@samples = {
0
- 'This IS a Tripped out title!!.!1 (well/ not really)' => 'this-is-a-tripped-out-title-1-well-not-really',
0
+ 'This IS a Tripped out title!!.!1 (well/ not really)' => 'this-is-a-tripped-out-title1-well-not-really',
0
     '////// meph1sto r0x ! \\\\\\' => 'meph1sto-r0x',
0
     'āčēģīķļņū' => 'acegiklnu',
0
- '中文測試 chinese text' => 'chinese-text'
0
+ '中文測試 chinese text' => 'chinese-text',
0
+ 'fööbär' => 'foobar'
0
   }
0
 
0
   @@extra = { 'some-)()()-ExtRa!/// .data==?> to \/\/test' => 'some-extra-data-to-test' }

Comments

    No one has commented yet.