avoid truncation on document page

pull/10724/head
ulferts 2 years ago
parent fd874a8311
commit c1b8301dc1
No known key found for this signature in database
GPG Key ID: A205708DE1284017
  1. 10
      app/helpers/text_formatting_helper.rb
  2. 9
      lib/open_project/text_formatting/truncation.rb
  3. 2
      modules/documents/app/views/documents/_document.html.erb
  4. 29
      modules/documents/spec/controllers/documents_controller_spec.rb

@ -82,7 +82,7 @@ module TextFormattingHelper
stripped_text = strip_tags(format_text(text.to_s)).html_safe
if length
truncate_lines(stripped_text, length: length)
truncate_multiline(stripped_text)
else
stripped_text
end
@ -91,4 +91,12 @@ module TextFormattingHelper
.html_safe
# rubocop:enable Rails/OutputSafety
end
def truncate_multiline(string)
if string.to_s =~ /\A(.{120}).*?$/m
"#{$1}..."
else
string
end
end
end

@ -36,15 +36,6 @@ module OpenProject
def truncate_single_line(string, *args)
truncate(string.to_s, *args).gsub(%r{[\r\n]+}m, ' ').html_safe
end
# Truncates at line break after 250 characters
def truncate_lines(string, length: 250)
if string.to_s =~ /\A(.{#{length}}).*?$/m
"#{$1}..."
else
string
end
end
end
end
end

@ -31,5 +31,5 @@ See COPYRIGHT and LICENSE files for more details.
<p class="document-category-elements--date"><em><%= format_time(document.updated_at) %></em></p>
<div class="wiki op-uc-container">
<%= truncate_formatted_text(document.description, length: 250) %>
<%= format_text(document.description) %>
</div>

@ -26,7 +26,7 @@
# See COPYRIGHT and LICENSE files for more details.
#++
require File.dirname(__FILE__) + '/../spec_helper'
require "#{File.dirname(__FILE__)}/../spec_helper"
describe DocumentsController do
render_views
@ -40,32 +40,14 @@ describe DocumentsController do
create(:document_category, project: project, name: "Default Category")
end
let(:document) do
let!(:document) do
create(:document, title: "Sample Document", project: project, category: default_category)
end
current_user { admin }
describe "index" do
let(:long_description) do
<<-LOREM.strip_heredoc
Lorem ipsum dolor sit amet, consectetur adipiscing elit.\
Ut egestas, mi vehicula varius varius, ipsum massa fermentum orci,\
eget tristique ante sem vel mi. Nulla facilisi.\
Donec enim libero, luctus ac sagittis sit amet, vehicula sagittis magna.\
Duis ultrices molestie ante, eget scelerisque sem iaculis vitae.\
Etiam fermentum mauris vitae metus pharetra condimentum fermentum est pretium.\
Proin sollicitudin elementum quam quis pharetra.\
Aenean facilisis nunc quis elit volutpat mollis.\
Aenean eleifend varius euismod. Ut dolor est, congue eget dapibus eget, elementum eu odio.\
Integer et lectus neque, nec scelerisque nisi. EndOfLineHere
Praesent a nunc lorem, ac porttitor eros.
LOREM
end
before do
document.update(description: long_description)
get :index, params: { project_id: project.identifier }
end
@ -78,11 +60,6 @@ describe DocumentsController do
expect(assigns(:grouped)).not_to be_nil
expect(assigns(:grouped).keys.map(&:name)).to eql [default_category.name]
end
it "renders documents with long descriptions properly" do
expect(response.body).to have_selector('.wiki', visible: :all)
expect(response.body).to have_selector('.wiki', visible: :all, text: "#{document.description[0..249]}...")
end
end
describe 'new' do
@ -149,7 +126,7 @@ describe DocumentsController do
it "adds an attachment" do
document = Document.last
expect(document.attachments.count).to eql 1
expect(document.attachments.count).to be 1
attachment = document.attachments.first
expect(uncontainered.reload).to eql attachment
end

Loading…
Cancel
Save