slugorize 0.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/.gitignore +4 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/README.md +8 -0
- data/Rakefile +1 -0
- data/lib/slugorize/version.rb +3 -0
- data/lib/slugorize.rb +19 -0
- data/slugorize.gemspec +22 -0
- data/spec/slugorize_spec.rb +45 -0
- metadata +66 -0
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/slugorize.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require "slugorize/version"
|
2
|
+
|
3
|
+
module Slugorize
|
4
|
+
def slugorize
|
5
|
+
result = self.downcase
|
6
|
+
result.gsub!(/&(#?[0-9a-z])+;/, '') # Ditch Entities
|
7
|
+
result.gsub!(/[^a-z0-9\_]/, '_') # Get rid of anything we don't like
|
8
|
+
result.gsub!(/_+/, '_') # collapse underscores
|
9
|
+
result.gsub!(/_$/, '') # trim underscores
|
10
|
+
result.gsub!(/^_/, '') # trim underscores
|
11
|
+
result
|
12
|
+
end
|
13
|
+
|
14
|
+
def slugorize!
|
15
|
+
self.replace(self.slugorize)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
String.send(:include, Slugorize)
|
data/slugorize.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "slugorize/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "slugorize"
|
7
|
+
s.version = Slugorize::VERSION
|
8
|
+
s.authors = ["Katrina Owen"]
|
9
|
+
s.email = ["katrina.owen@gmail.com"]
|
10
|
+
s.homepage = "https://github.com/kytrinyx/slugorize"
|
11
|
+
s.summary = %q{Small string extension for normalizing strings to slugs}
|
12
|
+
s.description = %q{Small string extension which normalizes strings making them suitable for usage as a slug in a url. Based on code from Xavier Shay's Enki.}
|
13
|
+
|
14
|
+
s.rubyforge_project = "slugorize"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {spec}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_development_dependency "rspec"
|
22
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'slugorize'
|
2
|
+
|
3
|
+
describe String do
|
4
|
+
describe "#slugorize" do
|
5
|
+
it "should lowercase everything" do
|
6
|
+
"FANTASTIC".slugorize.should == "fantastic"
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should leave alphanumerics and underscores alone" do
|
10
|
+
"abc_123".slugorize.should == "abc_123"
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should ditch entities" do
|
14
|
+
"abcæ_bxyz".slugorize.should == "abc_xyz"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should strip all non_alphanumeric characters except _" do
|
18
|
+
'abc\'""!@#$%^*()/=+|\[],.<&>123'.slugorize.should == "abc_123"
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should replace all whitespace with an underscore" do
|
22
|
+
"abc\n\t xyz".slugorize.should == "abc_xyz"
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should trim underscores at the tail" do
|
26
|
+
"abc_".slugorize.should == "abc"
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should trim underscores at the head" do
|
30
|
+
"_abc".slugorize.should == "abc"
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should collapse multiple dashes" do
|
34
|
+
"abc___xyz".slugorize.should == "abc_xyz"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "#slugorize!" do
|
39
|
+
it "replaces the original string" do
|
40
|
+
s = "OH.My.godness!"
|
41
|
+
s.slugorize!
|
42
|
+
s.should eq('oh_my_godness')
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: slugorize
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Katrina Owen
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-11-22 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &2153405800 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2153405800
|
25
|
+
description: Small string extension which normalizes strings making them suitable
|
26
|
+
for usage as a slug in a url. Based on code from Xavier Shay's Enki.
|
27
|
+
email:
|
28
|
+
- katrina.owen@gmail.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- .gitignore
|
34
|
+
- .rspec
|
35
|
+
- Gemfile
|
36
|
+
- README.md
|
37
|
+
- Rakefile
|
38
|
+
- lib/slugorize.rb
|
39
|
+
- lib/slugorize/version.rb
|
40
|
+
- slugorize.gemspec
|
41
|
+
- spec/slugorize_spec.rb
|
42
|
+
homepage: https://github.com/kytrinyx/slugorize
|
43
|
+
licenses: []
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ! '>='
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
requirements: []
|
61
|
+
rubyforge_project: slugorize
|
62
|
+
rubygems_version: 1.8.10
|
63
|
+
signing_key:
|
64
|
+
specification_version: 3
|
65
|
+
summary: Small string extension for normalizing strings to slugs
|
66
|
+
test_files: []
|