Class: GovukComponent::Base

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/govuk_component/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(classes:, html_attributes:) ⇒ Base

Returns a new instance of Base.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/components/govuk_component/base.rb', line 8

def initialize(classes:, html_attributes:)
  if classes.nil?
    Rails.logger.warn("classes is nil, if no custom classes are needed omit the param")

    classes = []
  end
  # FIXME: remove first merge when we deprecate classes
  #
  # This step only needs to be here while we still accept classes:, now
  # we're using html_attributes_utils we can start to move towards
  # supporting html_attributes: { class: 'xyz' } over taking them
  # separately

  @html_attributes = default_attributes
    .deep_merge_html_attributes({ class: classes })
    .deep_merge_html_attributes(html_attributes)
    .deep_tidy_html_attributes

  super
end

Instance Attribute Details

#html_attributesObject (readonly)

Returns the value of attribute html_attributes.



4
5
6
# File 'app/components/govuk_component/base.rb', line 4

def html_attributes
  @html_attributes
end

Instance Method Details

#brand(override = nil) ⇒ Object



29
30
31
# File 'app/components/govuk_component/base.rb', line 29

def brand(override = nil)
  override || config.brand
end