geetarista (owner)

Fork Of

Revisions

gist: 94514 Download_button fork
public
Public Clone URL: git://gist.github.com/94514.git
Embed All Files: show embed
inflectors.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
require 'iconv'
 
module ActiveSupport
  module Inflector
    extend self
  
    def slugize(words)
      slug = Iconv.iconv('ascii//TRANSLIT//IGNORE', 'utf-8', words).to_s
      slug.gsub!(/&/, 'and')
      slug.gsub!(/[^\w_-]+/i, '-')
      slug.gsub!(/\-{2,}/i, '-')
      slug.gsub!(/^\-|\-$/i, '')
      url_encode(slug.downcase)
    end
  
    def url_encode(word)
      URI.escape(word, /[^\w_+-]/i)
    end
  
  end
end
 
module ActiveSupport::CoreExtensions::String::Inflections
  def slugize
    ActiveSupport::Inflector.slugize(self)
  end
  
  def url_encode
    ActiveSupport::Inflector.url_encode(self)
  end
end