Module: NotificationsHelper

Includes:
ActionView::Helpers::TextHelper, SubjectsHelper
Defined in:
app/helpers/notifications_helper.rb

Constant Summary

Constants included from SubjectsHelper

SubjectsHelper::NAME_MAX_LENGHT

Instance Method Summary collapse

Methods included from SubjectsHelper

#link_name, #truncate_name

Instance Method Details

#decode_notification(notification_text, activity) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/helpers/notifications_helper.rb', line 4

def decode_notification notification_text, activity
  return if activity.nil?
  notification_text = notification_text.gsub(/\%\{sender\}/, link_to(truncate_name(activity.sender.name), 
                                                                    url_for(:controller=> activity.sender.subject.class.to_s.downcase.pluralize, 
                                                                            :action=> :show, :id=> activity.sender.subject.slug, :only_path => false)))   
  notification_text = notification_text.gsub(/\%\{confirm\}/,link_to(t('notification.confirm'),edit_contact_url(activity.receiver.contact_to!(activity.sender))))
  notification_text = notification_text.gsub(/\%\{look\}/,link_to(t('notification.look'),
                                                                    url_for(:controller=> activity.sender.subject.class.to_s.downcase.pluralize, 
                                                                            :action=> :show, :id=> activity.sender.subject.slug, :only_path => false)))
  notification_text = notification_text.gsub(/\%\{sender.name\}/,truncate_name(activity.sender.name))
  
  if activity.direct_object.present?
    object = activity.direct_object
    object = object.subject if object.is_a? Actor
    notification_text=notification_text.gsub(/\%\{object\}/,link_to(object.class.to_s.downcase,
                                                                    url_for(:controller=> object.class.to_s.downcase.pluralize, :action=> :show, 
                                                                            :id=> object.id, :only_path => false)))
    notification_text=notification_text.gsub(/\%\{object.name\}/,object.class.to_s.downcase)
    notification_text=notification_text.gsub(/\%\{object.text\}/,link_to(object.text.truncate(100, :separator =>' '), 
                                                                        url_for(:controller=> object.class.to_s.downcase.pluralize, :action=> :show, 
                                                                                :id=> object.id, :only_path => false))) if object.respond_to? :text 
    #notification_text=notification_text.gsub(/\%\{object.image\}/,thumb_for(object)) if SocialStream.activity_forms.include? :document and object.is_a? Document
    
  else
    notification_text=notification_text.gsub(/\%\{object\}/,"nilclass")
    notification_text=notification_text.gsub(/\%\{object.name\}/,"nilclass")
  end

  notification_text
end