diff --git a/app/helpers/text_helper.rb b/app/helpers/text_helper.rb new file mode 100644 index 000000000..dda3ba721 --- /dev/null +++ b/app/helpers/text_helper.rb @@ -0,0 +1,9 @@ +module TextHelper + def first_paragraph(text) + if text.blank? + "" + else + text.strip.split("\n").first + end + end +end diff --git a/app/views/legislation/processes/_process.html.erb b/app/views/legislation/processes/_process.html.erb index 9eac89a7b..a5780f792 100644 --- a/app/views/legislation/processes/_process.html.erb +++ b/app/views/legislation/processes/_process.html.erb @@ -3,7 +3,7 @@

<%= link_to process.title, process %>

-

<%= process.description %>

+ <%= simple_format(first_paragraph(process.description)) %>
diff --git a/spec/helpers/text_helper_spec.rb b/spec/helpers/text_helper_spec.rb new file mode 100644 index 000000000..cc9300b7f --- /dev/null +++ b/spec/helpers/text_helper_spec.rb @@ -0,0 +1,17 @@ +require 'rails_helper' + +describe TextHelper do + + describe "#first_paragraph" do + it "should return the first paragraph of a text" do + text = "\n\nThis is the first paragraph\n\nThis is the second paragraph\n" + expect(first_paragraph(text)).to eq("This is the first paragraph") + end + + it "should return blank if the text is blank" do + expect(first_paragraph("")).to eq("") + expect(first_paragraph(nil)).to eq("") + end + end + +end