Class: Decidim::Events::SimpleEvent
- Includes:
- ComponentPathHelper, EmailEvent, NotificationEvent, OrganizationHelper
- Defined in:
- lib/decidim/events/simple_event.rb
Overview
Extends the BaseEvent to add common components to most events so you do not need to write each time the same code.
The only convention you need to keep in mind is that the event name will be used as the i18n scope to search for the keys.
Direct Known Subclasses
Amendable::AmendmentBaseEvent, ChangeNicknameEvent, DemotedMembershipEvent, Gamification::BaseEvent, InvitedToGroupEvent, JoinRequestAcceptedEvent, JoinRequestCreatedEvent, JoinRequestRejectedEvent, ProfileUpdatedEvent, PromotedToAdminEvent, RemovedFromGroupEvent, ResourceEndorsedEvent, UserGroupAdminEvent, WelcomeNotificationEvent
Class Method Summary collapse
-
.i18n_attributes(*attributes) ⇒ Object
Public: A method to add values to pass as interpolations to the I18n.t method.
Instance Method Summary collapse
- #email_intro ⇒ Object
- #email_outro ⇒ Object
- #email_subject ⇒ Object
-
#event_has_roles? ⇒ Boolean
Public: Whether the event differentiates between different user roles.
-
#i18n_options ⇒ Object
Public: The Hash of options to pass to the I18.t method.
-
#i18n_scope ⇒ Object
Public: The String to use as scope to search for the keys when using I18n.t.
- #notification_title ⇒ Object
-
#participatory_space_url ⇒ Object
Caches the URL for the resource’s participatory space.
-
#resource_path ⇒ Object
Caches the path for the given resource when it is a Decidim::Component.
-
#resource_text ⇒ Object
Caches the text to render as a quote in the email.
-
#resource_url ⇒ Object
Caches the URL for the given resource when it is a Decidim::Component.
Methods included from OrganizationHelper
#current_organization_name, #organization_colors, #organization_description_label, #organization_name
Methods included from TranslatableAttributes
Methods included from ComponentPathHelper
#can_be_managed?, #main_component_path, #main_component_url, #manage_component_path
Methods inherited from BaseEvent
#action_cell, #action_data, #content_in_same_language?, #hidden_resource?, #initialize, #organization, #perform_translation?, #resource_locator, #resource_title, #safe_resource_text, #safe_resource_translated_text, #translation_missing?, type
Methods included from SanitizeHelper
#decidim_escape_translated, #decidim_html_escape, #decidim_sanitize, #decidim_sanitize_admin, #decidim_sanitize_editor, #decidim_sanitize_editor_admin, #decidim_sanitize_newsletter, #decidim_sanitize_translated, #decidim_url_escape, included
Constructor Details
This class inherits a constructor from Decidim::Events::BaseEvent
Class Method Details
.i18n_attributes(*attributes) ⇒ Object
Public: A method to add values to pass as interpolations to the I18n.t method.
By default the resource_path, resource_title and resource_url are already included.
attribute - A Symbol of the method name (and interpolation value) to add.
Example:
class MyEvent < Decidim::Events::SimpleEvent
i18n_attributes :participatory_space_title
end
32 33 34 |
# File 'lib/decidim/events/simple_event.rb', line 32 def self.i18n_attributes(*attributes) self.i18n_interpolations += Array(attributes) end |
Instance Method Details
#email_intro ⇒ Object
40 41 42 |
# File 'lib/decidim/events/simple_event.rb', line 40 def email_intro I18n.t("email_intro", **).html_safe end |
#email_outro ⇒ Object
44 45 46 |
# File 'lib/decidim/events/simple_event.rb', line 44 def email_outro I18n.t("email_outro", **).html_safe end |
#email_subject ⇒ Object
36 37 38 |
# File 'lib/decidim/events/simple_event.rb', line 36 def email_subject I18n.t("email_subject", **).html_safe end |
#event_has_roles? ⇒ Boolean
Public: Whether the event differentiates between different user roles. This will change the default i18n scope.
Returns a boolean.
67 68 69 |
# File 'lib/decidim/events/simple_event.rb', line 67 def event_has_roles? false end |
#i18n_options ⇒ Object
Public: The Hash of options to pass to the I18.t method.
72 73 74 |
# File 'lib/decidim/events/simple_event.rb', line 72 def .merge(event_interpolations) end |
#i18n_scope ⇒ Object
Public: The String to use as scope to search for the keys when using I18n.t
By default is the same value as the event name. If the event has roles, then the role is appended to the i18n scope.
57 58 59 60 61 |
# File 'lib/decidim/events/simple_event.rb', line 57 def i18n_scope return event_name if user_role.blank? || !event_has_roles? "#{event_name}.#{user_role}" end |
#notification_title ⇒ Object
48 49 50 |
# File 'lib/decidim/events/simple_event.rb', line 48 def notification_title I18n.t("notification_title", **).html_safe end |
#participatory_space_url ⇒ Object
Caches the URL for the resource’s participatory space.
91 92 93 94 95 |
# File 'lib/decidim/events/simple_event.rb', line 91 def participatory_space_url return unless participatory_space @participatory_space_url ||= ResourceLocatorPresenter.new(participatory_space).url end |
#resource_path ⇒ Object
Caches the path for the given resource when it is a Decidim::Component.
77 78 79 80 81 |
# File 'lib/decidim/events/simple_event.rb', line 77 def resource_path return super unless resource.is_a?(Decidim::Component) @resource_path ||= main_component_path(resource) end |
#resource_text ⇒ Object
Caches the text to render as a quote in the email. It will appear, if present, after the ‘intro` section. This method is intended to be overwritten by each event class.
Returns a string.
102 103 104 |
# File 'lib/decidim/events/simple_event.rb', line 102 def resource_text nil end |