forked from kickstarter/acts_as_sluggable
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated for rails 3.*, added Gemfile and gemspec, & fixed tests
- Loading branch information
Showing
8 changed files
with
100 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
source :rubygems | ||
|
||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
PATH | ||
remote: . | ||
specs: | ||
acts_as_sluggable (1.0) | ||
activerecord (>= 3.0.0) | ||
|
||
GEM | ||
remote: http://rubygems.org/ | ||
specs: | ||
activemodel (3.2.2) | ||
activesupport (= 3.2.2) | ||
builder (~> 3.0.0) | ||
activerecord (3.2.2) | ||
activemodel (= 3.2.2) | ||
activesupport (= 3.2.2) | ||
arel (~> 3.0.2) | ||
tzinfo (~> 0.3.29) | ||
activesupport (3.2.2) | ||
i18n (~> 0.6) | ||
multi_json (~> 1.0) | ||
arel (3.0.2) | ||
builder (3.0.0) | ||
i18n (0.6.0) | ||
multi_json (1.2.0) | ||
rake (0.8.7) | ||
sqlite3 (1.3.5) | ||
tzinfo (0.3.32) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
acts_as_sluggable! | ||
bundler (>= 1.0.0) | ||
rake (= 0.8.7) | ||
sqlite3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# -*- encoding: utf-8 -*- | ||
Gem::Specification.new do |s| | ||
s.name = "acts_as_sluggable" | ||
s.version = "1.0" | ||
s.platform = Gem::Platform::RUBY | ||
s.authors = ["[email protected]"] | ||
s.email = ["[email protected]"] | ||
s.homepage = "https://github.com/kickstarter/acts_as_sluggable" | ||
s.summary = "acts_as_sluggable, forked and updated" | ||
s.description = "acts_as_sluggable, forked and updated" | ||
|
||
s.add_dependency "activerecord", ">= 3.0.0" | ||
|
||
s.add_development_dependency "bundler", ">= 1.0.0" | ||
s.add_development_dependency "sqlite3" | ||
s.add_development_dependency "rake", "0.8.7" | ||
|
||
s.files = `git ls-files`.split("\n") | ||
s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact | ||
s.require_path = 'lib' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
class String | ||
def to_slug(options = {}) | ||
options[:length] ||= 50 | ||
|
||
#normalize chars to ascii | ||
self.mb_chars.normalize(:kd).gsub(/[^\x00-\x7F]/n, '').to_s.downcase. | ||
#strip out common punctuation | ||
gsub(/[\'\"\#\$\,\.\!\?\%\@\(\)]+/, ''). | ||
#replace ampersand chars with 'and' | ||
gsub(/&/, 'and'). | ||
#replace non-word chars with dashes | ||
gsub(/[\W^-_]+/, '-'). | ||
#remove double dashes | ||
gsub(/\-{2}/, '-'). | ||
#removing leading dashes | ||
gsub(/^-/, ''). | ||
#truncate to a a decent length | ||
slice(0...options[:length]). | ||
#remove trailing dashes and whitespace | ||
gsub(/[-\s]*$/, '') | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
class Page < ActiveRecord::Base | ||
validates_length_of :title, :minimum => 2 | ||
validates_presence_of :title | ||
acts_as_slugable :source_column => :title, :target_column => :url_slug, :scope => :parent, :slug_length => 50 | ||
acts_as_slugable :source_column => :title, :target_column => :url_slug, | ||
:scope => :parent, :slug_length => 50 | ||
end |