1
0
mirror of https://github.com/danbee/slugtastic synced 2025-03-04 08:49:05 +00:00

Add delimiter substitution for slugs.

This commit is contained in:
Dan Barber 2013-02-12 17:15:51 +00:00
parent 066d38cb9b
commit 117b4e9398
3 changed files with 11 additions and 3 deletions

View File

@ -3,8 +3,12 @@ require "slugtastic/model_additions"
require "slugtastic/railtie" if defined? Rails
module Slugtastic
def self.generate_slug(string)
def self.generate_slug(string, delimiter = nil)
return if string.nil?
string.parameterize
slug = string.parameterize
if delimiter
slug.gsub!("-", delimiter)
end
slug
end
end

View File

@ -1,3 +1,3 @@
module Slugtastic
VERSION = "1.1.0"
VERSION = "1.2.0-alpha"
end

View File

@ -11,6 +11,10 @@ describe Slugtastic do
Slugtastic.generate_slug("A simple string.").should eq "a-simple-string"
end
it "substitutes hyphens for delimiter if specified" do
Slugtastic.generate_slug("A simple string.", "_").should eq "a_simple_string"
end
it "generates a slug from a string with numbers" do
Slugtastic.generate_slug("Slugtastic was built in 2012.").should eq "slugtastic-was-built-in-2012"
end