titleize 1.1.0 → 1.2.0
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/History.txt +6 -0
- data/lib/titleize.rb +10 -5
- data/spec/spec.opts +2 -0
- data/spec/titleize_spec.rb +45 -17
- metadata +15 -4
data/History.txt
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
=== 1.2.0 / 2010-07-22
|
2
|
+
|
3
|
+
* Ruby 1.9 compatibility. [Jason Weathered]
|
4
|
+
* Active Support's Inflector is under the ActiveSupport namespace. [Jason Weathered]
|
5
|
+
* have String#titleize act like Inflector#titleize when ActiveSupport is loaded
|
6
|
+
|
1
7
|
=== 1.1.0 / 2010-03-18
|
2
8
|
|
3
9
|
* fix all-caps titles
|
data/lib/titleize.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
1
2
|
# Adds String#titleize for creating properly capitalized titles.
|
2
3
|
# It can be called as Titleize.titleize or "a string".titleize.
|
3
4
|
#
|
@@ -5,7 +6,7 @@
|
|
5
6
|
#
|
6
7
|
# If loaded in a Rails environment, it modifies Inflector.titleize.
|
7
8
|
module Titleize
|
8
|
-
VERSION = '1.
|
9
|
+
VERSION = '1.2.0'
|
9
10
|
SMALL_WORDS = %w{a an and as at but by en for if in of on or the to v v. via vs vs.}
|
10
11
|
|
11
12
|
extend self
|
@@ -82,13 +83,17 @@ class String
|
|
82
83
|
# "notes on a scandal" # => "Notes on a Scandal"
|
83
84
|
# "the good german" # => "The Good German"
|
84
85
|
def titleize
|
85
|
-
|
86
|
+
if defined? ActiveSupport
|
87
|
+
ActiveSupport::Inflector.titleize(self)
|
88
|
+
else
|
89
|
+
Titleize.titleize(self)
|
90
|
+
end
|
86
91
|
end
|
87
92
|
alias_method :titlecase, :titleize
|
88
93
|
end
|
89
94
|
|
90
|
-
if defined?
|
91
|
-
module Inflector
|
95
|
+
if defined? ActiveSupport
|
96
|
+
module ActiveSupport::Inflector
|
92
97
|
extend self
|
93
98
|
|
94
99
|
# Capitalizes most words to create a nicer looking title string.
|
@@ -105,7 +110,7 @@ if defined? Inflector
|
|
105
110
|
# "notes on an active_record" # => "Notes on an Active Record"
|
106
111
|
# "the GoodGerman" # => "The Good German"
|
107
112
|
def titleize(title)
|
108
|
-
Titleize.titleize(Inflector.humanize(Inflector.underscore(title)))
|
113
|
+
Titleize.titleize(ActiveSupport::Inflector.humanize(ActiveSupport::Inflector.underscore(title)))
|
109
114
|
end
|
110
115
|
alias_method :titlecase, :titleize
|
111
116
|
end
|
data/spec/spec.opts
CHANGED
data/spec/titleize_spec.rb
CHANGED
@@ -1,8 +1,14 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
module ActiveSupport
|
4
|
+
module Inflector
|
5
|
+
#stub
|
6
|
+
def underscore(string) string; end
|
7
|
+
def humanize(string) string; end
|
8
|
+
end
|
3
9
|
end
|
4
10
|
|
5
|
-
require
|
11
|
+
require 'spec_helper'
|
6
12
|
|
7
13
|
SMALL_WORDS = %w{a an and as at but by en for if in of on or the to v v. via vs vs.}
|
8
14
|
|
@@ -215,12 +221,12 @@ describe Titleize do
|
|
215
221
|
end
|
216
222
|
|
217
223
|
it "should have titleize as a singleton method" do
|
218
|
-
Titleize.singleton_methods.should include(
|
224
|
+
Titleize.singleton_methods.map(&:to_sym).should include(:titleize)
|
219
225
|
end
|
220
226
|
end
|
221
227
|
|
222
|
-
describe Inflector do
|
223
|
-
include Inflector
|
228
|
+
describe ActiveSupport::Inflector do
|
229
|
+
include ActiveSupport::Inflector
|
224
230
|
|
225
231
|
describe "titleize" do
|
226
232
|
before(:each) do
|
@@ -230,30 +236,30 @@ describe Inflector do
|
|
230
236
|
it "should call humanize and underscore like the default in Rails" do
|
231
237
|
underscored_title = "active_record and active_resource"
|
232
238
|
humanized_title = "Active record and active resource"
|
233
|
-
Inflector.should_receive(:underscore).with(@title).and_return(underscored_title)
|
234
|
-
Inflector.should_receive(:humanize).with(underscored_title).and_return(humanized_title)
|
239
|
+
ActiveSupport::Inflector.should_receive(:underscore).with(@title).and_return(underscored_title)
|
240
|
+
ActiveSupport::Inflector.should_receive(:humanize).with(underscored_title).and_return(humanized_title)
|
235
241
|
titleize(@title).should == "Active Record and Active Resource"
|
236
242
|
end
|
237
243
|
|
238
244
|
it "should replace Inflector.titleize" do
|
239
245
|
Titleize.should_receive(:titleize).with(@title)
|
240
|
-
Inflector.stub!(:underscore).and_return(@title)
|
241
|
-
Inflector.stub!(:humanize).and_return(@title)
|
242
|
-
Inflector.titleize(@title)
|
246
|
+
ActiveSupport::Inflector.stub!(:underscore).and_return(@title)
|
247
|
+
ActiveSupport::Inflector.stub!(:humanize).and_return(@title)
|
248
|
+
ActiveSupport::Inflector.titleize(@title)
|
243
249
|
end
|
244
250
|
|
245
251
|
it "should be aliased as titlecase" do
|
246
|
-
Inflector.singleton_methods.should include(
|
247
|
-
Inflector.stub!(:titlecase).and_return("title")
|
248
|
-
Inflector.stub!(:titleize).and_return("title")
|
249
|
-
Inflector.titlecase("this").should == Inflector.titleize("this")
|
252
|
+
ActiveSupport::Inflector.singleton_methods.map(&:to_sym).should include(:titlecase)
|
253
|
+
ActiveSupport::Inflector.stub!(:titlecase).and_return("title")
|
254
|
+
ActiveSupport::Inflector.stub!(:titleize).and_return("title")
|
255
|
+
ActiveSupport::Inflector.titlecase("this").should == ActiveSupport::Inflector.titleize("this")
|
250
256
|
end
|
251
257
|
end
|
252
258
|
end
|
253
259
|
|
254
260
|
describe String do
|
255
261
|
it "should have a titleize method" do
|
256
|
-
String.instance_methods.should include(
|
262
|
+
String.instance_methods.map(&:to_sym).should include(:titleize)
|
257
263
|
end
|
258
264
|
|
259
265
|
it "should work" do
|
@@ -261,8 +267,30 @@ describe String do
|
|
261
267
|
end
|
262
268
|
|
263
269
|
it "should be aliased as #titlecase" do
|
264
|
-
String.instance_methods.should include(
|
270
|
+
String.instance_methods.map(&:to_sym).should include(:titlecase)
|
265
271
|
title = "this is a pile of testing text"
|
266
272
|
title.titlecase.should == title.titleize
|
267
273
|
end
|
274
|
+
|
275
|
+
context "when ActiveSupport is loaded" do
|
276
|
+
it "should act the same as Inflector#titleize" do
|
277
|
+
ActiveSupport::Inflector.should_receive(:titleize).with("title")
|
278
|
+
"title".titleize
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
282
|
+
context "when ActiveSupport is not loaded" do
|
283
|
+
before(:all) do
|
284
|
+
Object.send :remove_const, :ActiveSupport
|
285
|
+
end
|
286
|
+
|
287
|
+
it "should work" do
|
288
|
+
lambda { "foo".titleize }.should_not raise_exception
|
289
|
+
end
|
290
|
+
|
291
|
+
it "should call Titleize#titleize" do
|
292
|
+
Titleize.should_receive(:titleize).with("title")
|
293
|
+
"title".titleize
|
294
|
+
end
|
295
|
+
end
|
268
296
|
end
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: titleize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 31
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 1
|
7
|
-
-
|
8
|
+
- 2
|
8
9
|
- 0
|
9
|
-
version: 1.
|
10
|
+
version: 1.2.0
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Grant Hollingworth
|
@@ -14,16 +15,18 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-
|
18
|
+
date: 2010-07-22 00:00:00 -04:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
21
22
|
name: rubyforge
|
22
23
|
prerelease: false
|
23
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
24
26
|
requirements:
|
25
27
|
- - ">="
|
26
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 9
|
27
30
|
segments:
|
28
31
|
- 2
|
29
32
|
- 0
|
@@ -35,9 +38,11 @@ dependencies:
|
|
35
38
|
name: gemcutter
|
36
39
|
prerelease: false
|
37
40
|
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
38
42
|
requirements:
|
39
43
|
- - ">="
|
40
44
|
- !ruby/object:Gem::Version
|
45
|
+
hash: 11
|
41
46
|
segments:
|
42
47
|
- 0
|
43
48
|
- 5
|
@@ -49,9 +54,11 @@ dependencies:
|
|
49
54
|
name: hoe
|
50
55
|
prerelease: false
|
51
56
|
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
52
58
|
requirements:
|
53
59
|
- - ">="
|
54
60
|
- !ruby/object:Gem::Version
|
61
|
+
hash: 27
|
55
62
|
segments:
|
56
63
|
- 2
|
57
64
|
- 5
|
@@ -101,23 +108,27 @@ rdoc_options:
|
|
101
108
|
require_paths:
|
102
109
|
- lib
|
103
110
|
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
none: false
|
104
112
|
requirements:
|
105
113
|
- - ">="
|
106
114
|
- !ruby/object:Gem::Version
|
115
|
+
hash: 3
|
107
116
|
segments:
|
108
117
|
- 0
|
109
118
|
version: "0"
|
110
119
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
|
+
none: false
|
111
121
|
requirements:
|
112
122
|
- - ">="
|
113
123
|
- !ruby/object:Gem::Version
|
124
|
+
hash: 3
|
114
125
|
segments:
|
115
126
|
- 0
|
116
127
|
version: "0"
|
117
128
|
requirements: []
|
118
129
|
|
119
130
|
rubyforge_project: titleize
|
120
|
-
rubygems_version: 1.3.
|
131
|
+
rubygems_version: 1.3.7
|
121
132
|
signing_key:
|
122
133
|
specification_version: 3
|
123
134
|
summary: Adds String#titleize for creating properly capitalized titles
|