From bb901297310b7527e38d6c5f90c1fd01860a901b Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Tue, 12 Jul 2016 13:49:03 -0400 Subject: [PATCH] Improvements to email cook text rendering --- lib/email_cook.rb | 6 +++++- spec/components/email_cook_spec.rb | 22 +++++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/lib/email_cook.rb b/lib/email_cook.rb index 03f40ea2a10..8c91ac27cb9 100644 --- a/lib/email_cook.rb +++ b/lib/email_cook.rb @@ -26,11 +26,15 @@ class EmailCook in_quote = false else + sz = l.size + l.scan(EmailCook.url_regexp).each do |m| url = m[0] l.gsub!(url, "#{url}") end - result << l << "
" + + result << l + result << "
" if sz < 60 end end diff --git a/spec/components/email_cook_spec.rb b/spec/components/email_cook_spec.rb index a440fbf7923..783f7ef5757 100644 --- a/spec/components/email_cook_spec.rb +++ b/spec/components/email_cook_spec.rb @@ -3,10 +3,30 @@ require 'email_cook' describe EmailCook do - it 'adds linebreaks' do + it 'adds linebreaks to short lines' do expect(EmailCook.new("hello\nworld\n").cook).to eq("hello\n
world\n
") end + it "doesn't add linebreaks to long lines" do + long = < +
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc convallis volutpat +risus. Nulla ac faucibus quam, quis cursus lorem. Sed rutrum eget nunc sed accumsan. +Vestibulum feugiat mi vitae turpis tempor dignissim. +
+LONG_COOKED + expect(EmailCook.new(long).cook).to eq(long_cooked.strip) + end + it 'autolinks' do expect(EmailCook.new("https://www.eviltrout.com").cook).to eq("https://www.eviltrout.com
") end