Class: CCS::Components::GovUK::CookieBanner::Message

Inherits:
Base
  • Object
show all
Defined in:
lib/ccs/components/govuk/cookie_banner/message.rb

Overview

GOV.UK Cookie Banner Message

The individual cookie banner message

Constant Summary collapse

DEFAULT_ATTRIBUTES =

The default attributes for the cookie banner message

{ class: 'govuk-cookie-banner__message govuk-width-container' }.freeze

Instance Method Summary collapse

Constructor Details

#initialize(heading_text: nil, content: nil, text: nil, actions: nil, **options) ⇒ Message

Returns a new instance of Message.

Parameters:

  • heading_text (String) (defaults to: nil)

    the heading text that displays in the message

  • content (ActiveSupport::SafeBuffer) (defaults to: nil)

    HTML to use as content for the message

  • text (String) (defaults to: nil)

    if :content is blank then this is the text used for the message

  • actions (Array<Hash>) (defaults to: nil)

    the buttons and/or links that you want to display in the message. See Action#initialize for details of the items in the array.

  • options (Hash)

    options that will be used in customising the HTML

Options Hash (**options):

  • :classes (String)

    additional CSS classes for the cookie message HTML

  • :attributes (Hash)

    any additional attributes that will added as part of the HTML



38
39
40
41
42
43
44
45
# File 'lib/ccs/components/govuk/cookie_banner/message.rb', line 38

def initialize(heading_text: nil, content: nil, text: nil, actions: nil, **options)
  super(**options)

  @heading_text = heading_text
  @content = content
  @text = text
  @actions = actions.map { |action| Action.new(context: @context, **action) } if actions
end

Instance Method Details

#renderActiveSupport::SafeBuffer

Generates the HTML for the GOV.UK Cookie Banner Message

Returns:

  • (ActiveSupport::SafeBuffer)


53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/ccs/components/govuk/cookie_banner/message.rb', line 53

def render
  tag.div(**options[:attributes]) do
    concat(tag.div(class: 'govuk-grid-row') do
      tag.div(class: 'govuk-grid-column-two-thirds') do
        concat(tag.h2(heading_text, class: 'govuk-cookie-banner__heading govuk-heading-m')) if heading_text
        concat(tag.div(class: 'govuk-cookie-banner__content') do
          content || tag.p(text, class: 'govuk-body') if content || text
        end)
      end
    end)
    if actions
      concat(tag.div(class: 'govuk-button-group') do
        actions.each { |action| concat(action.render) }
      end)
    end
  end
end