discourse/lib/slug.rb

19 lines
436 B
Ruby
Raw Normal View History

2013-02-05 14:16:51 -05:00
# encoding: utf-8
2013-02-05 14:16:51 -05:00
module Slug
def self.for(string)
2013-06-02 19:08:34 -04:00
slug = string.gsub("'", "").parameterize
slug.gsub!("_", "-")
if ['zh_CN', 'ja', 'ko'].include?(SiteSetting.default_locale)
unless defined? Stringex
require 'stringex_lite'
end
slug = string.to_url
end
slug =~ /[^\d]/ ? slug : '' # Reject slugs that only contain numbers, because they would be indistinguishable from id's.
2013-02-05 14:16:51 -05:00
end
end