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
# File 'lib/govuk_publishing_components/presenters/intervention_helper.rb', line 29

def security_attr
  rel = "noopener noreferrer"
  rel << " external" unless @suggestion_link_url.start_with?("/", "https://gov.uk", "https://www.gov.uk")

  rel
end

#show?Boolean

Returns:

  • (Boolean)


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

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