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
30 31 32 |
# File 'lib/govuk_publishing_components/presenters/single_page_notification_button_helper.rb', line 30 def %w[bottom top].include? @local_assigns[:button_location] end |
#button_text ⇒ Object
34 35 36 |
# File 'lib/govuk_publishing_components/presenters/single_page_notification_button_helper.rb', line 34 def @already_subscribed ? @button_text_unsubscribe : @button_text_subscribe end |
#custom_button_text_is_valid? ⇒ Boolean
38 39 40 |
# File 'lib/govuk_publishing_components/presenters/single_page_notification_button_helper.rb', line 38 def custom_subscribe_text.present? && custom_unsubscribe_text.present? end |
#custom_subscribe_text ⇒ Object
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_text ⇒ Object
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 |
#data ⇒ Object
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] = @data_attributes[:button_text_subscribe] = @button_text_subscribe @data_attributes[:button_text_unsubscribe] = @button_text_unsubscribe @data_attributes end |
#default_subscribe_text ⇒ Object
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_text ⇒ Object
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_account ⇒ Object
66 67 68 |
# File 'lib/govuk_publishing_components/presenters/single_page_notification_button_helper.rb', line 66 def email_alert_frontend_endpoint_enforce_account "/email/subscriptions/single-page/new" end |
#email_alert_frontend_endpoint_no_account ⇒ Object
70 71 72 |
# File 'lib/govuk_publishing_components/presenters/single_page_notification_button_helper.rb', line 70 def email_alert_frontend_endpoint_no_account "/email-signup" end |
#form_action ⇒ Object
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? email_alert_frontend_endpoint_no_account else email_alert_frontend_endpoint_enforce_account end end |
#skip_account_param ⇒ Object
74 75 76 |
# File 'lib/govuk_publishing_components/presenters/single_page_notification_button_helper.rb', line 74 def skip_account_param "single_page_subscription" end |
#skip_the_gov_uk_account? ⇒ 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 |