Skip to content

Commit

Permalink
omit single quotes from slug
Browse files Browse the repository at this point in the history
  • Loading branch information
SamSaffron committed Jun 2, 2013
1 parent 1833c12 commit da22c0f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 2 additions & 4 deletions lib/slug.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# encoding: utf-8

# Generates a slug. This is annoying because 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)
slug = string.parameterize.gsub("_", "-")
slug = string.gsub("'", "").parameterize
slug.gsub!("_", "-")
slug =~ /[^\d]/ ? slug : '' # Reject slugs that only contain numbers, because they would be indistinguishable from id's.
end

Expand Down
4 changes: 4 additions & 0 deletions spec/components/slug_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,9 @@
Slug.for('電車男 2').should be_blank
end

it "doesn't keep single quotes within word" do
Slug.for("Jeff hate's this").should == "jeff-hates-this"
end

end

0 comments on commit da22c0f

Please sign in to comment.