From 4dd43001476befffc1929add99aa0e20606c187b Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Thu, 18 Mar 2010 20:02:17 +0000 Subject: [PATCH] Adds text formatting to documents index (#202). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3602 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/helpers/application_helper.rb | 10 ++++++++++ app/views/documents/_document.rhtml | 9 ++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index bbc1a988..054bac8a 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -263,6 +263,16 @@ module ApplicationHelper def truncate_single_line(string, *args) truncate(string.to_s, *args).gsub(%r{[\r\n]+}m, ' ') end + + # Truncates at line break after 250 characters or options[:length] + def truncate_lines(string, options={}) + length = options[:length] || 250 + if string.to_s =~ /\A(.{#{length}}.*?)$/m + "#{$1}..." + else + string + end + end def html_hours(text) text.gsub(%r{(\d+)\.(\d+)}, '\1.\2') diff --git a/app/views/documents/_document.rhtml b/app/views/documents/_document.rhtml index 94a64ac8..644cf2fb 100644 --- a/app/views/documents/_document.rhtml +++ b/app/views/documents/_document.rhtml @@ -1,3 +1,6 @@ -

<%= link_to h(document.title), :controller => 'documents', :action => 'show', :id => document %>
-<% unless document.description.blank? %><%=h(truncate(document.description, :length => 250)) %>
<% end %> -<%= format_time(document.updated_on) %>

\ No newline at end of file +

<%= link_to h(document.title), :controller => 'documents', :action => 'show', :id => document %>

+

<%= format_time(document.updated_on) %>

+ +
+ <%= textilizable(truncate_lines(document.description)) %> +