Truncate page_description to 30 words

This commit is contained in:
Robert Speicher 2015-12-24 16:26:52 -05:00
parent 5a3b9c97e3
commit c6d2508362
2 changed files with 15 additions and 2 deletions

View file

@ -30,9 +30,9 @@ module PageLayoutHelper
@page_description ||= page_description_default
if description.present?
@page_description = description
@page_description = description.squish
else
sanitize(@page_description.squish, tags: [])
sanitize(@page_description, tags: []).truncate_words(30)
end
end

View file

@ -22,6 +22,19 @@ describe PageLayoutHelper do
expect(helper.page_description).to eq 'Foo Bar Baz'
end
it 'truncates' do
helper.page_description <<-LOREM.strip_heredoc
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo
ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis
dis parturient montes, nascetur ridiculus mus. Donec quam felis,
ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa
quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget,
arcu.
LOREM
expect(helper.page_description).to end_with 'quam felis,...'
end
it 'sanitizes all HTML' do
helper.page_description("<b>Bold</b> <h1>Header</h1>")