Sha256: 6e509522ad17006f975f5d977c3c5e7737f42446e556cac5817f54721380477a

Contents?: true

Size: 1.21 KB

Versions: 8

Compression:

Stored size: 1.21 KB

Contents

# frozen_string_literal: true

module Decidim
  class WelcomeNotificationEvent < Decidim::Events::BaseEvent
    include Decidim::Events::EmailEvent
    include Decidim::Events::NotificationEvent
    include TranslationsHelper

    delegate :organization, to: :user, prefix: false
    delegate :url_helpers, to: "Decidim::Core::Engine.routes"

    def subject
      interpolate(organization.welcome_notification_subject.symbolize_keys[I18n.locale])
    end

    def body
      interpolate(organization.welcome_notification_body.symbolize_keys[I18n.locale])
    end

    def email_subject
      subject
    end

    def email_greeting; end

    def email_intro
      body
    end

    def email_outro; end

    def notification_title
      ("<p><strong>#{subject}</strong></p>" + body).html_safe
    end

    def resource_path
      nil
    end

    def resource_title
      nil
    end

    private

    def interpolate(template)
      template
        .gsub("{{name}}", user.name)
        .gsub("{{organization}}", organization.name)
        .gsub("{{help_url}}", url_helpers.pages_url(host: organization.host))
        .gsub("{{badges_url}}", url_helpers.gamification_badges_url(host: organization.host))
        .html_safe
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
decidim-core-0.28.4 app/events/decidim/welcome_notification_event.rb
decidim-core-0.27.9 app/events/decidim/welcome_notification_event.rb
decidim-core-0.28.3 app/events/decidim/welcome_notification_event.rb
decidim-core-0.27.8 app/events/decidim/welcome_notification_event.rb
decidim-core-0.28.2 app/events/decidim/welcome_notification_event.rb
decidim-core-0.27.7 app/events/decidim/welcome_notification_event.rb
decidim-core-0.28.1 app/events/decidim/welcome_notification_event.rb
decidim-core-0.27.6 app/events/decidim/welcome_notification_event.rb