diff app/models/project.rb @ 130:db0caa9f0ff4 cannam-pre-20110113-merge

Make project descriptions briefer on the projects list, and ensure that images &c are removed from them
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Mon, 17 Jan 2011 14:47:09 +0000
parents 94944d00e43c
children 05f9a2a9c753
line wrap: on
line diff
--- a/app/models/project.rb	Thu Jan 06 10:41:19 2011 +0000
+++ b/app/models/project.rb	Mon Jan 17 14:47:09 2011 +0000
@@ -418,7 +418,14 @@
   
   # Returns a short description of the projects (first lines)
   def short_description(length = 255)
-    description.gsub(/^(.{#{length}}[^\n\r]*).*$/m, '\1...').strip if description
+    ## Original Redmine code: this truncates to the CR that is more
+    ## than "length" characters from the start.
+    # description.gsub(/^(.{#{length}}[^\n\r]*).*$/m, '\1...').strip if description
+    ## That's too much for us, and also we want to omit images and the
+    ## like.  Truncate instead to the first CR that follows _any_
+    ## non-blank text, and to the next word break beyond "length"
+    ## characters if the result is still longer than that.
+    description.gsub(/![^\s]+!/, '').gsub(/^(\s*[^\n\r]*).*$/m, '\1').gsub(/^(.{#{length}}\b).*$/m, '\1 ...').strip if description
   end
 
   def css_classes