Sha256: 5fe14fb92f8fb60ad060f6401a1a507b24fd7dee9c291cc0dff5cbda1c976cab

Contents?: true

Size: 1.58 KB

Versions: 57

Compression:

Stored size: 1.58 KB

Contents

module GovukPublishingComponents
  module Presenters
    class InterventionHelper
      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

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

        @suggestion_link_text
      end

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

      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

      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

    private

      attr_reader :accessible_text_suffix, :query_string, :params, :suggestion_text, :suggestion_link_text, :suggestion_link_url
    end
  end
end

Version data entries

57 entries across 57 versions & 1 rubygems

Version Path
govuk_publishing_components-45.7.0 lib/govuk_publishing_components/presenters/intervention_helper.rb
govuk_publishing_components-45.6.1 lib/govuk_publishing_components/presenters/intervention_helper.rb
govuk_publishing_components-45.6.0 lib/govuk_publishing_components/presenters/intervention_helper.rb
govuk_publishing_components-45.5.0 lib/govuk_publishing_components/presenters/intervention_helper.rb
govuk_publishing_components-45.4.1 lib/govuk_publishing_components/presenters/intervention_helper.rb
govuk_publishing_components-45.4.0 lib/govuk_publishing_components/presenters/intervention_helper.rb
govuk_publishing_components-45.3.0 lib/govuk_publishing_components/presenters/intervention_helper.rb
govuk_publishing_components-45.2.0 lib/govuk_publishing_components/presenters/intervention_helper.rb
govuk_publishing_components-45.1.0 lib/govuk_publishing_components/presenters/intervention_helper.rb
govuk_publishing_components-45.0.0 lib/govuk_publishing_components/presenters/intervention_helper.rb
govuk_publishing_components-44.11.0 lib/govuk_publishing_components/presenters/intervention_helper.rb
govuk_publishing_components-44.10.0 lib/govuk_publishing_components/presenters/intervention_helper.rb
govuk_publishing_components-44.9.1 lib/govuk_publishing_components/presenters/intervention_helper.rb
govuk_publishing_components-44.9.0 lib/govuk_publishing_components/presenters/intervention_helper.rb
govuk_publishing_components-44.8.0 lib/govuk_publishing_components/presenters/intervention_helper.rb
govuk_publishing_components-44.7.1 lib/govuk_publishing_components/presenters/intervention_helper.rb
govuk_publishing_components-44.7.0 lib/govuk_publishing_components/presenters/intervention_helper.rb
govuk_publishing_components-44.6.0 lib/govuk_publishing_components/presenters/intervention_helper.rb
govuk_publishing_components-44.5.0 lib/govuk_publishing_components/presenters/intervention_helper.rb
govuk_publishing_components-44.4.2 lib/govuk_publishing_components/presenters/intervention_helper.rb