Sha256: dd2b433e838765bedcc71e032026e1935c9d35b548a817a4d5bfc90c3097b148

Contents?: true

Size: 1.66 KB

Versions: 258

Compression:

Stored size: 1.66 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("govuk_component.subscription_links.email_signup_link_text", default: "Get email alerts")
      end

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

        I18n.t("govuk_component.subscription_links.feed_link_text", default: "Subscribe to feed")
      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

258 entries across 258 versions & 1 rubygems

Version Path
govuk_publishing_components-23.7.4 lib/govuk_publishing_components/presenters/subscription_links_helper.rb
govuk_publishing_components-23.7.3 lib/govuk_publishing_components/presenters/subscription_links_helper.rb
govuk_publishing_components-23.7.2 lib/govuk_publishing_components/presenters/subscription_links_helper.rb
govuk_publishing_components-23.7.1 lib/govuk_publishing_components/presenters/subscription_links_helper.rb
govuk_publishing_components-23.7.0 lib/govuk_publishing_components/presenters/subscription_links_helper.rb
govuk_publishing_components-23.6.0 lib/govuk_publishing_components/presenters/subscription_links_helper.rb
govuk_publishing_components-23.5.1 lib/govuk_publishing_components/presenters/subscription_links_helper.rb
govuk_publishing_components-23.5.0 lib/govuk_publishing_components/presenters/subscription_links_helper.rb
govuk_publishing_components-23.4.0 lib/govuk_publishing_components/presenters/subscription_links_helper.rb
govuk_publishing_components-23.3.0 lib/govuk_publishing_components/presenters/subscription_links_helper.rb
govuk_publishing_components-23.2.1 lib/govuk_publishing_components/presenters/subscription_links_helper.rb
govuk_publishing_components-23.2.0 lib/govuk_publishing_components/presenters/subscription_links_helper.rb
govuk_publishing_components-23.1.0 lib/govuk_publishing_components/presenters/subscription_links_helper.rb
govuk_publishing_components-23.0.0 lib/govuk_publishing_components/presenters/subscription_links_helper.rb
govuk_publishing_components-21.69.0 lib/govuk_publishing_components/presenters/subscription_links_helper.rb
govuk_publishing_components-21.68.1 lib/govuk_publishing_components/presenters/subscription_links_helper.rb
govuk_publishing_components-21.68.0 lib/govuk_publishing_components/presenters/subscription_links_helper.rb
govuk_publishing_components-21.67.2 lib/govuk_publishing_components/presenters/subscription_links_helper.rb
govuk_publishing_components-21.67.1 lib/govuk_publishing_components/presenters/subscription_links_helper.rb
govuk_publishing_components-21.67.0 lib/govuk_publishing_components/presenters/subscription_links_helper.rb