Class: CCS::Components::GovUK::ErrorSummary
- Defined in:
- lib/ccs/components/govuk/error_summary.rb,
lib/ccs/components/govuk/error_summary/item.rb
Overview
GOV.UK Error Summary
This is used to generate the error summary component from the GDS - Components - Error summary
Defined Under Namespace
Classes: Item
Constant Summary collapse
- DEFAULT_ATTRIBUTES =
The default attributes for the error summary
{ class: 'govuk-error-summary', data: { module: 'govuk-error-summary' } }.freeze
Instance Method Summary collapse
-
#initialize(title:, error_summary_items: [], description: nil, **options) ⇒ ErrorSummary
constructor
A new instance of ErrorSummary.
-
#render ⇒ ActiveSupport::SafeBuffer
Generates the HTML for the GOV.UK Error summary component.
Constructor Details
#initialize(title:, error_summary_items: [], description: nil, **options) ⇒ ErrorSummary
Returns a new instance of ErrorSummary.
34 35 36 37 38 39 40 |
# File 'lib/ccs/components/govuk/error_summary.rb', line 34 def initialize(title:, error_summary_items: [], description: nil, **) super(**) @title = title @error_summary_items = error_summary_items.map { |error_summary_item| Item.new(context: @context, **error_summary_item) } @description = description end |
Instance Method Details
#render ⇒ ActiveSupport::SafeBuffer
Generates the HTML for the GOV.UK Error summary component
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/ccs/components/govuk/error_summary.rb', line 48 def render tag.div(**[:attributes]) do tag.div(role: 'alert') do concat(tag.h2(title, class: 'govuk-error-summary__title')) concat(tag.div(class: 'govuk-error-summary__body') do concat(tag.p(description)) if description if error_summary_items.any? concat(tag.ul(class: 'govuk-list govuk-error-summary__list') do error_summary_items.each { |error_summary_item| concat(error_summary_item.render) } end) end end) end end end |