Mercurial > hg > soundsoftware-site
diff app/helpers/.svn/text-base/application_helper.rb.svn-base @ 22:40f7cfd4df19
* Update to SVN trunk rev 4173
author | Chris Cannam <chris.cannam@soundsoftware.ac.uk> |
---|---|
date | Fri, 24 Sep 2010 14:06:04 +0100 |
parents | 1d32c0a0efbf |
children | 94944d00e43c |
line wrap: on
line diff
--- a/app/helpers/.svn/text-base/application_helper.rb.svn-base Wed Aug 25 16:30:24 2010 +0100 +++ b/app/helpers/.svn/text-base/application_helper.rb.svn-base Fri Sep 24 14:06:04 2010 +0100 @@ -32,8 +32,27 @@ end # Display a link if user is authorized + # + # @param [String] name Anchor text (passed to link_to) + # @param [Hash, String] options Hash params or url for the link target (passed to link_to). + # This will checked by authorize_for to see if the user is authorized + # @param [optional, Hash] html_options Options passed to link_to + # @param [optional, Hash] parameters_for_method_reference Extra parameters for link_to def link_to_if_authorized(name, options = {}, html_options = nil, *parameters_for_method_reference) - link_to(name, options, html_options, *parameters_for_method_reference) if authorize_for(options[:controller] || params[:controller], options[:action]) + if options.is_a?(String) + begin + route = ActionController::Routing::Routes.recognize_path(options.gsub(/\?.*/,''), :method => options[:method] || :get) + link_controller = route[:controller] + link_action = route[:action] + rescue ActionController::RoutingError # Parse failed, not a route + link_controller, link_action = nil, nil + end + else + link_controller = options[:controller] || params[:controller] + link_action = options[:action] + end + + link_to(name, options, html_options, *parameters_for_method_reference) if authorize_for(link_controller, link_action) end # Display a link to remote if user is authorized @@ -102,6 +121,11 @@ link_to(text, {:controller => 'repositories', :action => 'revision', :id => project, :rev => revision}, :title => l(:label_revision_id, revision)) end + + def link_to_project(project, options={}) + options[:class] ||= 'project' + link_to(h(project), {:controller => 'projects', :action => 'show', :id => project}, :class => options[:class]) + end # Generates a link to a project if active # Examples: @@ -302,7 +326,7 @@ def time_tag(time) text = distance_of_time_in_words(Time.now, time) if @project - link_to(text, {:controller => 'projects', :action => 'activity', :id => @project, :from => time.to_date}, :title => format_time(time)) + link_to(text, {:controller => 'activities', :action => 'index', :id => @project, :from => time.to_date}, :title => format_time(time)) else content_tag('acronym', text, :title => format_time(time)) end @@ -805,7 +829,7 @@ # +user+ can be a User or a string that will be scanned for an email address (eg. 'joe <joe@foo.bar>') def avatar(user, options = { }) if Setting.gravatar_enabled? - options.merge!({:ssl => Setting.protocol == 'https', :default => Setting.gravatar_default}) + options.merge!({:ssl => (defined?(request) && request.ssl?), :default => Setting.gravatar_default}) email = nil if user.respond_to?(:mail) email = user.mail @@ -813,6 +837,8 @@ email = $1 end return gravatar(email.to_s.downcase, options) unless email.blank? rescue nil + else + '' end end