ccs-frontend_helpers 0.1.0.rc.2 → 0.1.0.rc.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (140) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1 -1
  3. data/Gemfile.lock +1 -1
  4. data/lib/ccs/components/ccs/dashboard_section/panel.rb +43 -41
  5. data/lib/ccs/components/ccs/dashboard_section.rb +50 -48
  6. data/lib/ccs/components/ccs/footer/link.rb +41 -39
  7. data/lib/ccs/components/ccs/footer/meta.rb +49 -48
  8. data/lib/ccs/components/ccs/footer/navigation.rb +51 -50
  9. data/lib/ccs/components/ccs/footer.rb +69 -67
  10. data/lib/ccs/components/ccs/header/link.rb +47 -45
  11. data/lib/ccs/components/ccs/header/navigation.rb +85 -84
  12. data/lib/ccs/components/ccs/header/service_authentication.rb +35 -34
  13. data/lib/ccs/components/ccs/header.rb +87 -85
  14. data/lib/ccs/components/ccs/logo.rb +36 -34
  15. data/lib/ccs/components/govuk/accordion/section/content.rb +42 -42
  16. data/lib/ccs/components/govuk/accordion/section/header.rb +48 -48
  17. data/lib/ccs/components/govuk/accordion/section.rb +49 -48
  18. data/lib/ccs/components/govuk/accordion.rb +43 -41
  19. data/lib/ccs/components/govuk/back_link.rb +39 -37
  20. data/lib/ccs/components/govuk/breadcrumbs/link.rb +42 -40
  21. data/lib/ccs/components/govuk/breadcrumbs.rb +40 -38
  22. data/lib/ccs/components/govuk/button.rb +83 -81
  23. data/lib/ccs/components/govuk/cookie_banner/action.rb +45 -43
  24. data/lib/ccs/components/govuk/cookie_banner/message.rb +57 -55
  25. data/lib/ccs/components/govuk/cookie_banner.rb +40 -38
  26. data/lib/ccs/components/govuk/details.rb +38 -36
  27. data/lib/ccs/components/govuk/error_message.rb +46 -44
  28. data/lib/ccs/components/govuk/error_summary/item.rb +41 -39
  29. data/lib/ccs/components/govuk/error_summary.rb +49 -47
  30. data/lib/ccs/components/govuk/field/input/character_count.rb +101 -99
  31. data/lib/ccs/components/govuk/field/input/file_upload.rb +29 -27
  32. data/lib/ccs/components/govuk/field/input/select.rb +61 -59
  33. data/lib/ccs/components/govuk/field/input/text_input/fix.rb +39 -37
  34. data/lib/ccs/components/govuk/field/input/text_input.rb +75 -73
  35. data/lib/ccs/components/govuk/field/input/textarea.rb +43 -41
  36. data/lib/ccs/components/govuk/field/input.rb +46 -44
  37. data/lib/ccs/components/govuk/field/inputs/checkboxes.rb +43 -41
  38. data/lib/ccs/components/govuk/field/inputs/date_input/item.rb +48 -46
  39. data/lib/ccs/components/govuk/field/inputs/date_input.rb +68 -66
  40. data/lib/ccs/components/govuk/field/inputs/item/checkbox/form.rb +29 -27
  41. data/lib/ccs/components/govuk/field/inputs/item/checkbox/tag.rb +26 -24
  42. data/lib/ccs/components/govuk/field/inputs/item/checkbox.rb +32 -30
  43. data/lib/ccs/components/govuk/field/inputs/item/divider.rb +39 -37
  44. data/lib/ccs/components/govuk/field/inputs/item/radio/form.rb +27 -25
  45. data/lib/ccs/components/govuk/field/inputs/item/radio/tag.rb +26 -24
  46. data/lib/ccs/components/govuk/field/inputs/item/radio.rb +32 -30
  47. data/lib/ccs/components/govuk/field/inputs/item.rb +100 -98
  48. data/lib/ccs/components/govuk/field/inputs/radios.rb +43 -41
  49. data/lib/ccs/components/govuk/field/inputs.rb +42 -40
  50. data/lib/ccs/components/govuk/field.rb +90 -88
  51. data/lib/ccs/components/govuk/fieldset/legend.rb +50 -48
  52. data/lib/ccs/components/govuk/fieldset.rb +40 -38
  53. data/lib/ccs/components/govuk/footer/link.rb +41 -39
  54. data/lib/ccs/components/govuk/footer/meta.rb +49 -48
  55. data/lib/ccs/components/govuk/footer/navigation.rb +51 -50
  56. data/lib/ccs/components/govuk/footer.rb +105 -103
  57. data/lib/ccs/components/govuk/form_group.rb +45 -43
  58. data/lib/ccs/components/govuk/header/link.rb +41 -39
  59. data/lib/ccs/components/govuk/header/navigation.rb +54 -53
  60. data/lib/ccs/components/govuk/header.rb +84 -82
  61. data/lib/ccs/components/govuk/hint.rb +33 -31
  62. data/lib/ccs/components/govuk/inset_text.rb +39 -37
  63. data/lib/ccs/components/govuk/label.rb +61 -59
  64. data/lib/ccs/components/govuk/notification_banner.rb +83 -81
  65. data/lib/ccs/components/govuk/pagination/increment/next.rb +29 -27
  66. data/lib/ccs/components/govuk/pagination/increment/previous.rb +28 -26
  67. data/lib/ccs/components/govuk/pagination/increment.rb +78 -76
  68. data/lib/ccs/components/govuk/pagination/item/ellipsis.rb +17 -15
  69. data/lib/ccs/components/govuk/pagination/item/form.rb +34 -32
  70. data/lib/ccs/components/govuk/pagination/item/tag.rb +33 -31
  71. data/lib/ccs/components/govuk/pagination/item.rb +47 -45
  72. data/lib/ccs/components/govuk/pagination.rb +69 -67
  73. data/lib/ccs/components/govuk/panel.rb +49 -47
  74. data/lib/ccs/components/govuk/phase_banner.rb +50 -48
  75. data/lib/ccs/components/govuk/skip_link.rb +39 -37
  76. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list/item.rb +40 -38
  77. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list.rb +30 -28
  78. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/paragraph.rb +28 -26
  79. data/lib/ccs/components/govuk/step_by_step_navigation/section/content.rb +47 -45
  80. data/lib/ccs/components/govuk/step_by_step_navigation/section/heading.rb +49 -47
  81. data/lib/ccs/components/govuk/step_by_step_navigation/section.rb +44 -42
  82. data/lib/ccs/components/govuk/step_by_step_navigation.rb +41 -39
  83. data/lib/ccs/components/govuk/summary_list/action/link.rb +46 -44
  84. data/lib/ccs/components/govuk/summary_list/card/actions.rb +38 -36
  85. data/lib/ccs/components/govuk/summary_list/card/title.rb +37 -35
  86. data/lib/ccs/components/govuk/summary_list/card.rb +48 -46
  87. data/lib/ccs/components/govuk/summary_list/row/actions.rb +38 -36
  88. data/lib/ccs/components/govuk/summary_list/row/key.rb +30 -28
  89. data/lib/ccs/components/govuk/summary_list/row/value.rb +30 -28
  90. data/lib/ccs/components/govuk/summary_list/row.rb +47 -45
  91. data/lib/ccs/components/govuk/summary_list.rb +48 -46
  92. data/lib/ccs/components/govuk/table/body/data_cell.rb +38 -36
  93. data/lib/ccs/components/govuk/table/body/head_cell.rb +37 -35
  94. data/lib/ccs/components/govuk/table/header/head_cell.rb +39 -37
  95. data/lib/ccs/components/govuk/table.rb +83 -81
  96. data/lib/ccs/components/govuk/tabs/panel.rb +47 -45
  97. data/lib/ccs/components/govuk/tabs/tab.rb +42 -40
  98. data/lib/ccs/components/govuk/tabs.rb +48 -46
  99. data/lib/ccs/components/govuk/tag.rb +39 -37
  100. data/lib/ccs/components/govuk/warning_text.rb +49 -47
  101. data/lib/ccs/frontend_helpers/ccs_frontend/dashboard_section.rb +16 -14
  102. data/lib/ccs/frontend_helpers/ccs_frontend/footer.rb +17 -15
  103. data/lib/ccs/frontend_helpers/ccs_frontend/header.rb +17 -15
  104. data/lib/ccs/frontend_helpers/ccs_frontend.rb +1 -1
  105. data/lib/ccs/frontend_helpers/govuk_frontend/accordion.rb +17 -15
  106. data/lib/ccs/frontend_helpers/govuk_frontend/back_link.rb +17 -15
  107. data/lib/ccs/frontend_helpers/govuk_frontend/breadcrumbs.rb +17 -15
  108. data/lib/ccs/frontend_helpers/govuk_frontend/button.rb +17 -15
  109. data/lib/ccs/frontend_helpers/govuk_frontend/character_count.rb +17 -15
  110. data/lib/ccs/frontend_helpers/govuk_frontend/checkboxes.rb +17 -15
  111. data/lib/ccs/frontend_helpers/govuk_frontend/cookie_banner.rb +17 -15
  112. data/lib/ccs/frontend_helpers/govuk_frontend/date_input.rb +17 -15
  113. data/lib/ccs/frontend_helpers/govuk_frontend/details.rb +19 -17
  114. data/lib/ccs/frontend_helpers/govuk_frontend/error_message.rb +32 -30
  115. data/lib/ccs/frontend_helpers/govuk_frontend/error_summary.rb +38 -36
  116. data/lib/ccs/frontend_helpers/govuk_frontend/fieldset.rb +19 -17
  117. data/lib/ccs/frontend_helpers/govuk_frontend/file_upload.rb +17 -15
  118. data/lib/ccs/frontend_helpers/govuk_frontend/footer.rb +17 -15
  119. data/lib/ccs/frontend_helpers/govuk_frontend/form_group.rb +27 -25
  120. data/lib/ccs/frontend_helpers/govuk_frontend/header.rb +17 -15
  121. data/lib/ccs/frontend_helpers/govuk_frontend/hint.rb +18 -16
  122. data/lib/ccs/frontend_helpers/govuk_frontend/input.rb +17 -15
  123. data/lib/ccs/frontend_helpers/govuk_frontend/inset_text.rb +19 -17
  124. data/lib/ccs/frontend_helpers/govuk_frontend/label.rb +18 -16
  125. data/lib/ccs/frontend_helpers/govuk_frontend/notification_banner.rb +19 -17
  126. data/lib/ccs/frontend_helpers/govuk_frontend/pagination.rb +17 -15
  127. data/lib/ccs/frontend_helpers/govuk_frontend/panel.rb +19 -17
  128. data/lib/ccs/frontend_helpers/govuk_frontend/phase_banner.rb +19 -17
  129. data/lib/ccs/frontend_helpers/govuk_frontend/radios.rb +17 -15
  130. data/lib/ccs/frontend_helpers/govuk_frontend/select.rb +17 -15
  131. data/lib/ccs/frontend_helpers/govuk_frontend/skip_link.rb +17 -15
  132. data/lib/ccs/frontend_helpers/govuk_frontend/step_by_step_navigation.rb +24 -22
  133. data/lib/ccs/frontend_helpers/govuk_frontend/summary_list.rb +17 -15
  134. data/lib/ccs/frontend_helpers/govuk_frontend/table.rb +17 -15
  135. data/lib/ccs/frontend_helpers/govuk_frontend/tabs.rb +17 -15
  136. data/lib/ccs/frontend_helpers/govuk_frontend/tag.rb +17 -15
  137. data/lib/ccs/frontend_helpers/govuk_frontend/textarea.rb +17 -15
  138. data/lib/ccs/frontend_helpers/govuk_frontend/warning_text.rb +19 -17
  139. data/lib/ccs/frontend_helpers/version.rb +1 -1
  140. metadata +2 -2
@@ -1,57 +1,58 @@
1
- require_relative '../../base'
2
1
  require_relative 'section/header'
3
2
  require_relative 'section/content'
4
3
 
5
- module CCS::Components
6
- module GovUK
7
- class Accordion < Base
8
- # = GOV.UK Accordion Section
9
- #
10
- # The individual accordion section
11
- #
12
- # @!attribute [r] header
13
- # @return [Header] Initialised accordion section header
14
- # @!attribute [r] content
15
- # @return [Content] Initialised accordion section content
16
- # @!attribute [r] section_is_expanded
17
- # @return [Boolean] flag to indicate of the section should be expanded
18
-
19
- class Section
20
- include ActionView::Context
21
- include ActionView::Helpers
22
-
23
- private
24
-
25
- attr_reader :header, :content, :section_is_expanded
26
-
27
- public
28
-
29
- # @param section [Hash] attributes for the accordion section
30
- # @param accordion_id [String] ID of the accordion
31
- # @param index [Integer] the index of the accordion section
32
- # @param heading_level [Integer] heading level, from 1 to 6
4
+ module CCS
5
+ module Components
6
+ module GovUK
7
+ class Accordion < Base
8
+ # = GOV.UK Accordion Section
33
9
  #
34
- # @option section [Boolean] :expanded sets whether the section should be expanded
35
- # when the page loads for the first time.
36
- # @option section [String] :heading the heading text for the accordion
37
- # @option section [String] :summary (nil) optional summary text for the accordion header
38
- # @option section [ActiveSupport::SafeBuffer] :content the content within the accordion section
39
- # @option section [String] : text if +:content+ is +nil+ then the text will be rendered
40
-
41
- def initialize(section:, accordion_id:, index:, heading_level:)
42
- @section_is_expanded = section[:expanded]
43
- @header = Header.new(section: section, accordion_id: accordion_id, index: index, heading_level: heading_level)
44
- @content = Content.new(section: section, accordion_id: accordion_id, index: index)
45
- end
46
-
47
- # Generates the HTML for the GOV.UK Accordion Section
10
+ # The individual accordion section
48
11
  #
49
- # @return [ActiveSupport::SafeBuffer]
12
+ # @!attribute [r] header
13
+ # @return [Header] Initialised accordion section header
14
+ # @!attribute [r] content
15
+ # @return [Content] Initialised accordion section content
16
+ # @!attribute [r] section_is_expanded
17
+ # @return [Boolean] flag to indicate of the section should be expanded
18
+
19
+ class Section
20
+ include ActionView::Context
21
+ include ActionView::Helpers
22
+
23
+ private
24
+
25
+ attr_reader :header, :content, :section_is_expanded
26
+
27
+ public
28
+
29
+ # @param section [Hash] attributes for the accordion section
30
+ # @param accordion_id [String] ID of the accordion
31
+ # @param index [Integer] the index of the accordion section
32
+ # @param heading_level [Integer] heading level, from 1 to 6
33
+ #
34
+ # @option section [Boolean] :expanded sets whether the section should be expanded
35
+ # when the page loads for the first time.
36
+ # @option section [String] :heading the heading text for the accordion
37
+ # @option section [String] :summary (nil) optional summary text for the accordion header
38
+ # @option section [ActiveSupport::SafeBuffer] :content the content within the accordion section
39
+ # @option section [String] : text if +:content+ is +nil+ then the text will be rendered
40
+
41
+ def initialize(section:, accordion_id:, index:, heading_level:)
42
+ @section_is_expanded = section[:expanded]
43
+ @header = Header.new(section: section, accordion_id: accordion_id, index: index, heading_level: heading_level)
44
+ @content = Content.new(section: section, accordion_id: accordion_id, index: index)
45
+ end
46
+
47
+ # Generates the HTML for the GOV.UK Accordion Section
48
+ #
49
+ # @return [ActiveSupport::SafeBuffer]
50
50
 
51
- def render
52
- tag.div(class: "govuk-accordion__section #{'govuk-accordion__section--expanded' if section_is_expanded}".rstrip) do
53
- concat(header.render)
54
- concat(content.render)
51
+ def render
52
+ tag.div(class: "govuk-accordion__section #{'govuk-accordion__section--expanded' if section_is_expanded}".rstrip) do
53
+ concat(header.render)
54
+ concat(content.render)
55
+ end
55
56
  end
56
57
  end
57
58
  end
@@ -1,56 +1,58 @@
1
1
  require_relative '../base'
2
2
  require_relative 'accordion/section'
3
3
 
4
- module CCS::Components
5
- module GovUK
6
- # = GOV.UK Accordion
7
- #
8
- # This is used for generating the accordion component from the
9
- # {https://design-system.service.gov.uk/accordion/back-link GDS - Components - Accordion}
10
- #
11
- # @!attribute [r] accordion_sections
12
- # @return [Array<Section>] An array of the initialised accordion sections
13
-
14
- class Accordion < Base
15
- private
16
-
17
- attr_reader :accordion_sections
18
-
19
- public
20
-
21
- # @param accordion_id [String] used as an id in the HTML for the accordion as a whole,
22
- # and also as a prefix for the ids of the section contents
23
- # and the buttons that open them
24
- # @param accordion_sections [Array<Hash>] an array of accordion section attributes.
25
- # See {Components::GovUK::Accordion::Section#initialize Section#initialize} for details of the items in the array.
26
- # @param options [Hash] options that will be used in customising the HTML
4
+ module CCS
5
+ module Components
6
+ module GovUK
7
+ # = GOV.UK Accordion
27
8
  #
28
- # @option options [String] :classes additional CSS classes for the accordion HTML
29
- # @option options [Integer] :heading_level (2) heading level, from 1 to 6
30
- # @option options [Hash] :attributes any additional attributes that will added as part of the HTML
9
+ # This is used for generating the accordion component from the
10
+ # {https://design-system.service.gov.uk/accordion/back-link GDS - Components - Accordion}
11
+ #
12
+ # @!attribute [r] accordion_sections
13
+ # @return [Array<Section>] An array of the initialised accordion sections
31
14
 
32
- def initialize(accordion_id:, accordion_sections:, **options)
33
- super(**options)
15
+ class Accordion < Base
16
+ private
34
17
 
35
- @options[:attributes][:id] = accordion_id
36
- @options[:heading_level] ||= 2
18
+ attr_reader :accordion_sections
37
19
 
38
- @accordion_sections = accordion_sections.map.with_index(1) { |accordion_section, index| Section.new(section: accordion_section, accordion_id: accordion_id, index: index, heading_level: @options[:heading_level]) }
39
- end
20
+ public
40
21
 
41
- # Generates the HTML for the GOV.UK Accordion component
42
- #
43
- # @return [ActiveSupport::SafeBuffer]
22
+ # @param accordion_id [String] used as an id in the HTML for the accordion as a whole,
23
+ # and also as a prefix for the ids of the section contents
24
+ # and the buttons that open them
25
+ # @param accordion_sections [Array<Hash>] an array of accordion section attributes.
26
+ # See {Components::GovUK::Accordion::Section#initialize Section#initialize} for details of the items in the array.
27
+ # @param options [Hash] options that will be used in customising the HTML
28
+ #
29
+ # @option options [String] :classes additional CSS classes for the accordion HTML
30
+ # @option options [Integer] :heading_level (2) heading level, from 1 to 6
31
+ # @option options [Hash] :attributes any additional attributes that will added as part of the HTML
32
+
33
+ def initialize(accordion_id:, accordion_sections:, **options)
34
+ super(**options)
35
+
36
+ @options[:attributes][:id] = accordion_id
37
+ @options[:heading_level] ||= 2
44
38
 
45
- def render
46
- tag.div(**options[:attributes]) do
47
- accordion_sections.each { |accordion_section| concat(accordion_section.render) }
39
+ @accordion_sections = accordion_sections.map.with_index(1) { |accordion_section, index| Section.new(section: accordion_section, accordion_id: accordion_id, index: index, heading_level: @options[:heading_level]) }
48
40
  end
49
- end
50
41
 
51
- # The default attributes for the accordion
42
+ # Generates the HTML for the GOV.UK Accordion component
43
+ #
44
+ # @return [ActiveSupport::SafeBuffer]
45
+
46
+ def render
47
+ tag.div(**options[:attributes]) do
48
+ accordion_sections.each { |accordion_section| concat(accordion_section.render) }
49
+ end
50
+ end
52
51
 
53
- DEFAULT_ATTRIBUTES = { class: 'govuk-accordion', data: { module: 'govuk-accordion' } }.freeze
52
+ # The default attributes for the accordion
53
+
54
+ DEFAULT_ATTRIBUTES = { class: 'govuk-accordion', data: { module: 'govuk-accordion' } }.freeze
55
+ end
54
56
  end
55
57
  end
56
58
  end
@@ -1,49 +1,51 @@
1
1
  require_relative '../base'
2
2
 
3
- module CCS::Components
4
- module GovUK
5
- # = GOV.UK Back Link
6
- #
7
- # This is used to generate the back link component from the
8
- # {https://design-system.service.gov.uk/components/back-link GDS - Components - Back link}
9
- #
10
- # @!attribute [r] text
11
- # @return [String] Text for the back link
12
- # @!attribute [r] href
13
- # @return [String] The href for the back link
14
-
15
- class BackLink < Base
16
- private
17
-
18
- attr_reader :text, :href
19
-
20
- public
21
-
22
- # @param text [String] the text for the back link
23
- # @param href [String] the href for the back link
24
- # @param options [Hash] options that will be used in customising the HTML
3
+ module CCS
4
+ module Components
5
+ module GovUK
6
+ # = GOV.UK Back Link
25
7
  #
26
- # @option options [String] :classes additional CSS classes for the back link HTML
27
- # @option options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
8
+ # This is used to generate the back link component from the
9
+ # {https://design-system.service.gov.uk/components/back-link GDS - Components - Back link}
10
+ #
11
+ # @!attribute [r] text
12
+ # @return [String] Text for the back link
13
+ # @!attribute [r] href
14
+ # @return [String] The href for the back link
28
15
 
29
- def initialize(text:, href:, **options)
30
- super(**options)
16
+ class BackLink < Base
17
+ private
31
18
 
32
- @text = text
33
- @href = href
34
- end
19
+ attr_reader :text, :href
35
20
 
36
- # Generates the HTML for the GOV.UK Back link component
37
- #
38
- # @return [ActiveSupport::SafeBuffer]
21
+ public
39
22
 
40
- def render
41
- link_to(text, href, **options[:attributes])
42
- end
23
+ # @param text [String] the text for the back link
24
+ # @param href [String] the href for the back link
25
+ # @param options [Hash] options that will be used in customising the HTML
26
+ #
27
+ # @option options [String] :classes additional CSS classes for the back link HTML
28
+ # @option options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
29
+
30
+ def initialize(text:, href:, **options)
31
+ super(**options)
43
32
 
44
- # The default attributes for the back link
33
+ @text = text
34
+ @href = href
35
+ end
45
36
 
46
- DEFAULT_ATTRIBUTES = { class: 'govuk-back-link' }.freeze
37
+ # Generates the HTML for the GOV.UK Back link component
38
+ #
39
+ # @return [ActiveSupport::SafeBuffer]
40
+
41
+ def render
42
+ link_to(text, href, **options[:attributes])
43
+ end
44
+
45
+ # The default attributes for the back link
46
+
47
+ DEFAULT_ATTRIBUTES = { class: 'govuk-back-link' }.freeze
48
+ end
47
49
  end
48
50
  end
49
51
  end
@@ -1,52 +1,54 @@
1
1
  require_relative '../../base'
2
2
 
3
- module CCS::Components
4
- module GovUK
5
- class Breadcrumbs < Base
6
- # = GOV.UK Breadcrumbs Link
7
- #
8
- # The individual list item for the breadcrumbs
9
- #
10
- # @!attribute [r] text
11
- # @return [String] Text for the breadcrumb link
12
- # @!attribute [r] href
13
- # @return [String] The href for the breadcrumb link
14
-
15
- class Link < Base
16
- private
17
-
18
- attr_reader :text, :href
19
-
20
- public
21
-
22
- # @param text [String] the text for the breadcrumb link
23
- # @param href [String] the href for the breadcrumb link.
24
- # If blank it is assumed that this item relates to current page
25
- # @param options [Hash] options that will be used in customising the HTML
3
+ module CCS
4
+ module Components
5
+ module GovUK
6
+ class Breadcrumbs < Base
7
+ # = GOV.UK Breadcrumbs Link
26
8
  #
27
- # @option options [Hash] :attributes any additional attributes that will added as part of the HTML.
28
- # If the link is blank then it defaults to +{ aria: { current: 'page' } }+
9
+ # The individual list item for the breadcrumbs
10
+ #
11
+ # @!attribute [r] text
12
+ # @return [String] Text for the breadcrumb link
13
+ # @!attribute [r] href
14
+ # @return [String] The href for the breadcrumb link
29
15
 
30
- def initialize(text:, href: nil, **options)
31
- super(**options)
16
+ class Link < Base
17
+ private
32
18
 
33
- @text = text
34
- @href = href
35
- end
19
+ attr_reader :text, :href
36
20
 
37
- # Generates the HTML for the GOV.UK Breadcrumbs link
38
- #
39
- # @return [ActiveSupport::SafeBuffer]
21
+ public
22
+
23
+ # @param text [String] the text for the breadcrumb link
24
+ # @param href [String] the href for the breadcrumb link.
25
+ # If blank it is assumed that this item relates to current page
26
+ # @param options [Hash] options that will be used in customising the HTML
27
+ #
28
+ # @option options [Hash] :attributes any additional attributes that will added as part of the HTML.
29
+ # If the link is blank then it defaults to +{ aria: { current: 'page' } }+
30
+
31
+ def initialize(text:, href: nil, **options)
32
+ super(**options)
33
+
34
+ @text = text
35
+ @href = href
36
+ end
37
+
38
+ # Generates the HTML for the GOV.UK Breadcrumbs link
39
+ #
40
+ # @return [ActiveSupport::SafeBuffer]
40
41
 
41
- def render
42
- if href.present?
43
- options[:attributes][:class] = 'govuk-breadcrumbs__link'
42
+ def render
43
+ if href.present?
44
+ options[:attributes][:class] = 'govuk-breadcrumbs__link'
44
45
 
45
- tag.li(class: 'govuk-breadcrumbs__list-item') do
46
- link_to(text, href, **options[:attributes])
46
+ tag.li(class: 'govuk-breadcrumbs__list-item') do
47
+ link_to(text, href, **options[:attributes])
48
+ end
49
+ else
50
+ tag.li(text, class: 'govuk-breadcrumbs__list-item', aria: { current: 'page' })
47
51
  end
48
- else
49
- tag.li(text, class: 'govuk-breadcrumbs__list-item', aria: { current: 'page' })
50
52
  end
51
53
  end
52
54
  end
@@ -1,53 +1,55 @@
1
1
  require_relative '../base'
2
2
  require_relative 'breadcrumbs/link'
3
3
 
4
- module CCS::Components
5
- module GovUK
6
- # = GOV.UK Breadcrumbs
7
- #
8
- # This is used to generate the breadcrumbs component from the
9
- # {https://design-system.service.gov.uk/components/breadcrumbs GDS - Components - Breadcrumbs}
10
- #
11
- # @!attribute [r] breadcrumb_links
12
- # @return [Array<Link>] An array of the initialised breadcrumb links
13
-
14
- class Breadcrumbs < Base
15
- private
16
-
17
- attr_reader :breadcrumb_links
18
-
19
- public
20
-
21
- # @param breadcrumb_links [Array<Hash>] An array of links for the breadcrumbs list.
22
- # See {Components::GovUK::Breadcrumbs::Link#initialize Link#initialize} for details of the items in the array.
23
- # @param options [Hash] options that will be used in customising the HTML
4
+ module CCS
5
+ module Components
6
+ module GovUK
7
+ # = GOV.UK Breadcrumbs
24
8
  #
25
- # @option options [String] :classes additional CSS classes for the breadcrumbs HTML
26
- # @option options [Boolean] :collapse_on_mobile indicates if it is to colapse breadcrumbs on mobile
27
- # @option options [Hash] :attributes any additional attributes that will added as part of the HTML
9
+ # This is used to generate the breadcrumbs component from the
10
+ # {https://design-system.service.gov.uk/components/breadcrumbs GDS - Components - Breadcrumbs}
11
+ #
12
+ # @!attribute [r] breadcrumb_links
13
+ # @return [Array<Link>] An array of the initialised breadcrumb links
28
14
 
29
- def initialize(breadcrumb_links:, **options)
30
- super(**options)
31
- @options[:attributes][:class] << ' govuk-breadcrumbs--collapse-on-mobile' if @options[:collapse_on_mobile]
15
+ class Breadcrumbs < Base
16
+ private
32
17
 
33
- @breadcrumb_links = breadcrumb_links.map { |breadcrumb_link| Link.new(context: @context, **breadcrumb_link) }
34
- end
18
+ attr_reader :breadcrumb_links
35
19
 
36
- # Generates the HTML for the GOV.UK breadcrumbs component
37
- #
38
- # @return [ActiveSupport::SafeBuffer]
20
+ public
21
+
22
+ # @param breadcrumb_links [Array<Hash>] An array of links for the breadcrumbs list.
23
+ # See {Components::GovUK::Breadcrumbs::Link#initialize Link#initialize} for details of the items in the array.
24
+ # @param options [Hash] options that will be used in customising the HTML
25
+ #
26
+ # @option options [String] :classes additional CSS classes for the breadcrumbs HTML
27
+ # @option options [Boolean] :collapse_on_mobile indicates if it is to colapse breadcrumbs on mobile
28
+ # @option options [Hash] :attributes any additional attributes that will added as part of the HTML
29
+
30
+ def initialize(breadcrumb_links:, **options)
31
+ super(**options)
32
+ @options[:attributes][:class] << ' govuk-breadcrumbs--collapse-on-mobile' if @options[:collapse_on_mobile]
39
33
 
40
- def render
41
- tag.div(**options[:attributes]) do
42
- tag.ol(class: 'govuk-breadcrumbs__list') do
43
- breadcrumb_links.each { |breadcrumb_link| concat(breadcrumb_link.render) }
34
+ @breadcrumb_links = breadcrumb_links.map { |breadcrumb_link| Link.new(context: @context, **breadcrumb_link) }
35
+ end
36
+
37
+ # Generates the HTML for the GOV.UK breadcrumbs component
38
+ #
39
+ # @return [ActiveSupport::SafeBuffer]
40
+
41
+ def render
42
+ tag.div(**options[:attributes]) do
43
+ tag.ol(class: 'govuk-breadcrumbs__list') do
44
+ breadcrumb_links.each { |breadcrumb_link| concat(breadcrumb_link.render) }
45
+ end
44
46
  end
45
47
  end
46
- end
47
48
 
48
- # The default attributes for the breadcrumbs
49
+ # The default attributes for the breadcrumbs
49
50
 
50
- DEFAULT_ATTRIBUTES = { class: 'govuk-breadcrumbs' }.freeze
51
+ DEFAULT_ATTRIBUTES = { class: 'govuk-breadcrumbs' }.freeze
52
+ end
51
53
  end
52
54
  end
53
55
  end