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

Instance Method Details

#move_notification_path_for(notification, params = {}) ⇒ String

TODO:

Needs any other better implementation

TODO:

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

TODO:

Needs any other better implementation

TODO:

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

TODO:

Needs any other better implementation

TODO:

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

TODO:

Needs any other better implementation

TODO:

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

TODO:

Needs any other better implementation

TODO:

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

TODO:

Needs any other better implementation

TODO:

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

TODO:

Needs any other better implementation

TODO:

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

TODO:

Needs any other better implementation

TODO:

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

TODO:

Needs any other better implementation

TODO:

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

TODO:

Needs any other better implementation

TODO:

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.

Options Hash (options):

  • :target (String, Symbol) — default: nil —

    Target type name to find template or i18n text

  • :partial (String) — default: "activity_notification/notifications/#{target}", controller.target_view_path, 'activity_notification/notifications/default' —

    Partial template name

  • :partial_root (String) — default: self.key.gsub('.', '/') —

    Root path of partial template

  • :layout (String) — default: nil —

    Layout template name

  • :layout_root (String) — default: 'layouts' —

    Root path of layout template

  • :fallback (String, Symbol) — default: nil —

    Fallback template to use when MissingTemplate is raised. Set :text to use i18n text as fallback.

See Also:



17
18
19
20
21
22
23
24
# File 'lib/activity_notification/helpers/view_helpers.rb', line 17

def render_notification(notifications, options = {})
  if notifications.is_a? ActivityNotification::Notification
    notifications.render self, options
  elsif notifications.respond_to?(:map)
    return nil if notifications.empty?
    notifications.map {|notification| notification.render self, options.dup }.join.html_safe
  end
end

#render_notification_of(target, options = {}) ⇒ String Also known as: render_notifications_of

TODO:

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.

Options Hash (options):

  • :target (String, Symbol) — default: nil —

    Target type name to find template or i18n text

  • :index_content (Symbol) — default: :with_attributes —

    Option method to load target notification index, [:simple, :unopened_simple, :opened_simple, :with_attributes, :unopened_with_attributes, :opened_with_attributes, :none] are available

  • :partial_root (String) — default: "activity_notification/notifications/#{target.to_resources_name}", 'activity_notification/notifications/default' —

    Root path of partial template

  • :notification_partial (String) — default: "activity_notification/notifications/#{target.to_resources_name}", controller.target_view_path, 'activity_notification/notifications/default' —

    Partial template name of the notification index content

  • :layout_root (String) — default: 'layouts' —

    Root path of layout template

  • :notification_layout (String) — default: nil —

    Layout template name of the notification index content

  • :fallback (String) — default: nil —

    Fallback template to use when MissingTemplate is raised. Set :text to use i18n text as fallback.

  • :partial (String) — default: 'index' —

    Partial template name of the partial index

  • :layout (String) — default: nil —

    Layout template name of the partial index

  • :limit (Integer) — default: nil —

    Limit to query for notifications

  • :reverse (Boolean) — default: false —

    If notification index will be ordered as earliest first

  • :with_group_members (Boolean) — default: false —

    If notification index will include group members

  • :filtered_by_type (String) — default: nil —

    Notifiable type for filter

  • :filtered_by_group (Object) — default: nil —

    Group instance for filter

  • :filtered_by_group_type (String) — default: nil —

    Group type for filter, valid with :filtered_by_group_id

  • :filtered_by_group_id (String) — default: nil —

    Group instance id for filter, valid with :filtered_by_group_type

  • :filtered_by_key (String) — default: nil —

    Key of the notification for filter

  • :custom_filter (Array) — default: nil —

    Custom notification filter (e.g. ["created_at >= ?", time.hour.ago])



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, options = {}
  return unless target.is_a? ActivityNotification::Target

  # Prepare content for notifications index
  notification_options = options.merge( target: target.to_resources_name,
                                        partial: options[:notification_partial],
                                        layout: options[:notification_layout] )
  index_options = options.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, options[:index_content], index_options)
  prepare_content_for(target, notification_index, notification_options)

  # Render partial index
  render_partial_index(target, options)
end

#subscribe_subscription_path_for(subscription, params = {}) ⇒ String Also known as: subscribe_path_for

TODO:

Needs any other better implementation

Returns subscribe_subscription_path for the target of specified subscription



208
209
210
# File 'lib/activity_notification/helpers/view_helpers.rb', line 208

def subscribe_subscription_path_for(subscription, params = {})
  send("subscribe_#{subscription.target.to_resource_name}_subscription_path", subscription.target, subscription, params)
end

#subscribe_subscription_url_for(subscription, params = {}) ⇒ String Also known as: subscribe_url_for

TODO:

Needs any other better implementation

Returns subscribe_subscription_url for the target of specified subscription



294
295
296
# File 'lib/activity_notification/helpers/view_helpers.rb', line 294

def subscribe_subscription_url_for(subscription, params = {})
  send("subscribe_#{subscription.target.to_resource_name}_subscription_url", subscription.target, subscription, params)
end

#subscribe_to_email_subscription_path_for(subscription, params = {}) ⇒ String Also known as: subscribe_to_email_path_for

TODO:

Needs any other better implementation

Returns subscribe_to_email_subscription_path for the target of specified subscription



230
231
232
# File 'lib/activity_notification/helpers/view_helpers.rb', line 230

def subscribe_to_email_subscription_path_for(subscription, params = {})
  send("subscribe_to_email_#{subscription.target.to_resource_name}_subscription_path", subscription.target, subscription, params)
end

#subscribe_to_email_subscription_url_for(subscription, params = {}) ⇒ String Also known as: subscribe_to_email_url_for

TODO:

Needs any other better implementation

Returns subscribe_to_email_subscription_url for the target of specified subscription



316
317
318
# File 'lib/activity_notification/helpers/view_helpers.rb', line 316

def subscribe_to_email_subscription_url_for(subscription, params = {})
  send("subscribe_to_email_#{subscription.target.to_resource_name}_subscription_url", subscription.target, subscription, params)
end

#subscribe_to_optional_target_subscription_path_for(subscription, params = {}) ⇒ String Also known as: subscribe_to_optional_target_path_for

TODO:

Needs any other better implementation

Returns subscribe_to_optional_target_subscription_path for the target of specified subscription



252
253
254
# File 'lib/activity_notification/helpers/view_helpers.rb', line 252

def subscribe_to_optional_target_subscription_path_for(subscription, params = {})
  send("subscribe_to_optional_target_#{subscription.target.to_resource_name}_subscription_path", subscription.target, subscription, params)
end

#subscribe_to_optional_target_subscription_url_for(subscription, params = {}) ⇒ String Also known as: subscribe_to_optional_target_url_for

TODO:

Needs any other better implementation

Returns subscribe_to_optional_target_subscription_url for the target of specified subscription



338
339
340
# File 'lib/activity_notification/helpers/view_helpers.rb', line 338

def subscribe_to_optional_target_subscription_url_for(subscription, params = {})
  send("subscribe_to_optional_target_#{subscription.target.to_resource_name}_subscription_url", subscription.target, subscription, params)
end

#subscription_path_for(subscription, params = {}) ⇒ String

TODO:

Needs any other better implementation

Returns subscription_path for the subscription



198
199
200
# File 'lib/activity_notification/helpers/view_helpers.rb', line 198

def subscription_path_for(subscription, params = {})
  send("#{subscription.target.to_resource_name}_subscription_path", subscription.target, subscription, params)
end

#subscription_url_for(subscription, params = {}) ⇒ String

TODO:

Needs any other better implementation

Returns subscription_url for the subscription



284
285
286
# File 'lib/activity_notification/helpers/view_helpers.rb', line 284

def subscription_url_for(subscription, params = {})
  send("#{subscription.target.to_resource_name}_subscription_url", subscription.target, subscription, params)
end

#subscriptions_path_for(target, params = {}) ⇒ String

TODO:

Needs any other better implementation

Returns subscriptions_path for the target



188
189
190
# File 'lib/activity_notification/helpers/view_helpers.rb', line 188

def subscriptions_path_for(target, params = {})
  send("#{target.to_resource_name}_subscriptions_path", target, params)
end

#subscriptions_url_for(target, params = {}) ⇒ String

TODO:

Needs any other better implementation

Returns subscriptions_url for the target



274
275
276
# File 'lib/activity_notification/helpers/view_helpers.rb', line 274

def subscriptions_url_for(target, params = {})
  send("#{target.to_resource_name}_subscriptions_url", target, params)
end

#unsubscribe_subscription_path_for(subscription, params = {}) ⇒ String Also known as: unsubscribe_path_for

TODO:

Needs any other better implementation

Returns unsubscribe_subscription_path for the target of specified subscription



219
220
221
# File 'lib/activity_notification/helpers/view_helpers.rb', line 219

def unsubscribe_subscription_path_for(subscription, params = {})
  send("unsubscribe_#{subscription.target.to_resource_name}_subscription_path", subscription.target, subscription, params)
end

#unsubscribe_subscription_url_for(subscription, params = {}) ⇒ String Also known as: unsubscribe_url_for

TODO:

Needs any other better implementation

Returns unsubscribe_subscription_url for the target of specified subscription



305
306
307
# File 'lib/activity_notification/helpers/view_helpers.rb', line 305

def unsubscribe_subscription_url_for(subscription, params = {})
  send("unsubscribe_#{subscription.target.to_resource_name}_subscription_url", subscription.target, subscription, params)
end

#unsubscribe_to_email_subscription_path_for(subscription, params = {}) ⇒ String Also known as: unsubscribe_to_email_path_for

TODO:

Needs any other better implementation

Returns unsubscribe_to_email_subscription_path for the target of specified subscription



241
242
243
# File 'lib/activity_notification/helpers/view_helpers.rb', line 241

def unsubscribe_to_email_subscription_path_for(subscription, params = {})
  send("unsubscribe_to_email_#{subscription.target.to_resource_name}_subscription_path", subscription.target, subscription, params)
end

#unsubscribe_to_email_subscription_url_for(subscription, params = {}) ⇒ String Also known as: unsubscribe_to_email_url_for

TODO:

Needs any other better implementation

Returns unsubscribe_to_email_subscription_url for the target of specified subscription



327
328
329
# File 'lib/activity_notification/helpers/view_helpers.rb', line 327

def unsubscribe_to_email_subscription_url_for(subscription, params = {})
  send("unsubscribe_to_email_#{subscription.target.to_resource_name}_subscription_url", subscription.target, subscription, params)
end

#unsubscribe_to_optional_target_subscription_path_for(subscription, params = {}) ⇒ String Also known as: unsubscribe_to_optional_target_path_for

TODO:

Needs any other better implementation

Returns unsubscribe_to_optional_target_subscription_path for the target of specified subscription



263
264
265
# File 'lib/activity_notification/helpers/view_helpers.rb', line 263

def unsubscribe_to_optional_target_subscription_path_for(subscription, params = {})
  send("unsubscribe_to_optional_target_#{subscription.target.to_resource_name}_subscription_path", subscription.target, subscription, params)
end

#unsubscribe_to_optional_target_subscription_url_for(subscription, params = {}) ⇒ String Also known as: unsubscribe_to_optional_target_url_for

TODO:

Needs any other better implementation

Returns unsubscribe_to_optional_target_subscription_url for the target of specified subscription



349
350
351
# File 'lib/activity_notification/helpers/view_helpers.rb', line 349

def unsubscribe_to_optional_target_subscription_url_for(subscription, params = {})
  send("unsubscribe_to_optional_target_#{subscription.target.to_resource_name}_subscription_url", subscription.target, subscription, params)
end