Class: GovukPublishingComponents::Presenters::SinglePageNotificationButtonHelper
- Inherits:
-
Object
- Object
- GovukPublishingComponents::Presenters::SinglePageNotificationButtonHelper
- Defined in:
- lib/govuk_publishing_components/presenters/single_page_notification_button_helper.rb
Instance Attribute Summary collapse
-
#already_subscribed ⇒ Object
readonly
Returns the value of attribute already_subscribed.
-
#base_path ⇒ Object
readonly
Returns the value of attribute base_path.
-
#button_location ⇒ Object
readonly
Returns the value of attribute button_location.
-
#button_type ⇒ Object
readonly
Returns the value of attribute button_type.
-
#classes ⇒ Object
readonly
Returns the value of attribute classes.
-
#data_attributes ⇒ Object
readonly
Returns the value of attribute data_attributes.
-
#js_enhancement ⇒ Object
readonly
Returns the value of attribute js_enhancement.
-
#skip_account ⇒ Object
readonly
Returns the value of attribute skip_account.
Instance Method Summary collapse
- #button_location_is_valid? ⇒ Boolean
- #button_text ⇒ Object
- #custom_button_text_is_valid? ⇒ Boolean
- #custom_subscribe_text ⇒ Object
- #custom_unsubscribe_text ⇒ Object
- #data ⇒ Object
- #default_subscribe_text ⇒ Object
- #default_unsubscribe_text ⇒ Object
- #email_alert_frontend_endpoint_enforce_account ⇒ Object
- #email_alert_frontend_endpoint_no_account ⇒ Object
- #form_action ⇒ Object
-
#initialize(local_assigns) ⇒ SinglePageNotificationButtonHelper
constructor
A new instance of SinglePageNotificationButtonHelper.
- #skip_account_param ⇒ Object
- #skip_the_gov_uk_account? ⇒ Boolean
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 = ? @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_subscribe_text : default_subscribe_text @button_text_unsubscribe = ? custom_unsubscribe_text : default_unsubscribe_text @skip_account = @local_assigns[:skip_account] || nil end |
Instance Attribute Details
#already_subscribed ⇒ Object (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_path ⇒ Object (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_location ⇒ Object (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 end |
#button_type ⇒ Object (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 end |
#classes ⇒ Object (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_attributes ⇒ Object (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_enhancement ⇒ Object (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_account ⇒ Object (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 @skip_account end |
Instance Method Details
#button_location_is_valid? ⇒ Boolean
35 36 37 |
# File 'lib/govuk_publishing_components/presenters/single_page_notification_button_helper.rb', line 35 def %w[bottom top].include? @local_assigns[:button_location] end |
#button_text ⇒ Object
39 40 41 |
# File 'lib/govuk_publishing_components/presenters/single_page_notification_button_helper.rb', line 39 def @already_subscribed ? @button_text_unsubscribe : @button_text_subscribe end |
#custom_button_text_is_valid? ⇒ Boolean
43 44 45 |
# File 'lib/govuk_publishing_components/presenters/single_page_notification_button_helper.rb', line 43 def custom_subscribe_text.present? && custom_unsubscribe_text.present? end |
#custom_subscribe_text ⇒ Object
47 48 49 |
# File 'lib/govuk_publishing_components/presenters/single_page_notification_button_helper.rb', line 47 def custom_subscribe_text @local_assigns.dig(:button_text, :subscribe) end |
#custom_unsubscribe_text ⇒ Object
51 52 53 |
# File 'lib/govuk_publishing_components/presenters/single_page_notification_button_helper.rb', line 51 def custom_unsubscribe_text @local_assigns.dig(:button_text, :unsubscribe) end |
#data ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/govuk_publishing_components/presenters/single_page_notification_button_helper.rb', line 21 def data @data_attributes[:track_label] = base_path # data-action for tracking should have the format of e.g. "Unsubscribe-button-top", or "Subscribe-button-bottom" # when button_location is not present data-action will fall back to "Unsubscribe-button"/"Subscribe-button" @data_attributes[:track_action] = [, "button", ].compact.join("-") @data_attributes[:module] = "single-page-notification-button" if js_enhancement @data_attributes[:track_category] = "Single-page-notification-button" # 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] = @data_attributes[:button_text_subscribe] = @button_text_subscribe @data_attributes[:button_text_unsubscribe] = @button_text_unsubscribe @data_attributes end |
#default_subscribe_text ⇒ Object
55 56 57 |
# File 'lib/govuk_publishing_components/presenters/single_page_notification_button_helper.rb', line 55 def default_subscribe_text I18n.t("components.single_page_notification_button.subscribe_text") end |
#default_unsubscribe_text ⇒ Object
59 60 61 |
# File 'lib/govuk_publishing_components/presenters/single_page_notification_button_helper.rb', line 59 def default_unsubscribe_text I18n.t("components.single_page_notification_button.unsubscribe_text") end |
#email_alert_frontend_endpoint_enforce_account ⇒ Object
71 72 73 |
# File 'lib/govuk_publishing_components/presenters/single_page_notification_button_helper.rb', line 71 def email_alert_frontend_endpoint_enforce_account "/email/subscriptions/single-page/new" end |
#email_alert_frontend_endpoint_no_account ⇒ Object
75 76 77 |
# File 'lib/govuk_publishing_components/presenters/single_page_notification_button_helper.rb', line 75 def email_alert_frontend_endpoint_no_account "/email-signup" end |
#form_action ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/govuk_publishing_components/presenters/single_page_notification_button_helper.rb', line 63 def form_action if skip_the_gov_uk_account? email_alert_frontend_endpoint_no_account else email_alert_frontend_endpoint_enforce_account end end |
#skip_account_param ⇒ Object
79 80 81 |
# File 'lib/govuk_publishing_components/presenters/single_page_notification_button_helper.rb', line 79 def skip_account_param "single_page_subscription" end |
#skip_the_gov_uk_account? ⇒ Boolean
83 84 85 |
# File 'lib/govuk_publishing_components/presenters/single_page_notification_button_helper.rb', line 83 def skip_the_gov_uk_account? @skip_account == "true" end |