Improvements to email cook text rendering
This commit is contained in:
parent
0c3b049176
commit
bb90129731
|
@ -26,11 +26,15 @@ class EmailCook
|
||||||
in_quote = false
|
in_quote = false
|
||||||
else
|
else
|
||||||
|
|
||||||
|
sz = l.size
|
||||||
|
|
||||||
l.scan(EmailCook.url_regexp).each do |m|
|
l.scan(EmailCook.url_regexp).each do |m|
|
||||||
url = m[0]
|
url = m[0]
|
||||||
l.gsub!(url, "<a href='#{url}'>#{url}</a>")
|
l.gsub!(url, "<a href='#{url}'>#{url}</a>")
|
||||||
end
|
end
|
||||||
result << l << "<br>"
|
|
||||||
|
result << l
|
||||||
|
result << "<br>" if sz < 60
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -3,10 +3,30 @@ require 'email_cook'
|
||||||
|
|
||||||
describe EmailCook do
|
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<br>world\n<br>")
|
expect(EmailCook.new("hello\nworld\n").cook).to eq("hello\n<br>world\n<br>")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "doesn't add linebreaks to long lines" do
|
||||||
|
long = <<LONG_EMAIL
|
||||||
|
Hello,
|
||||||
|
|
||||||
|
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_EMAIL
|
||||||
|
|
||||||
|
long_cooked = <<LONG_COOKED
|
||||||
|
Hello,
|
||||||
|
<br>
|
||||||
|
<br>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.
|
||||||
|
<br>
|
||||||
|
LONG_COOKED
|
||||||
|
expect(EmailCook.new(long).cook).to eq(long_cooked.strip)
|
||||||
|
end
|
||||||
|
|
||||||
it 'autolinks' do
|
it 'autolinks' do
|
||||||
expect(EmailCook.new("https://www.eviltrout.com").cook).to eq("<a href='https://www.eviltrout.com'>https://www.eviltrout.com</a><br>")
|
expect(EmailCook.new("https://www.eviltrout.com").cook).to eq("<a href='https://www.eviltrout.com'>https://www.eviltrout.com</a><br>")
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue