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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
avoid truncation on document page
ulfertsc1b8301dc176
diff --git a/app/helpers/text_formatting_helper.rb b/app/helpers/text_formatting_helper.rbindex d8367b2bf4f..a2dd94eac93 100644--- a/app/helpers/text_formatting_helper.rb+++ b/app/helpers/text_formatting_helper.rb@@ -82,7 +82,7 @@ module TextFormattingHelperstripped_text = strip_tags(format_text(text.to_s)).html_safeif length- truncate_lines(stripped_text, length: length)+ truncate_multiline(stripped_text)elsestripped_textend@@ -91,4 +91,12 @@ module TextFormattingHelper.html_safe# rubocop:enable Rails/OutputSafetyend++ def truncate_multiline(string)+ if string.to_s =~ /\A(.{120}).*?$/m+ "#{$1}..."+ else+ string+ end+ endenddiff --git a/lib/open_project/text_formatting/truncation.rb b/lib/open_project/text_formatting/truncation.rbindex ca26236327c..ce94321c169 100644--- a/lib/open_project/text_formatting/truncation.rb+++ b/lib/open_project/text_formatting/truncation.rb@@ -36,15 +36,6 @@ module OpenProjectdef truncate_single_line(string, *args)truncate(string.to_s, *args).gsub(%r{[\r\n]+}m, ' ').html_safeend-- # Truncates at line break after 250 characters- def truncate_lines(string, length: 250)- if string.to_s =~ /\A(.{#{length}}).*?$/m- "#{$1}..."- else- string- end- endendendenddiff --git a/modules/documents/app/views/documents/_document.html.erb b/modules/documents/app/views/documents/_document.html.erbindex 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.rbindex 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 dorender_views@@ -40,32 +40,14 @@ describe DocumentsController docreate(:document_category, project: project, name: "Default Category")end- let(:document) do+ let!(:document) docreate(:document, title: "Sample Document", project: project, category: default_category)endcurrent_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 doexpect(assigns(:grouped)).not_to be_nilexpect(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]}...")- endenddescribe 'new' do@@ -149,7 +126,7 @@ describe DocumentsController doit "adds an attachment" dodocument = Document.last- expect(document.attachments.count).to eql 1+ expect(document.attachments.count).to be 1attachment = document.attachments.firstexpect(uncontainered.reload).to eql attachmentend