Adds ability to specify custom small words and acronyms#14
Adds ability to specify custom small words and acronyms#14santry wants to merge 1 commit intogranth:masterfrom
Conversation
|
|
||
| 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.
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.
Prefer single-quoted strings when you don't need string interpolation or special symbols.
| "title".titleize(:humanize => false) | ||
| end | ||
|
|
||
| it "should properly capitalize acronyms configured in Inflector.inflections.acronyms" do |
There was a problem hiding this comment.
Prefer single-quoted strings when you don't need string interpolation or special symbols.
Line is too long. [92/80]
| 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.
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.
Prefer single-quoted strings when you don't need string interpolation or special symbols.
| end | ||
| end | ||
|
|
||
| it "should not capitalize custom small words specified in opts[:small_words]" do |
There was a problem hiding this comment.
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.
Use empty lines between method definitions.
| # for ActiveSupport::Inflector | ||
| opts[:acronyms] ||= ActiveSupport::Inflector.inflections.acronyms | ||
|
|
||
| passthru_opts = opts.select { |k, _| [:acronyms, :small_words].include?(k) } |
| # 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. |
|
|
||
| def titleize! | ||
| replace(titleize) | ||
| def titleize!(opts={}) |
There was a problem hiding this comment.
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" |
1847ca8 to
93efd76
Compare
| # for ActiveSupport::Inflector | ||
| opts[:acronyms] ||= ActiveSupport::Inflector.inflections.acronyms.values | ||
|
|
||
| passthru_opts = opts.select { |k, _| [:acronyms, :small_words].include?(k) } |
|
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,
titleizenow will also respect the acronyms configured inActiveSupport::Inflector.inflections.acronyms.