Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

avoid truncation on document page

ulfertsc1b8301dc176
diff --git a/app/helpers/text_formatting_helper.rb b/app/helpers/text_formatting_helper.rb
index d8367b2bf4f..a2dd94eac93 100644
--- a/app/helpers/text_formatting_helper.rb
+++ b/app/helpers/text_formatting_helper.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
diff --git a/lib/open_project/text_formatting/truncation.rb b/lib/open_project/text_formatting/truncation.rb
index ca26236327c..ce94321c169 100644
--- a/lib/open_project/text_formatting/truncation.rb
+++ b/lib/open_project/text_formatting/truncation.rb
@@ -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
diff --git a/modules/documents/app/views/documents/_document.html.erb b/modules/documents/app/views/documents/_document.html.erb
index 05155759c3a..924bd676074 100644
--- a/modules/documents/app/views/documents/_document.html.erb
+++ b/modules/documents/app/views/documents/_document.html.erb
@@ -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>
diff --git a/modules/documents/spec/controllers/documents_controller_spec.rb b/modules/documents/spec/controllers/documents_controller_spec.rb
index 5831f5e5dc1..1014cc3b389 100644
--- a/modules/documents/spec/controllers/documents_controller_spec.rb
+++ b/modules/documents/spec/controllers/documents_controller_spec.rb
@@ -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