-
Notifications
You must be signed in to change notification settings - Fork 115
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
Omission included when truncating by break_token. #57
base: master
Are you sure you want to change the base?
Conversation
|
||
context 'when truncating by break_token and using a omission' do | ||
it 'includes the omission after the truncation' do | ||
truncate('This is the time to truncate this. Do it properly!', :length => 50, :break_token => 'truncate').should == 'This is the time to...' |
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.
You haven't specified an omission here. You've already tested that the default omission of ...
works with all the other tests. You should probably do something like:
truncate('This is the time to truncate this. Do it properly!', :length => 50, :break_token => 'truncate', :omission => link_to(' MORE', 'path')).should == 'This is the time to <a href="path">MORE</a>'
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.
Thanks @gwagener! It was a good idea to include a test with a custom omission.
When using break_token, omissions was not added in the truncated html. Fix based on hgmnz/truncate_html#57. Issue described here hgmnz/truncate_html#52
When using break_token, omissions was not added in the truncated html. Fix based on hgmnz/truncate_html#57. Issue described here hgmnz/truncate_html#52
When using break_token, omissions was not added in the truncated html. Fix based on hgmnz/truncate_html#57. Issue described here hgmnz/truncate_html#52
When using break_token, omissions was not added in the truncated html. Fix based on hgmnz/truncate_html#57. Issue described here hgmnz/truncate_html#52
When using break_token, omissions was not added in the truncated html. Fix based on hgmnz/truncate_html#57. Issue described here hgmnz/truncate_html#52
This solves the issue #52
I just moved a little bit the logic to stop the truncation by break_token.
Instead of doing it on the truncate method (where it would not include the omission), I did it where the pipeline process occurs, if the token is the break token it will automatically put the chars_remaining at 0, and includes the omission if it happened.
I did it in a way that if the break token is a tag, it will include the omission anyway. If the tag is an opening tag, it will not include the tag, if it is a closing tag, it will include it via the close_open_tags method. (I guess that we don't want to leave any tag open in the string).
Doing it like this, we make sure that the truncation plus the omission will always be shorter or equal than the length param.
I included the proper test for this case.