Sha256: ed79612194c8a56f0b2b4e647015594ec5268e98d6b96803cc5c58267ca500d8

Contents?: true

Size: 1.6 KB

Versions: 341

Compression:

Stored size: 1.6 KB

Contents

module GovukPublishingComponents
  module Presenters
    class SubscriptionLinksHelper
      attr_reader :feed_box_id, :email_signup_link, :email_signup_link_data_attributes, :feed_link_box_value

      def initialize(local_assigns)
        @local_assigns = local_assigns
        @feed_box_id = "feed-reader-#{SecureRandom.hex(2)}"
        @email_signup_link = @local_assigns[:email_signup_link]
        @email_signup_link_data_attributes = @local_assigns[:email_signup_link_data_attributes]
        @feed_link_box_value = @local_assigns[:feed_link_box_value]
      end

      def email_signup_link_text
        return @local_assigns[:email_signup_link_text] if @local_assigns[:email_signup_link_text]

        I18n.t("components.subscription_links.email_signup_link_text")
      end

      def feed_link_text
        return @local_assigns[:feed_link_text] if @local_assigns[:feed_link_text]

        I18n.t("components.subscription_links.feed_link_text")
      end

      def component_data_is_valid?
        email_signup_link.present? || feed_link.present? || feed_link_box_value.present?
      end

      def tracking_is_present?
        @local_assigns[:email_signup_link_data_attributes].present? || @local_assigns[:feed_link_data_attributes].present?
      end

      def feed_link
        return "#" if feed_link_box_value

        @local_assigns[:feed_link]
      end

      def feed_link_data_attributes
        data = @local_assigns[:feed_link_data_attributes] || {}
        data[:controls] = feed_box_id if feed_link_box_value
        data[:expanded] = "false" if feed_link_box_value
        data
      end
    end
  end
end

Version data entries

341 entries across 341 versions & 1 rubygems

Version Path
govuk_publishing_components-49.1.0 lib/govuk_publishing_components/presenters/subscription_links_helper.rb
govuk_publishing_components-49.0.0 lib/govuk_publishing_components/presenters/subscription_links_helper.rb
govuk_publishing_components-48.0.0 lib/govuk_publishing_components/presenters/subscription_links_helper.rb
govuk_publishing_components-47.0.0 lib/govuk_publishing_components/presenters/subscription_links_helper.rb
govuk_publishing_components-46.4.0 lib/govuk_publishing_components/presenters/subscription_links_helper.rb
govuk_publishing_components-46.3.1 lib/govuk_publishing_components/presenters/subscription_links_helper.rb
govuk_publishing_components-46.3.0 lib/govuk_publishing_components/presenters/subscription_links_helper.rb
govuk_publishing_components-46.2.0 lib/govuk_publishing_components/presenters/subscription_links_helper.rb
govuk_publishing_components-46.1.0 lib/govuk_publishing_components/presenters/subscription_links_helper.rb
govuk_publishing_components-46.0.0 lib/govuk_publishing_components/presenters/subscription_links_helper.rb
govuk_publishing_components-45.10.0 lib/govuk_publishing_components/presenters/subscription_links_helper.rb
govuk_publishing_components-45.9.0 lib/govuk_publishing_components/presenters/subscription_links_helper.rb
govuk_publishing_components-45.8.0 lib/govuk_publishing_components/presenters/subscription_links_helper.rb
govuk_publishing_components-45.7.0 lib/govuk_publishing_components/presenters/subscription_links_helper.rb
govuk_publishing_components-45.6.1 lib/govuk_publishing_components/presenters/subscription_links_helper.rb
govuk_publishing_components-45.6.0 lib/govuk_publishing_components/presenters/subscription_links_helper.rb
govuk_publishing_components-45.5.0 lib/govuk_publishing_components/presenters/subscription_links_helper.rb
govuk_publishing_components-45.4.1 lib/govuk_publishing_components/presenters/subscription_links_helper.rb
govuk_publishing_components-45.4.0 lib/govuk_publishing_components/presenters/subscription_links_helper.rb
govuk_publishing_components-45.3.0 lib/govuk_publishing_components/presenters/subscription_links_helper.rb