app/core_ext/string.rb
# Produces a slugified version of this string safe for use in URLs.
Produces a slugified version of this string safe for use in URLs.
Produces a slugified version of this string safe for use in URLs .
def slugify( limit = nil )
    slug = normalize.gsub(/[^\sa-z0-9\-\_]/i,'').gsub(/\s+/,'-').gsub(/--+/, '-')
    return slug if limit.nil? or (slug.length < limit)
    slug = slug[0..(limit - 1)]
    slug.gsub( /\-([^\-]*)$/, '' ) unless slug.gsub( /\-([^\-]*)$/, '' ).empty?
  end
def slugify ( limit = nil ) slug = normalize . gsub ( / [^ \s a-z0-9 \- \_ ] /i , '' ) . gsub ( / \s + / , '-' ) . gsub ( / --+ / , '-' ) return slug if limit . nil? or ( slug . length < limit ) slug = slug [ 0 .. ( limit - 1 ) ] slug . gsub ( / \- ([^ \- ]*)$ / , '' ) unless slug . gsub ( / \- ([^ \- ]*)$ / , '' ) . empty? end
Produces a slugified version of this string safe for use in URLs.
Produces a slugified version of this string safe for use in URLs .
# if there’s no limit, or we’re lower than it # otherwise, chop things down # and chop the last word off it’s a fragment
limit