Class: Decidim::Events::SimpleEvent
- Includes:
- ComponentPathHelper, EmailEvent, NotificationEvent
- Defined in:
- lib/decidim/events/simple_event.rb
Overview
Extends the BaseEvent to add common components to most events so you don’t 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
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
-
#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’s a Decidim::Component.
-
#resource_url ⇒ Object
Caches the URL for the given resource when it’s a Decidim::Component.
Methods included from ComponentPathHelper
#main_component_path, #main_component_url, #manage_component_path
Methods inherited from BaseEvent
#initialize, #notifiable?, #resource_locator, type
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
29 30 31 |
# File 'lib/decidim/events/simple_event.rb', line 29 def self.i18n_attributes(*attributes) self.i18n_interpolations += Array(attributes) end |
Instance Method Details
#email_intro ⇒ Object
37 38 39 |
# File 'lib/decidim/events/simple_event.rb', line 37 def email_intro I18n.t("email_intro", ).html_safe end |
#email_outro ⇒ Object
41 42 43 |
# File 'lib/decidim/events/simple_event.rb', line 41 def email_outro I18n.t("email_outro", ).html_safe end |
#email_subject ⇒ Object
33 34 35 |
# File 'lib/decidim/events/simple_event.rb', line 33 def email_subject I18n.t("email_subject", ).html_safe end |
#i18n_options ⇒ Object
Public: The Hash of options to pass to the I18.t method.
58 59 60 |
# File 'lib/decidim/events/simple_event.rb', line 58 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.
53 54 55 |
# File 'lib/decidim/events/simple_event.rb', line 53 def i18n_scope event_name end |
#notification_title ⇒ Object
45 46 47 |
# File 'lib/decidim/events/simple_event.rb', line 45 def notification_title I18n.t("notification_title", ).html_safe end |
#participatory_space_url ⇒ Object
Caches the URL for the resource’s participatory space.
75 76 77 78 79 |
# File 'lib/decidim/events/simple_event.rb', line 75 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’s a Decidim::Component.
63 64 65 66 |
# File 'lib/decidim/events/simple_event.rb', line 63 def resource_path return super unless resource.is_a?(Decidim::Component) @resource_path ||= main_component_path(resource) end |
#resource_url ⇒ Object
Caches the URL for the given resource when it’s a Decidim::Component.
69 70 71 72 |
# File 'lib/decidim/events/simple_event.rb', line 69 def resource_url return super unless resource.is_a?(Decidim::Component) @resource_url ||= main_component_url(resource) end |