-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds ability to specify custom small words and acronyms #14
base: master
Are you sure you want to change the base?
Conversation
@@ -338,7 +366,7 @@ def humanize(string) string; end | |||
end | |||
|
|||
it "should call Titleize#titleize" do | |||
Titleize.should_receive(:titleize).with("title") | |||
Titleize.should_receive(:titleize).with("title", {}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer single-quoted strings when you don't need string interpolation or special symbols.
it "should properly capitalize acronyms configured in Inflector.inflections.acronyms" do | ||
inflections = double(acronyms: ['SEC']) | ||
ActiveSupport::Inflector.stub!(:inflections).and_return(inflections) | ||
"SMITH TO HEAD SEC".titleize.should == 'Smith to Head SEC' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer single-quoted strings when you don't need string interpolation or special symbols.
@@ -326,6 +348,12 @@ def humanize(string) string; end | |||
ActiveSupport::Inflector.should_not_receive(:humanize) | |||
"title".titleize(:humanize => false) | |||
end | |||
|
|||
it "should properly capitalize acronyms configured in Inflector.inflections.acronyms" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer single-quoted strings when you don't need string interpolation or special symbols.
Line is too long. [92/80]
@@ -115,7 +137,7 @@ def humanize(string) string; end | |||
titleize("ends with 'quotation.'").should == "Ends With 'Quotation.'" | |||
end | |||
|
|||
it "should not capitalize words that have a lowercase first letter" do | |||
it "should not capitalize words that have a lowercase first letter" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer single-quoted strings when you don't need string interpolation or special symbols.
end | ||
end | ||
|
||
it "should not capitalize words with dots" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer single-quoted strings when you don't need string interpolation or special symbols.
@@ -102,11 +106,29 @@ def humanize(string) string; end | |||
end | |||
end | |||
|
|||
it "should not capitalize custom small words specified in opts[:small_words]" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer single-quoted strings when you don't need string interpolation or special symbols.
Line is too long. [84/80]
#stub | ||
def underscore(string) string; end | ||
def humanize(string) string; end | ||
def inflections |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use empty lines between method definitions.
lib/titleize.rb
Outdated
# for ActiveSupport::Inflector | ||
opts[:acronyms] ||= ActiveSupport::Inflector.inflections.acronyms | ||
|
||
passthru_opts = opts.select { |k, _| [:acronyms, :small_words].include?(k) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [82/80]
@@ -114,7 +122,7 @@ module ActiveSupport::Inflector | |||
# This replaces the default Rails titleize. Like the default, it uses | |||
# Inflector.underscore and Inflector.humanize to convert | |||
# underscored_names and CamelCaseNames to a more human form. However, you can change | |||
# this behavior by passing :humanize => false or :underscore => false as options. | |||
# this behavior by passing :humanize => false or :underscore => false as options. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [85/80]
end | ||
end | ||
alias_method :titlecase, :titleize | ||
|
||
def titleize! | ||
replace(titleize) | ||
def titleize!(opts={}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Surrounding space missing in default value assignment.
8503b98
to
1847ca8
Compare
# capitalized. To override the set of acronyms used, pass in | ||
# opts[:acronyms] | ||
# | ||
# titleize("SMITH TO HEAD SEC", acronyms: ['SEC']) # => "Smith to Head SEC" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [81/80]
1847ca8
to
93efd76
Compare
# for ActiveSupport::Inflector | ||
opts[:acronyms] ||= ActiveSupport::Inflector.inflections.acronyms.values | ||
|
||
passthru_opts = opts.select { |k, _| [:acronyms, :small_words].include?(k) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [82/80]
Thanks! This looks good, and I think I'll merge it with some minor changes. I'll get Hound to stand down on some of its issues – single quotes for sure. It also takes care of the languishing #11. |
Sounds good. I left hound's howls alone since what I added seemed to (mostly) match what I saw in the existing code. If you need me to make changes I'm happy to, or, of course, you can hack it as you wish! |
This PR adds the ability to pass a list of acronyms to be capitalized when titleizing a string. It also includes the ability to pass a custom list of small words, which are added to the built-in list.
When ActiveSupport is loaded,
titleize
now will also respect the acronyms configured inActiveSupport::Inflector.inflections.acronyms
.