seamusabshere-slugify 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/LICENSE ADDED
@@ -0,0 +1,18 @@
1
+ (c) 2008 Fingertips, Manfred Stienstra <m.stienstra@fngtps.com>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to
5
+ deal in the Software without restriction, including without limitation the
6
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7
+ sell copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
+ THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,19 @@
1
+ = Slugify
2
+
3
+ Add .slugify to the string class so you can easily create a human readable but url safe version of a string.
4
+
5
+ == Installation
6
+
7
+ === As a gem
8
+
9
+ Configure the gem in environment.rb:
10
+
11
+ config.gem 'seamusabshere-slugify', :lib => 'slugify', :source => 'http://gems.github.com'
12
+
13
+ Install them using Rails' rake task:
14
+
15
+ $ rake gems:install
16
+
17
+ === In your vendor directory:
18
+
19
+ script/install plugin git://github.com/seamusabshere/slugify.git
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ desc 'Default: run unit tests.'
6
+ task :default => :test
7
+
8
+ desc 'Test the slugify plugin.'
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'lib'
11
+ t.pattern = 'test/**/*_test.rb'
12
+ t.verbose = true
13
+ end
data/init.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'slugify'
2
+
3
+ String.class_eval do
4
+ include ActiveSupport::CoreExtensions::String::Slugify
5
+ end
data/lib/slugify.rb ADDED
@@ -0,0 +1,23 @@
1
+ module ActiveSupport #:nodoc:
2
+ module CoreExtensions #:nodoc:
3
+ module String #:nodoc:
4
+ module Slugify
5
+ # Action can by either :generate or :increment. Generate will generate from the string as though it were a new slug.
6
+ # Increment will increment the integer at the end of the slug.
7
+ def slugify(action=:generate)
8
+ case action
9
+ when :generate
10
+ s = self.gsub(/\s+/, ' ')
11
+ s.strip!
12
+ s.gsub!(' ', '-')
13
+ s.gsub!('&', 'and')
14
+ s.gsub!(/[^\w-]/u, '')
15
+ s.mb_chars.downcase.to_s
16
+ when :increment
17
+ self.slugify.gsub(/^(.*?)-?(\d*)$/) { "#{$1}-#{$2.to_i.next}" }
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
data/rails/init.rb ADDED
@@ -0,0 +1 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'init')
data/slugify.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "slugify"
3
+ spec.version = "1.0.1"
4
+
5
+ spec.author = "Manfred Stienstra"
6
+ spec.email = "manfred@fngtps.com"
7
+
8
+ spec.description = <<-EOF
9
+ Add .slugify to the string class so you can easily create a human readable but url safe version of a string.
10
+ EOF
11
+ spec.summary = <<-EOF
12
+ Add .slugify to the string class so you can easily create a human readable but url safe version of a string.
13
+ EOF
14
+ spec.homepage = "https://fngtps.com/svn/rails-plugins/trunk/slugify"
15
+
16
+ # Dir['[a-zA-Z]*'] + Dir['lib/**/*'] + Dir['rails/*'] + Dir['test/**/*']
17
+ spec.files = ["init.rb", "lib", "LICENSE", "rails", "Rakefile", "README", "slugify-1.0.0.gem", "slugify.gemspec", "test", "lib/slugify.rb", "rails/init.rb", "test/slugify_test.rb"]
18
+ # Dir['test/**/*']
19
+ spec.test_file = "test/slugify_test.rb"
20
+
21
+ spec.has_rdoc = true
22
+ spec.extra_rdoc_files = [ 'README', 'LICENSE' ]
23
+ spec.rdoc_options << "--charset=utf-8"
24
+ end
@@ -0,0 +1,31 @@
1
+ require 'test/unit'
2
+
3
+ $:.unshift(File.expand_path('../lib', File.dirname(__FILE__)))
4
+ require 'init'
5
+ require File.dirname(__FILE__) + '/../../../rails/activesupport/lib/active_support'
6
+
7
+ class SlugifyTest < Test::Unit::TestCase
8
+ def test_should_create_slugs
9
+ assert_equal 'plain-slug', 'Plain slug'.slugify
10
+ assert_equal 'café-house', 'café house'.slugify
11
+ assert_equal 'here-and-now', 'here & now'.slugify
12
+ assert_equal 'strip-spaces', ' strip spaces '.slugify
13
+ assert_equal '1-2-3', '1 2 3'.slugify
14
+ assert_equal 'keep_underscores', 'keep_underscores'.slugify
15
+ assert_equal 'strip-those-non-chars', "strip #^@tho?se*%$ non-chars".slugify
16
+ assert_equal 'comin-right-at-ya', "Comin' right at ya'".slugify
17
+ end
18
+
19
+ def test_should_not_slugify_slugs
20
+ assert_equal 'plain-slug', 'plain-slug'.slugify
21
+ end
22
+
23
+ def test_should_create_alternatives_for_existing_slugs
24
+ assert_equal 'first-1', 'First'.slugify(:increment)
25
+ assert_equal 'second-2', 'Second 1'.slugify(:increment)
26
+ assert_equal 'second-2', 'second-1'.slugify(:increment)
27
+ assert_equal 'second-3', 'second-2'.slugify(:increment)
28
+ assert_equal 'lots-9533','lots-9532'.slugify(:increment)
29
+ assert_equal 'lots-9533','lots-009532'.slugify(:increment)
30
+ end
31
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: seamusabshere-slugify
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Manfred Stienstra
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-01-11 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Add .slugify to the string class so you can easily create a human readable but url safe version of a string.
17
+ email: manfred@fngtps.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README
24
+ - LICENSE
25
+ files:
26
+ - init.rb
27
+ - lib
28
+ - LICENSE
29
+ - rails
30
+ - Rakefile
31
+ - README
32
+ - slugify-1.0.0.gem
33
+ - slugify.gemspec
34
+ - test
35
+ - lib/slugify.rb
36
+ - rails/init.rb
37
+ - test/slugify_test.rb
38
+ has_rdoc: true
39
+ homepage: https://fngtps.com/svn/rails-plugins/trunk/slugify
40
+ post_install_message:
41
+ rdoc_options:
42
+ - --charset=utf-8
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: "0"
50
+ version:
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ requirements: []
58
+
59
+ rubyforge_project:
60
+ rubygems_version: 1.2.0
61
+ signing_key:
62
+ specification_version: 2
63
+ summary: Add .slugify to the string class so you can easily create a human readable but url safe version of a string.
64
+ test_files:
65
+ - test/slugify_test.rb