Module: NotificationsHelper
Instance Method Summary
collapse
#post_iframe_url, #post_page_title
#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
107
108
109
110
111
112
113
|
# File 'app/helpers/notifications_helper.rb', line 107
def display_year?(year, date)
unless year
Date.current.year != the_year(date)
else
year != the_year(date)
end
end
|
#locale_date(date) ⇒ Object
103
104
105
|
# File 'app/helpers/notifications_helper.rb', line 103
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
87
88
89
|
# File 'app/helpers/notifications_helper.rb', line 87
def notification_message_for(note)
object_link(note, notification_people_link(note))
end
|
#notification_people_link(note, people = nil) ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'app/helpers/notifications_helper.rb', line 64
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
|
#object_link(note, actors_html) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'app/helpers/notifications_helper.rb', line 7
def object_link(note, actors_html)
target_type = note.
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::LikedComment)
opts.merge!((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
60
61
62
|
# File 'app/helpers/notifications_helper.rb', line 60
def opts_for_birthday(note)
{date: I18n.l(note.created_at, format: I18n.t("date.formats.fullmonth_day"))}
end
|
42
43
44
45
46
47
48
49
|
# File 'app/helpers/notifications_helper.rb', line 42
def ()
{
comment_link: link_to(.message.title,
post_path(.post, anchor: .guid),
data: {ref: .id},
class: "hard_object_link")
}
end
|
#opts_for_mentioned(mentioned) ⇒ Object
51
52
53
54
55
56
57
58
|
# File 'app/helpers/notifications_helper.rb', line 51
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
32
33
34
35
36
37
38
39
40
|
# File 'app/helpers/notifications_helper.rb', line 32
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")
}
end
|
#the_day(date) ⇒ Object
91
92
93
|
# File 'app/helpers/notifications_helper.rb', line 91
def the_day(date)
date.split('-')[2].to_i
end
|
#the_month(date) ⇒ Object
95
96
97
|
# File 'app/helpers/notifications_helper.rb', line 95
def the_month(date)
I18n.l(Date.strptime(date, '%Y-%m-%d'), :format => '%B')
end
|
#the_year(date) ⇒ Object
99
100
101
|
# File 'app/helpers/notifications_helper.rb', line 99
def the_year(date)
date.split('-')[0].to_i
end
|
#translation(target_type, **kwargs) ⇒ Object
28
29
30
|
# File 'app/helpers/notifications_helper.rb', line 28
def translation(target_type, **kwargs)
t(target_type, **kwargs).html_safe end
|