titleize 1.2.1 → 1.3.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.
@@ -1,3 +1,13 @@
1
+ === 1.3.0 / 2013-03-07
2
+
3
+ * add String#titleize! [Scott Pullen]
4
+ * allow disabling of humanize/underscore in ActiveSupport#titleize [Jayme Deffenbaugh]
5
+ * RSpec 2
6
+
7
+ === 1.2.1 / 2011-04-15
8
+
9
+ * Bundler
10
+
1
11
  === 1.2.0 / 2010-07-22
2
12
 
3
13
  * Ruby 1.9 compatibility. [Jason Weathered]
@@ -1,30 +1,32 @@
1
- = Titleize
1
+ # Titleize
2
2
 
3
- * http://rubygems.org/gems/titleize
3
+ http://rubygems.org/gems/titleize
4
4
 
5
- == DESCRIPTION:
5
+ ### Description
6
6
 
7
- Adds String#titleize for creating properly capitalized titles.
8
- It can be called as Titleize.titleize or "a string".titleize. It is also
9
- aliased as titlecase.
7
+ Adds `String#titleize` for creating properly capitalized titles.
8
+ It can be called as `Titleize.titleize` or `"a string".titleize`. It is also
9
+ aliased as `titlecase`.
10
10
 
11
- The list of "small words" which are not capped comes from the New York Times
11
+ The list of "small words" which are not capped comes from the New York Times
12
12
  Manual of Style, plus 'vs' and 'v'.
13
13
 
14
- If loaded in a Rails environment, it modifies Inflector.titleize.
14
+ If loaded in a Rails environment, it modifies `Inflector#titleize`. By default
15
+ ActiveSupport calls `Inflector#underscore` and `Inflector#humanize`. This however
16
+ can be problematic with words like "iPod", "GPS", and "McArthur". To disable
17
+ this behavior, use the options `:underscore => false` and `:humanize => false`.
15
18
 
16
- Based on TitleCase.pl by John Gruber.
17
- http://daringfireball.net/2008/05/title_case
19
+ Based on [TitleCase.pl](http://daringfireball.net/2008/05/title_case) by John Gruber.
18
20
 
19
- == SYNOPSIS:
21
+ ### Synopsis
20
22
 
21
- "a lovely and talented title".titleize # => "A Lovely and Talented Title"
23
+ `"a lovely and talented title".titleize # => "A Lovely and Talented Title"`
22
24
 
23
- == INSTALL:
25
+ ### Install
24
26
 
25
- * gem install titleize
27
+ `gem install titleize`
26
28
 
27
- == LICENSE:
29
+ ### License
28
30
 
29
31
  (The MIT License)
30
32
 
data/Rakefile CHANGED
@@ -1,11 +1,11 @@
1
1
  require 'bundler'
2
- require 'spec/rake/spectask'
2
+ require 'rspec/core/rake_task'
3
3
  Bundler::GemHelper.install_tasks
4
4
 
5
5
  desc "Run all specs"
6
- Spec::Rake::SpecTask.new('spec') do |t|
7
- t.spec_files = FileList['spec/*_spec.rb']
8
- t.spec_opts = ['--options', "spec/spec.opts"]
6
+ RSpec::Core::RakeTask.new(:spec) do |spec|
7
+ spec.pattern = 'spec/*_spec.rb'
8
+ spec.rspec_opts = '--format documentation --colour --backtrace'
9
9
  end
10
10
 
11
11
  task :default => [:spec]
@@ -81,14 +81,19 @@ class String
81
81
  #
82
82
  # "notes on a scandal" # => "Notes on a Scandal"
83
83
  # "the good german" # => "The Good German"
84
- def titleize
84
+ def titleize(opts={})
85
85
  if defined? ActiveSupport
86
- ActiveSupport::Inflector.titleize(self)
86
+ ActiveSupport::Inflector.titleize(self, opts)
87
87
  else
88
88
  Titleize.titleize(self)
89
89
  end
90
90
  end
91
91
  alias_method :titlecase, :titleize
92
+
93
+ def titleize!
94
+ replace(titleize)
95
+ end
96
+ alias_method :titlecase!, :titleize!
92
97
  end
93
98
 
94
99
  if defined? ActiveSupport
@@ -102,14 +107,20 @@ if defined? ActiveSupport
102
107
  #
103
108
  # This replaces the default Rails titleize. Like the default, it uses
104
109
  # Inflector.underscore and Inflector.humanize to convert
105
- # underscored_names and CamelCaseNames to a more human form.
110
+ # underscored_names and CamelCaseNames to a more human form. However, you can change
111
+ # this behavior by passing :humanize => false or :underscore => false as options.
112
+ # This can be useful when dealing with words like "iPod" and "GPS".
106
113
  #
107
114
  # titleize is also aliased as titlecase.
108
115
  #
109
116
  # "notes on an active_record" # => "Notes on an Active Record"
110
117
  # "the GoodGerman" # => "The Good German"
111
- def titleize(title)
112
- Titleize.titleize(ActiveSupport::Inflector.humanize(ActiveSupport::Inflector.underscore(title)))
118
+ def titleize(title, opts={})
119
+ opts = {:humanize => true, :underscore => true}.merge(opts)
120
+ title = ActiveSupport::Inflector.underscore(title) if opts[:underscore]
121
+ title = ActiveSupport::Inflector.humanize(title) if opts[:humanize]
122
+
123
+ Titleize.titleize(title)
113
124
  end
114
125
  alias_method :titlecase, :titleize
115
126
  end
@@ -1,3 +1,3 @@
1
1
  module Titleize
2
- VERSION = "1.2.1"
2
+ VERSION = "1.3.0"
3
3
  end
@@ -241,6 +241,20 @@ describe ActiveSupport::Inflector do
241
241
  titleize(@title).should == "Active Record and Active Resource"
242
242
  end
243
243
 
244
+ it "should allow disabling of Inflector#underscore" do
245
+ humanized_title = "Active record and activeresource"
246
+ ActiveSupport::Inflector.should_not_receive(:underscore)
247
+ ActiveSupport::Inflector.should_receive(:humanize).with(@title).and_return(humanized_title)
248
+ titleize(@title, :underscore => false).should == "Active Record and Activeresource"
249
+ end
250
+
251
+ it "should allow disabling of Inflector#humanize" do
252
+ underscored_title = "active_record and active_resource"
253
+ ActiveSupport::Inflector.should_not_receive(:humanize)
254
+ ActiveSupport::Inflector.should_receive(:underscore).with(@title).and_return(underscored_title)
255
+ titleize(@title, :humanize => false).should == "Active_record and Active_resource"
256
+ end
257
+
244
258
  it "should replace Inflector.titleize" do
245
259
  Titleize.should_receive(:titleize).with(@title)
246
260
  ActiveSupport::Inflector.stub!(:underscore).and_return(@title)
@@ -262,6 +276,10 @@ describe String do
262
276
  String.instance_methods.map(&:to_sym).should include(:titleize)
263
277
  end
264
278
 
279
+ it "should have a titleize! method" do
280
+ String.instance_methods.map(&:to_sym).should include(:titleize!)
281
+ end
282
+
265
283
  it "should work" do
266
284
  "this is a test".titleize.should == "This Is a Test"
267
285
  end
@@ -272,11 +290,35 @@ describe String do
272
290
  title.titlecase.should == title.titleize
273
291
  end
274
292
 
293
+ context 'when using the self modified version of titleize' do
294
+ it 'should work' do
295
+ test_str = 'this is a test'
296
+ test_str.titleize!
297
+ test_str.should == 'This Is a Test'
298
+ end
299
+
300
+ it 'should be aliased as #titlecase!' do
301
+ test_str = 'this is a test'
302
+ test_str.titlecase!
303
+ test_str.should == 'This Is a Test'
304
+ end
305
+ end
306
+
275
307
  context "when ActiveSupport is loaded" do
276
308
  it "should act the same as Inflector#titleize" do
277
- ActiveSupport::Inflector.should_receive(:titleize).with("title")
309
+ ActiveSupport::Inflector.should_receive(:titleize).with("title", {})
278
310
  "title".titleize
279
311
  end
312
+
313
+ it "should allow disabling of Inflector#underscore" do
314
+ ActiveSupport::Inflector.should_not_receive(:underscore)
315
+ "title".titleize(:underscore => false)
316
+ end
317
+
318
+ it "should allow disabling of Inflector#humanize" do
319
+ ActiveSupport::Inflector.should_not_receive(:humanize)
320
+ "title".titleize(:humanize => false)
321
+ end
280
322
  end
281
323
 
282
324
  context "when ActiveSupport is not loaded" do
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
15
15
  s.required_rubygems_version = Gem::Requirement.new(">= 1.3.6") if s.respond_to? :required_rubygems_version=
16
16
  s.rubyforge_project = "titleize"
17
17
 
18
- s.add_development_dependency "rspec", "~> 1.3"
18
+ s.add_development_dependency "rspec", "~> 2.13"
19
19
  s.add_development_dependency "rake"
20
20
 
21
21
  s.files = `git ls-files`.split("\n")
metadata CHANGED
@@ -1,111 +1,90 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: titleize
3
- version: !ruby/object:Gem::Version
4
- hash: 29
5
- prerelease: false
6
- segments:
7
- - 1
8
- - 2
9
- - 1
10
- version: 1.2.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.3.0
5
+ prerelease:
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Grant Hollingworth
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-04-15 00:00:00 -07:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2013-03-08 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: rspec
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
18
+ requirements:
27
19
  - - ~>
28
- - !ruby/object:Gem::Version
29
- hash: 9
30
- segments:
31
- - 1
32
- - 3
33
- version: "1.3"
20
+ - !ruby/object:Gem::Version
21
+ version: '2.13'
34
22
  type: :development
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: rake
38
23
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '2.13'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
40
33
  none: false
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- hash: 3
45
- segments:
46
- - 0
47
- version: "0"
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
48
38
  type: :development
49
- version_requirements: *id002
50
- description: Adds String#titleize for creating properly capitalized titles. Replaces ActiveSupport::Inflector.titleize if ActiveSupport is present.
51
- email:
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Adds String#titleize for creating properly capitalized titles. Replaces
47
+ ActiveSupport::Inflector.titleize if ActiveSupport is present.
48
+ email:
52
49
  - grant@antiflux.org
53
50
  executables: []
54
-
55
51
  extensions: []
56
-
57
52
  extra_rdoc_files: []
58
-
59
- files:
53
+ files:
60
54
  - .gitignore
61
55
  - Gemfile
62
56
  - History.txt
63
- - Manifest.txt
64
- - README.txt
57
+ - README.md
65
58
  - Rakefile
66
59
  - lib/titleize.rb
67
60
  - lib/titleize/version.rb
68
- - spec/spec.opts
69
61
  - spec/spec_helper.rb
70
62
  - spec/titleize_spec.rb
71
63
  - titleize.gemspec
72
- has_rdoc: true
73
64
  homepage: http://rubygems.org/gems/titleize
74
65
  licenses: []
75
-
76
66
  post_install_message:
77
67
  rdoc_options: []
78
-
79
- require_paths:
68
+ require_paths:
80
69
  - lib
81
- required_ruby_version: !ruby/object:Gem::Requirement
70
+ required_ruby_version: !ruby/object:Gem::Requirement
82
71
  none: false
83
- requirements:
84
- - - ">="
85
- - !ruby/object:Gem::Version
86
- hash: 3
87
- segments:
88
- - 0
89
- version: "0"
90
- required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
77
  none: false
92
- requirements:
93
- - - ">="
94
- - !ruby/object:Gem::Version
95
- hash: 23
96
- segments:
97
- - 1
98
- - 3
99
- - 6
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
100
81
  version: 1.3.6
101
82
  requirements: []
102
-
103
83
  rubyforge_project: titleize
104
- rubygems_version: 1.3.7
84
+ rubygems_version: 1.8.23
105
85
  signing_key:
106
86
  specification_version: 3
107
87
  summary: Adds String#titleize for creating properly capitalized titles.
108
- test_files:
109
- - spec/spec.opts
88
+ test_files:
110
89
  - spec/spec_helper.rb
111
90
  - spec/titleize_spec.rb
@@ -1,8 +0,0 @@
1
- History.txt
2
- Manifest.txt
3
- README.txt
4
- Rakefile
5
- lib/titleize.rb
6
- spec/spec.opts
7
- spec/titleize_spec.rb
8
- spec/spec_helper.rb
@@ -1,3 +0,0 @@
1
- --format specdoc --colour
2
- --backtrace
3
-