Class: GovukPublishingComponents::Presenters::InterventionHelper
- Inherits:
-
Object
- Object
- GovukPublishingComponents::Presenters::InterventionHelper
- Defined in:
- lib/govuk_publishing_components/presenters/intervention_helper.rb
Instance Method Summary collapse
- #accessible_text ⇒ Object
- #dismiss_link ⇒ Object
-
#initialize(options = {}) ⇒ InterventionHelper
constructor
A new instance of InterventionHelper.
- #security_attr ⇒ Object
- #show? ⇒ Boolean
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( = {}) @name = [:name] @dismiss_text = [:dismiss_text] @accessible_text_suffix = I18n.t("components.intervention.accessible_link_text_suffix") @params = [:params] @query_string = [:query_string] @suggestion_text = [:suggestion_text] @suggestion_link_text = [:suggestion_link_text] @suggestion_link_url = [:suggestion_link_url] end |
Instance Method Details
#accessible_text ⇒ Object
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 |
#dismiss_link ⇒ Object
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_attr ⇒ Object
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
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 |