Module: ActivityNotification::ViewHelpers
- Defined in:
- lib/activity_notification/helpers/view_helpers.rb
Overview
Provides a shortcut from views to the rendering method. Module extending ActionView::Base and adding render_notification helper.
Instance Method Summary collapse
-
#move_notification_path_for(notification, params = {}) ⇒ String
Returns move_notification_path for the target of specified notification.
-
#move_notification_url_for(notification, params = {}) ⇒ String
Returns move_notification_url for the target of specified notification.
-
#notification_path_for(notification, params = {}) ⇒ String
Returns notification_path for the notification.
-
#notification_url_for(notification, params = {}) ⇒ String
Returns notification_url for the target of specified notification.
-
#notifications_path_for(target, params = {}) ⇒ String
Returns notifications_path for the target.
-
#notifications_url_for(target, params = {}) ⇒ String
Returns notifications_url for the target.
-
#open_all_notifications_path_for(target, params = {}) ⇒ String
Returns open_all_notifications_path for the target.
-
#open_all_notifications_url_for(target, params = {}) ⇒ String
Returns open_all_notifications_url for the target of specified notification.
-
#open_notification_path_for(notification, params = {}) ⇒ String
Returns open_notification_path for the target of specified notification.
-
#open_notification_url_for(notification, params = {}) ⇒ String
Returns open_notification_url for the target of specified notification.
-
#render_notification(notifications, options = {}) ⇒ String
(also: #render_notifications)
View helper for rendering an notification, calls Renderable#render internally.
-
#render_notification_of(target, options = {}) ⇒ String
(also: #render_notifications_of)
View helper for rendering on notifications of the target to embedded partial template.
Instance Method Details
#move_notification_path_for(notification, params = {}) ⇒ String
Needs any other better implementation
Must handle devise namespace
Returns move_notification_path for the target of specified notification
101 102 103 |
# File 'lib/activity_notification/helpers/view_helpers.rb', line 101 def move_notification_path_for(notification, params = {}) send("move_#{notification.target.to_resource_name}_notification_path", notification.target, notification, params) end |
#move_notification_url_for(notification, params = {}) ⇒ String
Needs any other better implementation
Must handle devise namespace
Returns move_notification_url for the target of specified notification
156 157 158 |
# File 'lib/activity_notification/helpers/view_helpers.rb', line 156 def move_notification_url_for(notification, params = {}) send("move_#{notification.target.to_resource_name}_notification_url", notification.target, notification, params) end |
#notification_path_for(notification, params = {}) ⇒ String
Needs any other better implementation
Must handle devise namespace
Returns notification_path for the notification
90 91 92 |
# File 'lib/activity_notification/helpers/view_helpers.rb', line 90 def notification_path_for(notification, params = {}) send("#{notification.target.to_resource_name}_notification_path", notification.target, notification, params) end |
#notification_url_for(notification, params = {}) ⇒ String
Needs any other better implementation
Must handle devise namespace
Returns notification_url for the target of specified notification
145 146 147 |
# File 'lib/activity_notification/helpers/view_helpers.rb', line 145 def notification_url_for(notification, params = {}) send("#{notification.target.to_resource_name}_notification_url", notification.target, notification, params) end |
#notifications_path_for(target, params = {}) ⇒ String
Needs any other better implementation
Must handle devise namespace
Returns notifications_path for the target
79 80 81 |
# File 'lib/activity_notification/helpers/view_helpers.rb', line 79 def notifications_path_for(target, params = {}) send("#{target.to_resource_name}_notifications_path", target, params) end |
#notifications_url_for(target, params = {}) ⇒ String
Needs any other better implementation
Must handle devise namespace
Returns notifications_url for the target
134 135 136 |
# File 'lib/activity_notification/helpers/view_helpers.rb', line 134 def notifications_url_for(target, params = {}) send("#{target.to_resource_name}_notifications_url", target, params) end |
#open_all_notifications_path_for(target, params = {}) ⇒ String
Needs any other better implementation
Must handle devise namespace
Returns open_all_notifications_path for the target
123 124 125 |
# File 'lib/activity_notification/helpers/view_helpers.rb', line 123 def open_all_notifications_path_for(target, params = {}) send("open_all_#{target.to_resource_name}_notifications_path", target, params) end |
#open_all_notifications_url_for(target, params = {}) ⇒ String
Needs any other better implementation
Must handle devise namespace
Returns open_all_notifications_url for the target of specified notification
178 179 180 |
# File 'lib/activity_notification/helpers/view_helpers.rb', line 178 def open_all_notifications_url_for(target, params = {}) send("open_all_#{target.to_resource_name}_notifications_url", target, params) end |
#open_notification_path_for(notification, params = {}) ⇒ String
Needs any other better implementation
Must handle devise namespace
Returns open_notification_path for the target of specified notification
112 113 114 |
# File 'lib/activity_notification/helpers/view_helpers.rb', line 112 def open_notification_path_for(notification, params = {}) send("open_#{notification.target.to_resource_name}_notification_path", notification.target, notification, params) end |
#open_notification_url_for(notification, params = {}) ⇒ String
Needs any other better implementation
Must handle devise namespace
Returns open_notification_url for the target of specified notification
167 168 169 |
# File 'lib/activity_notification/helpers/view_helpers.rb', line 167 def open_notification_url_for(notification, params = {}) send("open_#{notification.target.to_resource_name}_notification_url", notification.target, notification, params) end |
#render_notification(notifications, options = {}) ⇒ String Also known as: render_notifications
View helper for rendering an notification, calls Renderable#render internally.
17 18 19 20 21 22 23 24 |
# File 'lib/activity_notification/helpers/view_helpers.rb', line 17 def render_notification(notifications, = {}) if notifications.is_a? ActivityNotification::Notification notifications.render self, elsif notifications.respond_to?(:map) return nil if notifications.empty? notifications.map {|notification| notification.render self, .dup }.join.html_safe end end |
#render_notification_of(target, options = {}) ⇒ String Also known as: render_notifications_of
Show examples
View helper for rendering on notifications of the target to embedded partial template. It calls Renderable#render to prepare view as ‘content_for :index_content` and render partial index calling `yield :index_content` internally. For example, this method can be used for notification index as dropdown in common header.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/activity_notification/helpers/view_helpers.rb', line 54 def render_notification_of target, = {} return unless target.is_a? ActivityNotification::Target # Prepare content for notifications index = .merge( target: target.to_resources_name, partial: [:notification_partial], layout: [:notification_layout] ) = .slice( :limit, :reverse, :with_group_members, :filtered_by_group, :filtered_by_group_type, :filtered_by_group_id, :filtered_by_type, :filtered_by_key, :custom_filter ) notification_index = load_notification_index(target, [:index_content], ) prepare_content_for(target, notification_index, ) # Render partial index render_partial_index(target, ) end |