mirror of
https://github.com/discourse/discourse.git
synced 2025-09-06 10:50:21 +08:00
Initial release of Discourse
This commit is contained in:
commit
21b5628528
2932 changed files with 143949 additions and 0 deletions
30
lib/slug.rb
Normal file
30
lib/slug.rb
Normal file
|
@ -0,0 +1,30 @@
|
|||
# encoding: utf-8
|
||||
|
||||
# Generates a slug. This is annoying beacuse it's duplicating what the javascript
|
||||
# does, but on the other hand slugs are never matched so it's okay if they differ
|
||||
# a little.
|
||||
module Slug
|
||||
|
||||
def self.for(string)
|
||||
|
||||
str = string.dup
|
||||
str.gsub!(/^\s+|\s+$/, '')
|
||||
str.downcase!
|
||||
|
||||
from = "àáäâèéëêìíïîòóöôùúüûñç·/_,:;."
|
||||
to = "aaaaeeeeiiiioooouuuunc-------"
|
||||
|
||||
idx = 0
|
||||
from.each_char do |c|
|
||||
str.gsub!(c, to[idx])
|
||||
idx += 1
|
||||
end
|
||||
|
||||
str.gsub!(/[^a-z0-9 -]/, '')
|
||||
str.gsub!(/\s+/, '-')
|
||||
str.gsub!(/\-+/, '-')
|
||||
|
||||
str
|
||||
end
|
||||
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue