titleize 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ G*�~e쫇���kx �lvѪQ|:���C=-W/L���(#�N��LgS�{��`=��씯<��0}�<�r��k�N��th��V��y%�Y�S�@������8�]���(%�5-lX�|�?-�졉�ʒ��s�,t;��<��[z�:�{y6�voUk�s&M�:[�m ��ё�.�������������^��f��4Αo�\�Uq�`����L�>b��a�9�r� �3q'%�����!��(
@@ -0,0 +1,5 @@
1
+ === 1.0.0 / 2008-05-22
2
+
3
+ * Hoe-ized for RubyGemming
4
+
5
+
@@ -0,0 +1,8 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ lib/titleize.rb
6
+ spec/spec.opts
7
+ spec/spec/titleize_spec.rb
8
+ spec/spec_helper.rb
@@ -0,0 +1,50 @@
1
+ = Titleize
2
+
3
+ * http://rubyforge.org/projects/titleize/
4
+
5
+ == DESCRIPTION:
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.
10
+
11
+ The list of "small words" which are not capped comes from the New York Times
12
+ Manual of Style, plus 'vs' and 'v'.
13
+
14
+ If loaded in a Rails environment, it modifies Inflector.titleize.
15
+
16
+ Based on TitleCase.pl by John Gruber.
17
+ http://daringfireball.net/2008/05/title_case
18
+
19
+ == SYNOPSIS:
20
+
21
+ "a lovely and talented title".titleize # => "A Lovely and Talented Title"
22
+
23
+ == INSTALL:
24
+
25
+ * gem install titleize
26
+
27
+ == LICENSE:
28
+
29
+ (The MIT License)
30
+
31
+ Copyright (c) 2008 Grant Hollingworth
32
+
33
+ Permission is hereby granted, free of charge, to any person obtaining
34
+ a copy of this software and associated documentation files (the
35
+ 'Software'), to deal in the Software without restriction, including
36
+ without limitation the rights to use, copy, modify, merge, publish,
37
+ distribute, sublicense, and/or sell copies of the Software, and to
38
+ permit persons to whom the Software is furnished to do so, subject to
39
+ the following conditions:
40
+
41
+ The above copyright notice and this permission notice shall be
42
+ included in all copies or substantial portions of the Software.
43
+
44
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
45
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
46
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
47
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
48
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
49
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
50
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,21 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+ require './lib/titleize.rb'
6
+ require 'spec/rake/spectask'
7
+
8
+ Hoe.new('titleize', Titleize::VERSION) do |p|
9
+ p.developer("Grant Hollingworth", "grant@antiflux.org")
10
+ p.remote_rdoc_dir = '' # Release to root
11
+ end
12
+
13
+ desc "Run all specs"
14
+ Spec::Rake::SpecTask.new('spec') do |t|
15
+ t.spec_files = FileList['spec/**/*.rb']
16
+ t.spec_opts = ['--options', "spec/spec.opts"]
17
+ end
18
+
19
+ task :default => [:spec]
20
+
21
+ # vim: syntax=Ruby
@@ -0,0 +1,103 @@
1
+ # Adds String#titleize for creating properly capitalized titles.
2
+ # It can be called as Titleize.titleize or "a string".titleize.
3
+ #
4
+ # titlecase is included as an alias for titleize.
5
+ #
6
+ # If loaded in a Rails environment, it modifies Inflector.titleize.
7
+ module Titleize
8
+ VERSION = '1.0.0'
9
+ 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
+ extend self
12
+
13
+ # Capitalizes most words to create a nicer looking title string.
14
+ #
15
+ # The list of "small words" which are not capped comes from
16
+ # the New York Times Manual of Style, plus 'vs' and 'v'.
17
+ #
18
+ # "notes on a scandal" # => "Notes on a Scandal"
19
+ # "the good german" # => "The Good German"
20
+ def titleize(title)
21
+ phrases(title).map do |phrase|
22
+ words = phrase.split
23
+ words.map do |word|
24
+ def word.capitalize
25
+ # like String#capitalize, but it starts with the first letter
26
+ self.sub(/[[:alpha:]].*/) {|subword| subword.capitalize}
27
+ end
28
+
29
+ case word
30
+ when /[[:alpha:]]\.[[:alpha:]]/ # words with dots in, like "example.com"
31
+ word
32
+ when /^[[:alpha:]].*[[:upper:]]/ # non-first letter capitalized already
33
+ word
34
+ when words.first, words.last
35
+ word.capitalize
36
+ when *(SMALL_WORDS + SMALL_WORDS.map {|small| small.capitalize })
37
+ word.downcase
38
+ else
39
+ word.capitalize
40
+ end
41
+ end.join(" ")
42
+ end.join(" ")
43
+ end
44
+
45
+ # Splits a title into an array based on punctuation.
46
+ #
47
+ # "simple title" # => ["simple title"]
48
+ # "more complicated: titling" # => ["more complicated:", "titling"]
49
+ def phrases(title)
50
+ phrases = title.scan(/.+?(?:[:.;?!] |$)/).map {|phrase| phrase.strip }
51
+
52
+ # rejoin phrases that were split on the '.' from a small word
53
+ if phrases.size > 1
54
+ phrases[0..-1].each_with_index do |phrase, index|
55
+ if SMALL_WORDS.include?(phrase.split.last.downcase)
56
+ phrases[index] << " " + phrases.slice!(index + 1)
57
+ end
58
+ end
59
+ end
60
+
61
+ phrases
62
+ end
63
+ end
64
+
65
+ class String
66
+ # Capitalizes most words to create a nicer looking title string.
67
+ #
68
+ # The list of "small words" which are not capped comes from
69
+ # the New York Times Manual of Style, plus 'vs' and 'v'.
70
+ #
71
+ # titleize is also aliased as titlecase.
72
+ #
73
+ # "notes on a scandal" # => "Notes on a Scandal"
74
+ # "the good german" # => "The Good German"
75
+ def titleize
76
+ Titleize.titleize(self)
77
+ end
78
+ alias_method :titlecase, :titleize
79
+ end
80
+
81
+ if defined? Inflector
82
+ module Inflector
83
+ extend self
84
+
85
+ # Capitalizes most words to create a nicer looking title string.
86
+ #
87
+ # The list of "small words" which are not capped comes from
88
+ # the New York Times Manual of Style, plus 'vs' and 'v'.
89
+ #
90
+ # This replaces the default Rails titleize. Like the default, it uses
91
+ # Inflector.underscore and Inflector.humanize to convert
92
+ # underscored_names and CamelCaseNames to a more human form.
93
+ #
94
+ # titleize is also aliased as titlecase.
95
+ #
96
+ # "notes on an active_record" # => "Notes on an Active Record"
97
+ # "the GoodGerman" # => "The Good German"
98
+ def titleize(title)
99
+ Titleize.titleize(Inflector.humanize(Inflector.underscore(title)))
100
+ end
101
+ alias_method :titlecase, :titleize
102
+ end
103
+ end
@@ -0,0 +1 @@
1
+ --format specdoc --colour
@@ -0,0 +1,198 @@
1
+ module Inflector
2
+ #stub
3
+ end
4
+
5
+ require File.dirname(__FILE__) + "/../spec_helper.rb"
6
+
7
+ 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
+
9
+ describe Titleize do
10
+ describe "phrases" do
11
+ it "should return an array" do
12
+ phrases("a little sentence").should be_an_instance_of(Array)
13
+ end
14
+
15
+ it "should split on colons" do
16
+ phrases("this: a subphrase").should == ["this:", "a subphrase"]
17
+ end
18
+
19
+ it "should split on semi-colons" do
20
+ phrases("this; that").should == ["this;", "that"]
21
+ end
22
+
23
+ it "should split on question marks" do
24
+ phrases("this? that").should == ["this?", "that"]
25
+ end
26
+
27
+ it "should split on periods" do
28
+ phrases("this. that.").should == ["this.", "that."]
29
+ end
30
+
31
+ it "should split on exclamation marks" do
32
+ phrases("headache! yes").should == ["headache!", "yes"]
33
+ end
34
+
35
+ it "should rejoin into the original string" do
36
+ title = "happy: not sad; pushing! laughing? ok."
37
+ phrases(title).join(" ").should == title
38
+ end
39
+
40
+ it "should not get confused by small words with punctuation" do
41
+ phrases("this vs. that").should == ["this vs. that"]
42
+ phrases("this vs. that. no").should == ["this vs. that.", "no"]
43
+ phrases("this: that vs. him. no. why?").should ==
44
+ ["this:", "that vs. him.", "no.", "why?"]
45
+ end
46
+ end
47
+
48
+ describe "titleize" do
49
+ it "should return a string" do
50
+ titleize("this").should be_an_instance_of(String)
51
+ end
52
+
53
+ it "should capitalize the first letter of regular words" do
54
+ titleize("cat beats monkey").should == "Cat Beats Monkey"
55
+ end
56
+
57
+ it "should not capitalize small words" do
58
+ SMALL_WORDS.each do |word|
59
+ titleize("first #{word} last").should == "First #{word} Last"
60
+ end
61
+ end
62
+
63
+ it "should downcase a small word if it is capitalized" do
64
+ SMALL_WORDS.each do |word|
65
+ titleize("first #{word.capitalize} last").should == "First #{word} Last"
66
+ end
67
+ end
68
+
69
+ it "should capitalize a small word if it is the first word" do
70
+ SMALL_WORDS.each do |word|
71
+ titleize("#{word} is small").should == "#{word.capitalize} Is Small"
72
+ titleize("after: #{word} ok").should == "After: #{word.capitalize} Ok"
73
+ titleize("after; #{word} ok").should == "After; #{word.capitalize} Ok"
74
+ titleize("after. #{word} ok").should == "After. #{word.capitalize} Ok"
75
+ titleize("after? #{word} ok").should == "After? #{word.capitalize} Ok"
76
+ titleize("after! #{word} ok").should == "After! #{word.capitalize} Ok"
77
+ end
78
+ end
79
+
80
+ it "should capitalize a small word if it is the last word" do
81
+ SMALL_WORDS.each do |word|
82
+ titleize("small #{word}").should == "Small #{word.capitalize}"
83
+ end
84
+ end
85
+
86
+ it "should not screw up acronyms" do
87
+ titleize("the SEC's decision").should == "The SEC's Decision"
88
+ end
89
+
90
+ it "should not capitalize words with dots" do
91
+ titleize("del.icio.us web site").should == "del.icio.us Web Site"
92
+ end
93
+
94
+ it "should not think a quotation mark makes a dot word" do
95
+ titleize("'quoted.' yes.").should == "'Quoted.' Yes."
96
+ titleize("ends with 'quotation.'").should == "Ends With 'Quotation.'"
97
+ end
98
+
99
+ it "should not capitalize words that have a lowercase first letter" do
100
+ titleize("iTunes").should == "iTunes"
101
+ end
102
+
103
+ # http://daringfireball.net/projects/titlecase/examples-edge-cases
104
+ it "should handle edge cases" do
105
+ {
106
+ %{Q&A With Steve Jobs: 'That's What Happens In Technology'} =>
107
+ %{Q&A With Steve Jobs: 'That's What Happens in Technology'},
108
+
109
+ %{What Is AT&T's Problem?} => %{What Is AT&T's Problem?},
110
+
111
+ %{Apple Deal With AT&T Falls Through} =>
112
+ %{Apple Deal With AT&T Falls Through},
113
+
114
+ %{this v that} => %{This v That},
115
+ %{this vs that} => %{This vs That},
116
+ %{this v. that} => %{This v. That},
117
+ %{this vs. that} => %{This vs. That},
118
+
119
+ %{The SEC's Apple Probe: What You Need to Know} =>
120
+ %{The SEC's Apple Probe: What You Need to Know},
121
+
122
+ %{'by the Way, small word at the start but within quotes.'} =>
123
+ %{'By the Way, Small Word at the Start but Within Quotes.'},
124
+
125
+ %{Small word at end is nothing to be afraid of} =>
126
+ %{Small Word at End Is Nothing to Be Afraid Of},
127
+
128
+ %{Starting Sub-Phrase With a Small Word: a Trick, Perhaps?} =>
129
+ %{Starting Sub-Phrase With a Small Word: A Trick, Perhaps?},
130
+
131
+ %{Sub-Phrase With a Small Word in Quotes: 'a Trick, Perhaps?'} =>
132
+ %{Sub-Phrase With a Small Word in Quotes: 'A Trick, Perhaps?'},
133
+
134
+ %{Sub-Phrase With a Small Word in Quotes: "a Trick, Perhaps?"} =>
135
+ %{Sub-Phrase With a Small Word in Quotes: "A Trick, Perhaps?"},
136
+
137
+ %{"Nothing to Be Afraid of?"} => %{"Nothing to Be Afraid Of?"},
138
+ %{"Nothing to Be Afraid Of?"} => %{"Nothing to Be Afraid Of?"},
139
+ %{a thing} => %{A Thing},
140
+
141
+ %{'Gruber on OmniFocus and Vapo(u)rware'} =>
142
+ %{'Gruber on OmniFocus and Vapo(u)rware'},
143
+ }.each do |before, after|
144
+ titleize(before).should == after
145
+ end
146
+ end
147
+ end
148
+
149
+ it "should have titleize as a singleton method" do
150
+ Titleize.singleton_methods.should include("titleize")
151
+ end
152
+ end
153
+
154
+ describe Inflector do
155
+ describe "titleize" do
156
+ before(:each) do
157
+ @title = "active_record and ActiveResource"
158
+ end
159
+
160
+ it "should call humanize and underscore like the default in Rails" do
161
+ underscored_title = "active_record and active_resource"
162
+ humanized_title = "Active record and active resource"
163
+ Inflector.should_receive(:underscore).with(@title).and_return(underscored_title)
164
+ Inflector.should_receive(:humanize).with(underscored_title).and_return(humanized_title)
165
+ titleize(@title).should == "Active Record and Active Resource"
166
+ end
167
+
168
+ it "should replace Inflector.titleize" do
169
+ Titleize.should_receive(:titleize).with(@title)
170
+ Inflector.stub!(:underscore).and_return(@title)
171
+ Inflector.stub!(:humanize).and_return(@title)
172
+ Inflector.titleize(@title)
173
+ end
174
+
175
+ it "should be aliased as titlecase" do
176
+ Inflector.singleton_methods.should include("titlecase")
177
+ Inflector.stub!(:titlecase).and_return("title")
178
+ Inflector.stub!(:titleize).and_return("title")
179
+ Inflector.titlecase("this").should == Inflector.titleize("this")
180
+ end
181
+ end
182
+ end
183
+
184
+ describe String do
185
+ it "should have a titleize method" do
186
+ String.instance_methods.should include("titleize")
187
+ end
188
+
189
+ it "should work" do
190
+ "this is a test".titleize.should == "This Is a Test"
191
+ end
192
+
193
+ it "should be aliased as #titlecase" do
194
+ String.instance_methods.should include("titlecase")
195
+ title = "this is a pile of testing text"
196
+ title.titlecase.should == title.titleize
197
+ end
198
+ end
@@ -0,0 +1,5 @@
1
+ dir = File.dirname(__FILE__)
2
+ lib_path = File.expand_path("#{dir}/../lib")
3
+ $LOAD_PATH.unshift lib_path unless $LOAD_PATH.include?(lib_path)
4
+
5
+ require 'titleize'
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: titleize
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Grant Hollingworth
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDMjCCAhqgAwIBAgIBADANBgkqhkiG9w0BAQUFADA/MQ4wDAYDVQQDDAVncmFu
14
+ dDEYMBYGCgmSJomT8ixkARkWCGFudGlmbHV4MRMwEQ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 -----END CERTIFICATE-----
32
+
33
+ date: 2008-05-22 00:00:00 -04:00
34
+ default_executable:
35
+ dependencies:
36
+ - !ruby/object:Gem::Dependency
37
+ name: hoe
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 1.5.3
44
+ version:
45
+ description: Adds String#titleize for creating properly capitalized titles. It can be called as Titleize.titleize or "a string".titleize. It is also aliased as titlecase. The list of "small words" which are not capped comes from the New York Times Manual of Style, plus 'vs' and 'v'. If loaded in a Rails environment, it modifies Inflector.titleize. Based on TitleCase.pl by John Gruber. http://daringfireball.net/2008/05/title_case
46
+ email:
47
+ - grant@antiflux.org
48
+ executables: []
49
+
50
+ extensions: []
51
+
52
+ extra_rdoc_files:
53
+ - History.txt
54
+ - Manifest.txt
55
+ - README.txt
56
+ files:
57
+ - History.txt
58
+ - Manifest.txt
59
+ - README.txt
60
+ - Rakefile
61
+ - lib/titleize.rb
62
+ - spec/spec.opts
63
+ - spec/spec/titleize_spec.rb
64
+ - spec/spec_helper.rb
65
+ has_rdoc: true
66
+ homepage: http://rubyforge.org/projects/titleize/
67
+ post_install_message:
68
+ rdoc_options:
69
+ - --main
70
+ - README.txt
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: "0"
78
+ version:
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: "0"
84
+ version:
85
+ requirements: []
86
+
87
+ rubyforge_project: titleize
88
+ rubygems_version: 1.0.1
89
+ signing_key:
90
+ specification_version: 2
91
+ summary: Adds String#titleize for creating properly capitalized titles
92
+ test_files: []
93
+
@@ -0,0 +1,3 @@
1
+ �J �E�)E������?l��qw�b�f2�#���ٳ��y�k�L
2
+ _��ށ��Gl�X� �筥TRuq�}�9��� -�Nc7<f"��ThWc�C�g�˾՞��$?���Z�(,d�ud�ۖ_���`t��+�=J�
3
+ %� �p�u�s����ϯ����.��h���l�n��T������/��w��j�3�boy���o��o�2V�g┿���ݢ6�CA���'�}QĪ;c���?jt��(<%