lib/ccs/components/govuk/cookie_banner.rb in ccs-frontend_helpers-0.1.0.rc.2 vs lib/ccs/components/govuk/cookie_banner.rb in ccs-frontend_helpers-0.1.0.rc.3

- old
+ new

@@ -1,53 +1,55 @@ require_relative '../base' require_relative 'cookie_banner/message' -module CCS::Components - module GovUK - # = GOV.UK Cookie Banner - # - # This is used to generate the cookie banner component from the - # {https://design-system.service.gov.uk/components/cookie-banner GDS - Components - Cookie banner} - # - # @!attribute [r] messages - # @return [Array<Message>] An array of the initialised cookie banner messages +module CCS + module Components + module GovUK + # = GOV.UK Cookie Banner + # + # This is used to generate the cookie banner component from the + # {https://design-system.service.gov.uk/components/cookie-banner GDS - Components - Cookie banner} + # + # @!attribute [r] messages + # @return [Array<Message>] An array of the initialised cookie banner messages - class CookieBanner < Base - private + class CookieBanner < Base + private - attr_reader :messages + attr_reader :messages - public + public - # @param messages [Array<Hash>] An array of messages for the cookie banner. - # See {Components::GovUK::CookieBanner::Message#initialize Message#initialize} for details of the items in the array. - # @param options [Hash] options that will be used in customising the HTML - # - # @option options [String] :classes additional CSS classes for the cookie banner HTML - # @option options [Hash] :attributes any additional attributes that will added as part of the HTML + # @param messages [Array<Hash>] An array of messages for the cookie banner. + # See {Components::GovUK::CookieBanner::Message#initialize Message#initialize} for details of the items in the array. + # @param options [Hash] options that will be used in customising the HTML + # + # @option options [String] :classes additional CSS classes for the cookie banner HTML + # @option options [Hash] :attributes any additional attributes that will added as part of the HTML - def initialize(messages:, **options) - super(**options) + def initialize(messages:, **options) + super(**options) - (@options[:attributes][:data] ||= {})[:nosnippet] = 'true' - @options[:attributes][:role] = 'region' - (@options[:attributes][:aria] ||= {})[:label] ||= 'Cookie banner' + (@options[:attributes][:data] ||= {})[:nosnippet] = 'true' + @options[:attributes][:role] = 'region' + (@options[:attributes][:aria] ||= {})[:label] ||= 'Cookie banner' - @messages = messages.map { |message| Message.new(context: @context, **message) } - end + @messages = messages.map { |message| Message.new(context: @context, **message) } + end - # Generates the HTML for the GOV.UK Cookie banner component - # - # @return [ActiveSupport::SafeBuffer] + # Generates the HTML for the GOV.UK Cookie banner component + # + # @return [ActiveSupport::SafeBuffer] - def render - tag.div(**options[:attributes]) do - messages.each { |message| concat(message.render) } + def render + tag.div(**options[:attributes]) do + messages.each { |message| concat(message.render) } + end end - end - # The default attributes for the cookie banner + # The default attributes for the cookie banner - DEFAULT_ATTRIBUTES = { class: 'govuk-cookie-banner' }.freeze + DEFAULT_ATTRIBUTES = { class: 'govuk-cookie-banner' }.freeze + end end end end