Method for permalink creation in ruby, based on drupal code
1
2 def create_permalink(string, separator = '-', max_size = 127)
3
4
5 ignore_words = ['a', 'an', 'the']
6 ignore_re = String.new
7
8
9 ignore_words.each{ |word|
10 ignore_re << word + '\b|\b'
11 }
12 ignore_re = '\b' + ignore_re + '\b'
13
14
15 permalink = string.gsub("'", separator)
16
17
18 permalink.gsub!(ignore_re, '')
19
20
21 permalink.downcase!
22
23
24 permalink.gsub!(/[^a-z0-9]+/, separator)
25
26
27 permalink = permalink.to(max_size)
28
29
30 return permalink.gsub(/^\\#{separator}+|\\#{separator}+$/, '')
31
32 end