Class: GovukPublishingComponents::Presenters::SinglePageNotificationButtonHelper

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(local_assigns) ⇒ SinglePageNotificationButtonHelper

Returns a new instance of SinglePageNotificationButtonHelper.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/govuk_publishing_components/presenters/single_page_notification_button_helper.rb', line 6

def initialize(local_assigns)
  @local_assigns = local_assigns
  @data_attributes = @local_assigns[:data_attributes] || {}
  @js_enhancement = @local_assigns[:js_enhancement] || false
  @already_subscribed = @local_assigns[:already_subscribed] || false
  @base_path = @local_assigns[:base_path] || nil
  @button_location = button_location_is_valid? ? @local_assigns[:button_location] : nil
  @button_type = @local_assigns[:already_subscribed] ? "Unsubscribe" : "Subscribe"
  @classes = %w[gem-c-single-page-notification-button]
  @classes << "js-personalisation-enhancement" if js_enhancement
  @button_text_subscribe = custom_button_text_is_valid? ? custom_subscribe_text : default_subscribe_text
  @button_text_unsubscribe = custom_button_text_is_valid? ? custom_unsubscribe_text : default_unsubscribe_text
  @skip_account = @local_assigns[:skip_account] || nil
end

Instance Attribute Details

#already_subscribedObject (readonly)

Returns the value of attribute already_subscribed.



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

def already_subscribed
  @already_subscribed
end

#base_pathObject (readonly)

Returns the value of attribute base_path.



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

def base_path
  @base_path
end

#button_locationObject (readonly)

Returns the value of attribute button_location.



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

def button_location
  @button_location
end

#button_typeObject (readonly)

Returns the value of attribute button_type.



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

def button_type
  @button_type
end

#classesObject (readonly)

Returns the value of attribute classes.



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

def classes
  @classes
end

#data_attributesObject (readonly)

Returns the value of attribute data_attributes.



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

def data_attributes
  @data_attributes
end

#js_enhancementObject (readonly)

Returns the value of attribute js_enhancement.



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

def js_enhancement
  @js_enhancement
end

#skip_accountObject (readonly)

Returns the value of attribute skip_account.



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

def 
  @skip_account
end

Instance Method Details

#button_location_is_valid?Boolean

Returns:

  • (Boolean)


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

def button_location_is_valid?
  %w[bottom top].include? @local_assigns[:button_location]
end

#button_textObject



34
35
36
# File 'lib/govuk_publishing_components/presenters/single_page_notification_button_helper.rb', line 34

def button_text
  @already_subscribed ? @button_text_unsubscribe : @button_text_subscribe
end

#custom_button_text_is_valid?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/govuk_publishing_components/presenters/single_page_notification_button_helper.rb', line 38

def custom_button_text_is_valid?
  custom_subscribe_text.present? && custom_unsubscribe_text.present?
end

#custom_subscribe_textObject



42
43
44
# File 'lib/govuk_publishing_components/presenters/single_page_notification_button_helper.rb', line 42

def custom_subscribe_text
  @local_assigns.dig(:button_text, :subscribe)
end

#custom_unsubscribe_textObject



46
47
48
# File 'lib/govuk_publishing_components/presenters/single_page_notification_button_helper.rb', line 46

def custom_unsubscribe_text
  @local_assigns.dig(:button_text, :unsubscribe)
end

#dataObject



21
22
23
24
25
26
27
28
# File 'lib/govuk_publishing_components/presenters/single_page_notification_button_helper.rb', line 21

def data
  @data_attributes[:module] = "single-page-notification-button" if js_enhancement
  # This attribute is passed through to the personalisation API to ensure when a new button is returned from the API, it has the same button_location
  @data_attributes[:button_location] = button_location
  @data_attributes[:button_text_subscribe] = @button_text_subscribe
  @data_attributes[:button_text_unsubscribe] = @button_text_unsubscribe
  @data_attributes
end

#default_subscribe_textObject



50
51
52
# File 'lib/govuk_publishing_components/presenters/single_page_notification_button_helper.rb', line 50

def default_subscribe_text
  I18n.t("components.single_page_notification_button.subscribe_text")
end

#default_unsubscribe_textObject



54
55
56
# File 'lib/govuk_publishing_components/presenters/single_page_notification_button_helper.rb', line 54

def default_unsubscribe_text
  I18n.t("components.single_page_notification_button.unsubscribe_text")
end

#email_alert_frontend_endpoint_enforce_accountObject



66
67
68
# File 'lib/govuk_publishing_components/presenters/single_page_notification_button_helper.rb', line 66

def 
  "/email/subscriptions/single-page/new"
end

#email_alert_frontend_endpoint_no_accountObject



70
71
72
# File 'lib/govuk_publishing_components/presenters/single_page_notification_button_helper.rb', line 70

def 
  "/email-signup"
end

#form_actionObject



58
59
60
61
62
63
64
# File 'lib/govuk_publishing_components/presenters/single_page_notification_button_helper.rb', line 58

def form_action
  if skip_the_gov_uk_account?
    
  else
    
  end
end

#skip_account_paramObject



74
75
76
# File 'lib/govuk_publishing_components/presenters/single_page_notification_button_helper.rb', line 74

def 
  "single_page_subscription"
end

#skip_the_gov_uk_account?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/govuk_publishing_components/presenters/single_page_notification_button_helper.rb', line 78

def skip_the_gov_uk_account?
  @skip_account == "true"
end