comparison 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
comparison
equal deleted inserted replaced
14:1d32c0a0efbf 22:40f7cfd4df19
30 def authorize_for(controller, action) 30 def authorize_for(controller, action)
31 User.current.allowed_to?({:controller => controller, :action => action}, @project) 31 User.current.allowed_to?({:controller => controller, :action => action}, @project)
32 end 32 end
33 33
34 # Display a link if user is authorized 34 # Display a link if user is authorized
35 #
36 # @param [String] name Anchor text (passed to link_to)
37 # @param [Hash, String] options Hash params or url for the link target (passed to link_to).
38 # This will checked by authorize_for to see if the user is authorized
39 # @param [optional, Hash] html_options Options passed to link_to
40 # @param [optional, Hash] parameters_for_method_reference Extra parameters for link_to
35 def link_to_if_authorized(name, options = {}, html_options = nil, *parameters_for_method_reference) 41 def link_to_if_authorized(name, options = {}, html_options = nil, *parameters_for_method_reference)
36 link_to(name, options, html_options, *parameters_for_method_reference) if authorize_for(options[:controller] || params[:controller], options[:action]) 42 if options.is_a?(String)
43 begin
44 route = ActionController::Routing::Routes.recognize_path(options.gsub(/\?.*/,''), :method => options[:method] || :get)
45 link_controller = route[:controller]
46 link_action = route[:action]
47 rescue ActionController::RoutingError # Parse failed, not a route
48 link_controller, link_action = nil, nil
49 end
50 else
51 link_controller = options[:controller] || params[:controller]
52 link_action = options[:action]
53 end
54
55 link_to(name, options, html_options, *parameters_for_method_reference) if authorize_for(link_controller, link_action)
37 end 56 end
38 57
39 # Display a link to remote if user is authorized 58 # Display a link to remote if user is authorized
40 def link_to_remote_if_authorized(name, options = {}, html_options = nil) 59 def link_to_remote_if_authorized(name, options = {}, html_options = nil)
41 url = options[:url] || {} 60 url = options[:url] || {}
99 # * :text - Link text (default to the formatted revision) 118 # * :text - Link text (default to the formatted revision)
100 def link_to_revision(revision, project, options={}) 119 def link_to_revision(revision, project, options={})
101 text = options.delete(:text) || format_revision(revision) 120 text = options.delete(:text) || format_revision(revision)
102 121
103 link_to(text, {:controller => 'repositories', :action => 'revision', :id => project, :rev => revision}, :title => l(:label_revision_id, revision)) 122 link_to(text, {:controller => 'repositories', :action => 'revision', :id => project, :rev => revision}, :title => l(:label_revision_id, revision))
123 end
124
125 def link_to_project(project, options={})
126 options[:class] ||= 'project'
127 link_to(h(project), {:controller => 'projects', :action => 'show', :id => project}, :class => options[:class])
104 end 128 end
105 129
106 # Generates a link to a project if active 130 # Generates a link to a project if active
107 # Examples: 131 # Examples:
108 # 132 #
300 end 324 end
301 325
302 def time_tag(time) 326 def time_tag(time)
303 text = distance_of_time_in_words(Time.now, time) 327 text = distance_of_time_in_words(Time.now, time)
304 if @project 328 if @project
305 link_to(text, {:controller => 'projects', :action => 'activity', :id => @project, :from => time.to_date}, :title => format_time(time)) 329 link_to(text, {:controller => 'activities', :action => 'index', :id => @project, :from => time.to_date}, :title => format_time(time))
306 else 330 else
307 content_tag('acronym', text, :title => format_time(time)) 331 content_tag('acronym', text, :title => format_time(time))
308 end 332 end
309 end 333 end
310 334
803 827
804 # Returns the avatar image tag for the given +user+ if avatars are enabled 828 # Returns the avatar image tag for the given +user+ if avatars are enabled
805 # +user+ can be a User or a string that will be scanned for an email address (eg. 'joe <joe@foo.bar>') 829 # +user+ can be a User or a string that will be scanned for an email address (eg. 'joe <joe@foo.bar>')
806 def avatar(user, options = { }) 830 def avatar(user, options = { })
807 if Setting.gravatar_enabled? 831 if Setting.gravatar_enabled?
808 options.merge!({:ssl => Setting.protocol == 'https', :default => Setting.gravatar_default}) 832 options.merge!({:ssl => (defined?(request) && request.ssl?), :default => Setting.gravatar_default})
809 email = nil 833 email = nil
810 if user.respond_to?(:mail) 834 if user.respond_to?(:mail)
811 email = user.mail 835 email = user.mail
812 elsif user.to_s =~ %r{<(.+?)>} 836 elsif user.to_s =~ %r{<(.+?)>}
813 email = $1 837 email = $1
814 end 838 end
815 return gravatar(email.to_s.downcase, options) unless email.blank? rescue nil 839 return gravatar(email.to_s.downcase, options) unless email.blank? rescue nil
840 else
841 ''
816 end 842 end
817 end 843 end
818 844
819 def favicon 845 def favicon
820 "<link rel='shortcut icon' href='#{image_path('/favicon.ico')}' />" 846 "<link rel='shortcut icon' href='#{image_path('/favicon.ico')}' />"