Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/gluttonberg/extensions/string.rb

Instance Method Summary collapse

Instance Method Details

#sluglizeObject

accepts a string and return slug string if you’re changing this regex, make sure to change the one in /javascripts/slug_management.js too utf-8 special chars are fixed for new ruby 1.9.2



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/gluttonberg/extensions/string.rb', line 7

def sluglize
  new_slug = self
  unless new_slug.blank?
    new_slug = new_slug.to_s.downcase.gsub(/\s/, '-').gsub(/[\!\*'"″′‟‛„‚”“”˝\(\)\;\:\.\@\&\=\+\$\,\/?\%\#\[\]]/, '')
    new_slug = new_slug.gsub(/_$/,'-') # replace underscores with hyphen
    while new_slug.include?("--")
      new_slug = new_slug.gsub('--','-') # remove consective hyphen
    end
    new_slug = new_slug.gsub(/-$/,'') # remove trailing hyphen
  end
  new_slug
end