Class: GovukPublishingComponents::Presenters::SubscriptionLinksHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/govuk_publishing_components/presenters/subscription_links_helper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(local_assigns) ⇒ SubscriptionLinksHelper

Returns a new instance of SubscriptionLinksHelper.



6
7
8
9
10
11
12
# File 'lib/govuk_publishing_components/presenters/subscription_links_helper.rb', line 6

def initialize(local_assigns)
  @local_assigns = local_assigns
  @feed_box_id = "feed-reader-#{SecureRandom.hex(2)}"
  @email_signup_link = @local_assigns[:email_signup_link]
  @email_signup_link_data_attributes = @local_assigns[:email_signup_link_data_attributes]
  @feed_link_box_value = @local_assigns[:feed_link_box_value]
end

Instance Attribute Details

Returns the value of attribute email_signup_link.



4
5
6
# File 'lib/govuk_publishing_components/presenters/subscription_links_helper.rb', line 4

def 
  @email_signup_link
end

Returns the value of attribute email_signup_link_data_attributes.



4
5
6
# File 'lib/govuk_publishing_components/presenters/subscription_links_helper.rb', line 4

def 
  @email_signup_link_data_attributes
end

#feed_box_idObject (readonly)

Returns the value of attribute feed_box_id.



4
5
6
# File 'lib/govuk_publishing_components/presenters/subscription_links_helper.rb', line 4

def feed_box_id
  @feed_box_id
end

Returns the value of attribute feed_link_box_value.



4
5
6
# File 'lib/govuk_publishing_components/presenters/subscription_links_helper.rb', line 4

def feed_link_box_value
  @feed_link_box_value
end

Instance Method Details

#component_data_is_valid?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/govuk_publishing_components/presenters/subscription_links_helper.rb', line 26

def component_data_is_valid?
  .present? || feed_link.present? || feed_link_box_value.present?
end


14
15
16
17
18
# File 'lib/govuk_publishing_components/presenters/subscription_links_helper.rb', line 14

def 
  return @local_assigns[:email_signup_link_text] if @local_assigns[:email_signup_link_text]

  I18n.t("components.subscription_links.email_signup_link_text")
end


34
35
36
37
38
# File 'lib/govuk_publishing_components/presenters/subscription_links_helper.rb', line 34

def feed_link
  return "#" if feed_link_box_value

  @local_assigns[:feed_link]
end


40
41
42
43
44
45
# File 'lib/govuk_publishing_components/presenters/subscription_links_helper.rb', line 40

def feed_link_data_attributes
  data = @local_assigns[:feed_link_data_attributes] || {}
  data[:controls] = feed_box_id if feed_link_box_value
  data[:expanded] = "false" if feed_link_box_value
  data
end


20
21
22
23
24
# File 'lib/govuk_publishing_components/presenters/subscription_links_helper.rb', line 20

def feed_link_text
  return @local_assigns[:feed_link_text] if @local_assigns[:feed_link_text]

  I18n.t("components.subscription_links.feed_link_text")
end

#tracking_is_present?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/govuk_publishing_components/presenters/subscription_links_helper.rb', line 30

def tracking_is_present?
  @local_assigns[:email_signup_link_data_attributes].present? || @local_assigns[:feed_link_data_attributes].present?
end