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
# 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] || {}
  @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"
  @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_text_subscribeObject (readonly)

Returns the value of attribute button_text_subscribe.



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

def button_text_subscribe
  @button_text_subscribe
end

#button_text_unsubscribeObject (readonly)

Returns the value of attribute button_text_unsubscribe.



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

def button_text_unsubscribe
  @button_text_unsubscribe
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

#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

#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)


18
19
20
# File 'lib/govuk_publishing_components/presenters/single_page_notification_button_helper.rb', line 18

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

#button_textObject



22
23
24
# File 'lib/govuk_publishing_components/presenters/single_page_notification_button_helper.rb', line 22

def button_text
  @already_subscribed ? @button_text_unsubscribe : @button_text_subscribe
end

#custom_button_text_is_valid?Boolean

Returns:

  • (Boolean)


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

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

#custom_subscribe_textObject



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

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

#custom_unsubscribe_textObject



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

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

#default_subscribe_textObject



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

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

#default_unsubscribe_textObject



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

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

#email_alert_frontend_endpoint_enforce_accountObject



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

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

#email_alert_frontend_endpoint_no_accountObject



58
59
60
# File 'lib/govuk_publishing_components/presenters/single_page_notification_button_helper.rb', line 58

def 
  "/email-signup"
end

#form_actionObject



46
47
48
49
50
51
52
# File 'lib/govuk_publishing_components/presenters/single_page_notification_button_helper.rb', line 46

def form_action
  if skip_the_gov_uk_account?
    
  else
    
  end
end

#skip_account_paramObject



62
63
64
# File 'lib/govuk_publishing_components/presenters/single_page_notification_button_helper.rb', line 62

def 
  "single_page_subscription"
end

#skip_the_gov_uk_account?Boolean

Returns:

  • (Boolean)


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

def skip_the_gov_uk_account?
  @skip_account == true
end