Module: Decidim::NewslettersHelper

Included in:
NewsletterMailer, Decidim::NewsletterTemplates::BaseCell, NewslettersController
Defined in:
app/helpers/decidim/newsletters_helper.rb

Overview

Helper that provides methods to render links with utm codes, and replaced name

Instance Method Summary collapse

Instance Method Details

#custom_url_for_mail_root(organization, newsletter_id = nil) ⇒ String

this method is used to generate the root link on mail with the utm_codes If the newsletter_id is nil, it returns the root_url

Parameters:

  • organization (Decidim::Organization)
    • the Organization of this newsletter

  • newsletter_id (Integer) (defaults to: nil)
    • the id of the newsletter

Returns:

  • (String)
    • the root_url converted



33
34
35
36
37
38
39
40
# File 'app/helpers/decidim/newsletters_helper.rb', line 33

def custom_url_for_mail_root(organization, newsletter_id = nil)
  decidim = EngineRouter.new("decidim", {})
  if newsletter_id.present?
    decidim.root_url(host: organization.host) + utm_codes(organization.host, newsletter_id.to_s)
  else
    decidim.root_url(host: organization.host)
  end
end

#parse_interpolations(content, user = nil, id = nil) ⇒ String

If the newsletter body there are some links and the Decidim.track_newsletter_links = true it will be replaced with the utm_codes method described below. for example transform “es.lipsum.com/” to “es.lipsum.com/?utm_source=localhost&utm_campaign=newsletter_11” And replace “%name” on the subject or content of newsletter to the user Name for example transform “%name” to “User Name”

Parameters:

  • content (String)
    • the string to convert

  • user (Decidim::User) (defaults to: nil)
    • the user to replace

  • id (Integer) (defaults to: nil)
    • the id of the newsletter to change

Returns:

  • (String)
    • the content converted



17
18
19
20
21
22
23
# File 'app/helpers/decidim/newsletters_helper.rb', line 17

def parse_interpolations(content, user = nil, id = nil)
  host = user&.organization&.host&.to_s

  content = interpret_name(content, user)
  content = track_newsletter_links(content, id, host)
  transform_image_urls(content, host)
end