Commit c6d25083 authored by Robert Speicher's avatar Robert Speicher

Truncate page_description to 30 words

parent 5a3b9c97
...@@ -30,9 +30,9 @@ module PageLayoutHelper ...@@ -30,9 +30,9 @@ module PageLayoutHelper
@page_description ||= page_description_default @page_description ||= page_description_default
if description.present? if description.present?
@page_description = description @page_description = description.squish
else else
sanitize(@page_description.squish, tags: []) sanitize(@page_description, tags: []).truncate_words(30)
end end
end end
......
...@@ -22,6 +22,19 @@ describe PageLayoutHelper do ...@@ -22,6 +22,19 @@ describe PageLayoutHelper do
expect(helper.page_description).to eq 'Foo Bar Baz' expect(helper.page_description).to eq 'Foo Bar Baz'
end 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 it 'sanitizes all HTML' do
helper.page_description("<b>Bold</b> <h1>Header</h1>") helper.page_description("<b>Bold</b> <h1>Header</h1>")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment