File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66module Slug
77
88 def self . for ( string )
9-
10- str = string . dup
11- str . gsub! ( /^\s +|\s +$/ , '' )
12- str . downcase!
13-
9+ str = string . dup . strip . downcase
10+
1411 # The characters we want to replace with a hyphen
1512 str . tr! ( "·/_,:;." , "\- " )
1613
1714 # Convert to ASCII or remove if transliteration is unknown.
1815 str = ActiveSupport ::Inflector . transliterate ( str , '' )
19-
16+
17+ # Remove everything except alphanumberic, space, and hyphen characters.
2018 str . gsub! ( /[^a-z0-9 -]/ , '' )
19+
20+ # Replace multiple spaces with one hyphen.
2121 str . gsub! ( /\s +/ , '-' )
22+
23+ # Replace multiple hyphens with one hyphen.
2224 str . gsub! ( /\- +/ , '-' )
25+
26+ # Remove leading and trailing hyphens
2327 str . gsub! ( /^-|-$/ , '' )
2428
2529 str
Original file line number Diff line number Diff line change 11# encoding: utf-8
22
33require 'spec_helper'
4-
54require 'slug'
65
76describe Slug do
87
9-
108 it 'replaces spaces with hyphens' do
119 Slug . for ( "hello world" ) . should == 'hello-world'
1210 end
You can’t perform that action at this time.
0 commit comments