Module: NotificationsHelper

Includes:
PeopleHelper, PostsHelper
Defined in:
app/helpers/notifications_helper.rb

Instance Method Summary collapse

Methods included from PostsHelper

#post_iframe_url, #post_page_title

Methods included from PeopleHelper

#birthday_format, #local_or_remote_person_path, #person_image_link, #person_image_tag, #person_link, #search_header

Instance Method Details

#display_year?(year, date) ⇒ Boolean

Returns:

  • (Boolean)

96
97
98
99
100
101
102
# File 'app/helpers/notifications_helper.rb', line 96

def display_year?(year, date)
  unless year
    Date.current.year != the_year(date)
  else
    year != the_year(date)
  end
end

#locale_date(date) ⇒ Object


92
93
94
# File 'app/helpers/notifications_helper.rb', line 92

def locale_date(date)
  I18n.l(Date.strptime(date, '%Y-%m-%d'), :format => I18n.t('date.formats.fullmonth_day'))
end

#notification_message_for(note) ⇒ Object


76
77
78
# File 'app/helpers/notifications_helper.rb', line 76

def notification_message_for(note)
  object_link(note, notification_people_link(note))
end

53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'app/helpers/notifications_helper.rb', line 53

def notification_people_link(note, people=nil)
  actors =people || note.actors
  number_of_actors = actors.size
  sentence_translations = {:two_words_connector => " #{t('notifications.index.and')} ", :last_word_connector => ", #{t('notifications.index.and')} " }
  actor_links = actors.collect{ |person|
    person_link(person, :class => 'hovercardable')
  }

  if number_of_actors < 4
    message = actor_links.to_sentence(sentence_translations)
  else
    first, second, third, *others = actor_links
    others_sentence = others.to_sentence(sentence_translations)
    if others.count == 1
      others_sentence = " #{t('notifications.index.and')} " + others_sentence
    end
    message = "#{first}, #{second}, #{third},"
    message += "<a class='more' href='#'> #{t('notifications.index.and_others', :count =>(number_of_actors - 3))}</a>"
    message += "<span class='hidden'> #{others_sentence} </span>"
  end
  message.html_safe
end

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/helpers/notifications_helper.rb', line 7

def object_link(note, actors_html)
  target_type = note.popup_translation_key
  opts = {actors: actors_html, count: note.actors.size}

  if note.respond_to?(:linked_object)
    if note.linked_object.nil? && note.respond_to?(:deleted_translation_key)
      target_type = note.deleted_translation_key
    elsif note.is_a?(Notifications::Mentioned)
      opts.merge!(opts_for_mentioned(note.linked_object))
    elsif %w(Notifications::CommentOnPost Notifications::AlsoCommented Notifications::Reshared Notifications::Liked)
          .include?(note.type)
      opts.merge!(opts_for_post(note.linked_object))
    elsif note.is_a?(Notifications::ContactsBirthday)
      opts.merge!(opts_for_birthday(note))
    end
  end
  translation(target_type, opts)
end

#opts_for_birthday(note) ⇒ Object


49
50
51
# File 'app/helpers/notifications_helper.rb', line 49

def opts_for_birthday(note)
  {date: I18n.l(note.created_at, format: I18n.t("date.formats.fullmonth_day"))}
end

#opts_for_mentioned(mentioned) ⇒ Object


40
41
42
43
44
45
46
47
# File 'app/helpers/notifications_helper.rb', line 40

def opts_for_mentioned(mentioned)
  post = mentioned.instance_of?(Comment) ? mentioned.parent : mentioned
  {
    post_link: link_to(post_page_title(post), post_path(post)).html_safe
  }.tap {|opts|
    opts[:comment_path] = post_path(post, anchor: mentioned.guid).html_safe if mentioned.instance_of?(Comment)
  }
end

#opts_for_post(post) ⇒ Object


30
31
32
33
34
35
36
37
38
# File 'app/helpers/notifications_helper.rb', line 30

def opts_for_post(post)
  {
    post_author: html_escape(post.author_name),
    post_link:   link_to(post_page_title(post),
                         post_path(post),
                         data:  {ref: post.id},
                         class: "hard_object_link").html_safe
  }
end

#the_day(date) ⇒ Object


80
81
82
# File 'app/helpers/notifications_helper.rb', line 80

def the_day(date)
  date.split('-')[2].to_i
end

#the_month(date) ⇒ Object


84
85
86
# File 'app/helpers/notifications_helper.rb', line 84

def the_month(date)
  I18n.l(Date.strptime(date, '%Y-%m-%d'), :format => '%B')
end

#the_year(date) ⇒ Object


88
89
90
# File 'app/helpers/notifications_helper.rb', line 88

def the_year(date)
  date.split('-')[0].to_i
end

#translation(target_type, opts = {}) ⇒ Object


26
27
28
# File 'app/helpers/notifications_helper.rb', line 26

def translation(target_type, opts = {})
  t("#{target_type}", opts).html_safe
end