Class: GovukPublishingComponents::Presenters::InterventionHelper

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

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ InterventionHelper

Returns a new instance of InterventionHelper.



4
5
6
7
8
9
10
11
12
13
# File 'lib/govuk_publishing_components/presenters/intervention_helper.rb', line 4

def initialize(options = {})
  @name = options[:name]
  @dismiss_text = options[:dismiss_text]
  @accessible_text_suffix = I18n.t("components.intervention.accessible_link_text_suffix")
  @params = options[:params]
  @query_string = options[:query_string]
  @suggestion_text = options[:suggestion_text]
  @suggestion_link_text = options[:suggestion_link_text]
  @suggestion_link_url = options[:suggestion_link_url]
end

Instance Method Details

#accessible_textObject



15
16
17
18
19
# File 'lib/govuk_publishing_components/presenters/intervention_helper.rb', line 15

def accessible_text
  @suggestion_link_text << @accessible_text_suffix unless @suggestion_link_text.include?(@accessible_text_suffix)

  @suggestion_link_text
end


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

def dismiss_link
  if @query_string.present?
    "#{@query_string}&hide-intervention=true"
  else
    "?hide-intervention=true"
  end
end

#security_attrObject



29
30
31
32
33
34
35
36
# File 'lib/govuk_publishing_components/presenters/intervention_helper.rb', line 29

def security_attr
  # Link is external unless it begins with "/" (but not "//") or it's on gov.uk.
  if %r{\A(/[^/]|https://(www\.)?gov\.uk(/|\z))}.match?(@suggestion_link_url)
    "noopener noreferrer"
  else
    "noopener noreferrer external"
  end
end

#show?Boolean

Returns:

  • (Boolean)


38
39
40
41
42
43
# File 'lib/govuk_publishing_components/presenters/intervention_helper.rb', line 38

def show?
  return false if params["hide-intervention"] == "true"
  return false if @dismiss_text && @name.blank?

  @suggestion_text || (@suggestion_link_text && @suggestion_link_url)
end