summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2015-12-24 16:26:52 -0500
committerRobert Speicher <rspeicher@gmail.com>2015-12-24 16:26:52 -0500
commitc6d25083626c9a97a0ae442298b59c2ff9351f3a (patch)
tree0c6ac8026e8af2a4572400c9fc0a5dfaf7c7da29
parent5a3b9c97e34ee69312ef9bcf575894a106c5a271 (diff)
downloadgitlab-ce-c6d25083626c9a97a0ae442298b59c2ff9351f3a.tar.gz
Truncate page_description to 30 words
-rw-r--r--app/helpers/page_layout_helper.rb4
-rw-r--r--spec/helpers/page_layout_helper_spec.rb13
2 files changed, 15 insertions, 2 deletions
diff --git a/app/helpers/page_layout_helper.rb b/app/helpers/page_layout_helper.rb
index c4eb09bea2b..4f1276f93ec 100644
--- a/app/helpers/page_layout_helper.rb
+++ b/app/helpers/page_layout_helper.rb
@@ -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
diff --git a/spec/helpers/page_layout_helper_spec.rb b/spec/helpers/page_layout_helper_spec.rb
index 5d95beac908..530e9bab343 100644
--- a/spec/helpers/page_layout_helper_spec.rb
+++ b/spec/helpers/page_layout_helper_spec.rb
@@ -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>")