Mercurial > hg > soundsoftware-site
changeset 335:7acd282bee3c cannam-pre-20110113-merge
Introduce render_project_short_description into projects helper; use it in welcome page (latest projects) as well as project lists, to avoid text formatting appearing in these lists
author | Chris Cannam <chris.cannam@soundsoftware.ac.uk> |
---|---|
date | Wed, 30 Mar 2011 11:05:16 +0100 |
parents | e665cc1fdf07 |
children | 7f5bd8f2d79b d67a7d67b159 |
files | app/controllers/welcome_controller.rb app/helpers/projects_helper.rb app/models/project.rb app/views/welcome/index.rhtml public/stylesheets/application.css |
diffstat | 5 files changed, 31 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/app/controllers/welcome_controller.rb Tue Mar 29 18:06:44 2011 +0100 +++ b/app/controllers/welcome_controller.rb Wed Mar 30 11:05:16 2011 +0100 @@ -18,6 +18,9 @@ class WelcomeController < ApplicationController caches_action :robots + include ProjectsHelper + helper :projects + def index @news = News.latest User.current @projects = Project.latest User.current
--- a/app/helpers/projects_helper.rb Tue Mar 29 18:06:44 2011 +0100 +++ b/app/helpers/projects_helper.rb Wed Mar 30 11:05:16 2011 +0100 @@ -48,6 +48,16 @@ options << project_tree_options_for_select(project.allowed_parents.compact, :selected => selected) content_tag('select', options, :name => 'project[parent_id]', :id => 'project_parent_id') end + + def render_project_short_description(project) + s = '' + if (project.short_description) + s << "<div class='description'>" + s << textilizable(project.short_description, :project => project).gsub(/<[^>]+>/, '') + s << "</div>" + end + s + end # Renders a tree of projects as a nested set of unordered lists # The given collection may be a subset of the whole project tree @@ -73,7 +83,7 @@ classes = (ancestors.empty? ? 'root' : 'child') s << "<li class='#{classes}'><div class='#{classes}'>" + link_to_project(project, {}, :class => "project #{User.current.member_of?(project) ? 'my-project' : nil}") - s << "<div class='wiki description'>#{textilizable(project.short_description, :project => project)}</div>" unless project.description.blank? + s << render_project_short_description(project) s << "</div>\n" ancestors << project end @@ -127,8 +137,7 @@ else s << " <span class='private'>" << l("field_is_private") << "</span>" end - desc = textilizable(project.short_description, :project => project).gsub(/<[^>]+>/, '') - s << "<div class='wiki description'>#{desc}</div>" unless project.description.blank? + s << render_project_short_description(project) s << "</div>\n" ancestors << project end @@ -199,11 +208,7 @@ s << " no_description" if project.description.blank? s << "'>" << link_to_project(project, {}, :class => "project #{User.current.member_of?(project) ? 'my-project' : nil}"); s << "</div>" - unless project.description.blank? - s << "<div class='wiki description'>" - s << textilizable(project.short_description, :project => project).gsub(/<[^>]+>/, '') - s << "</div>" - end + s << render_project_short_description(project) s << "<td class='managers' align=top>"
--- a/app/models/project.rb Tue Mar 29 18:06:44 2011 +0100 +++ b/app/models/project.rb Wed Mar 30 11:05:16 2011 +0100 @@ -423,13 +423,20 @@ # Returns a short description of the projects (first lines) def short_description(length = 255) + + ## The short description is used in lists, e.g. Latest projects, + ## My projects etc. It should be no more than a line or two with + ## no text formatting. + ## 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. + + ## That can leave too much text 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
--- a/app/views/welcome/index.rhtml Tue Mar 29 18:06:44 2011 +0100 +++ b/app/views/welcome/index.rhtml Wed Mar 30 11:05:16 2011 +0100 @@ -33,9 +33,9 @@ <ul> <% for project in @projects %> <% @project = project %> - <li> + <li class="latest"> <%= link_to_project project %> (<%= format_time(project.created_on) %>) - <%= textilizable project.short_description, :project => project %> + <%= render_project_short_description project %> </li> <% end %> <% @project = nil %>
--- a/public/stylesheets/application.css Tue Mar 29 18:06:44 2011 +0100 +++ b/public/stylesheets/application.css Wed Mar 30 11:05:16 2011 +0100 @@ -352,6 +352,8 @@ ul.projects div.root a.project { /* font-family: "Trebuchet MS", Verdana, sans-serif; */ font-weight: bold; font-size: 16px; margin: 0 0 10px 0; } /* .my-project { padding-left: 18px; background: url(../images/fav.png) no-repeat 0 50%; } */ +li.latest { margin-bottom: 0.5em; } + #tracker_project_ids ul { margin: 0; padding-left: 1em; } #tracker_project_ids li { list-style-type:none; }