Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

AlexGunslinger
Copy link

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.


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...'
Copy link

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>'

Copy link
Author

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.

delxen pushed a commit to skroutz/truncate_html that referenced this pull request Apr 18, 2019
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
delxen pushed a commit to skroutz/truncate_html that referenced this pull request Apr 18, 2019
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
delxen pushed a commit to skroutz/truncate_html that referenced this pull request Apr 18, 2019
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
delxen pushed a commit to skroutz/truncate_html that referenced this pull request Apr 19, 2019
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
delxen pushed a commit to skroutz/truncate_html that referenced this pull request Apr 22, 2019
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants