Created
June 19, 2014 20:39
-
-
Save amccloud/3fc684661c642cde7e2f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module TypographyHelper | |
WIDOW_EXPRESSION = /([^\s])\s+([^\s]+)\s*$/ | |
def widont(text, count=1) | |
count.times.inject(text) do |text| | |
text.sub(WIDOW_EXPRESSION, '\1 \2') | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
describe TypographyHelper do | |
specify '#widont' do | |
expect(helper.widont('')).to eq '' | |
expect(helper.widont('text')).to eq 'text' | |
expect(helper.widont('text with widow')).to eq 'text with widow' | |
expect(helper.widont('text with widow', 1)).to eq 'text with widow' | |
expect(helper.widont('text with widow', 2)).to eq 'text with widow' | |
expect(helper.widont('text with widow', 3)).to eq 'text with widow' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment