ccs-frontend_helpers 0.1.0.rc.7 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (157) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -5
  3. data/CHANGELOG.md +2 -4
  4. data/Gemfile +1 -15
  5. data/Gemfile.lock +80 -81
  6. data/ccs-frontend_helpers.gemspec +10 -0
  7. data/lib/ccs/frontend_helpers/ccs_frontend/dashboard_panels.rb +79 -0
  8. data/lib/ccs/frontend_helpers/ccs_frontend/footer.rb +119 -6
  9. data/lib/ccs/frontend_helpers/ccs_frontend/header.rb +183 -6
  10. data/lib/ccs/{components/ccs → frontend_helpers/ccs_frontend}/logo.rb +12 -10
  11. data/lib/ccs/frontend_helpers/ccs_frontend.rb +4 -2
  12. data/lib/ccs/frontend_helpers/govuk_frontend/accordion.rb +95 -8
  13. data/lib/ccs/frontend_helpers/govuk_frontend/back_link.rb +17 -6
  14. data/lib/ccs/frontend_helpers/govuk_frontend/breadcrumbs.rb +54 -6
  15. data/lib/ccs/frontend_helpers/govuk_frontend/button.rb +105 -6
  16. data/lib/ccs/frontend_helpers/govuk_frontend/cookie_banner.rb +114 -6
  17. data/lib/ccs/frontend_helpers/govuk_frontend/details.rb +23 -7
  18. data/lib/ccs/frontend_helpers/govuk_frontend/error_message.rb +32 -11
  19. data/lib/ccs/frontend_helpers/govuk_frontend/error_summary.rb +65 -13
  20. data/lib/ccs/frontend_helpers/govuk_frontend/field/character_count.rb +165 -0
  21. data/lib/ccs/frontend_helpers/govuk_frontend/field/checkboxes.rb +200 -0
  22. data/lib/ccs/frontend_helpers/govuk_frontend/field/date_input.rb +153 -0
  23. data/lib/ccs/frontend_helpers/govuk_frontend/field/file_upload.rb +83 -0
  24. data/lib/ccs/frontend_helpers/govuk_frontend/field/input.rb +153 -0
  25. data/lib/ccs/frontend_helpers/govuk_frontend/field/radios.rb +201 -0
  26. data/lib/ccs/frontend_helpers/govuk_frontend/field/select.rb +124 -0
  27. data/lib/ccs/frontend_helpers/govuk_frontend/field/textarea.rb +106 -0
  28. data/lib/ccs/frontend_helpers/govuk_frontend/field.rb +213 -0
  29. data/lib/ccs/frontend_helpers/govuk_frontend/fieldset.rb +48 -7
  30. data/lib/ccs/frontend_helpers/govuk_frontend/footer.rb +161 -6
  31. data/lib/ccs/frontend_helpers/govuk_frontend/form_group.rb +24 -13
  32. data/lib/ccs/frontend_helpers/govuk_frontend/header.rb +139 -6
  33. data/lib/ccs/frontend_helpers/govuk_frontend/hint.rb +17 -8
  34. data/lib/ccs/frontend_helpers/govuk_frontend/inset_text.rb +21 -7
  35. data/lib/ccs/frontend_helpers/govuk_frontend/label.rb +70 -7
  36. data/lib/ccs/frontend_helpers/govuk_frontend/notification_banner.rb +113 -7
  37. data/lib/ccs/frontend_helpers/govuk_frontend/pagination.rb +314 -6
  38. data/lib/ccs/frontend_helpers/govuk_frontend/panel.rb +28 -7
  39. data/lib/ccs/frontend_helpers/govuk_frontend/phase_banner.rb +27 -8
  40. data/lib/ccs/frontend_helpers/govuk_frontend/skip_link.rb +18 -6
  41. data/lib/ccs/frontend_helpers/govuk_frontend/step_by_step_navigation.rb +186 -7
  42. data/lib/ccs/frontend_helpers/govuk_frontend/summary_list.rb +204 -6
  43. data/lib/ccs/frontend_helpers/govuk_frontend/table.rb +100 -11
  44. data/lib/ccs/frontend_helpers/govuk_frontend/tabs.rb +73 -6
  45. data/lib/ccs/frontend_helpers/govuk_frontend/tag.rb +21 -7
  46. data/lib/ccs/frontend_helpers/govuk_frontend/warning_text.rb +30 -7
  47. data/lib/ccs/frontend_helpers/govuk_frontend.rb +19 -17
  48. data/lib/ccs/frontend_helpers/shared_methods.rb +27 -0
  49. data/lib/ccs/frontend_helpers/version.rb +1 -1
  50. metadata +142 -112
  51. data/.ruby-version +0 -1
  52. data/lib/ccs/components/base.rb +0 -64
  53. data/lib/ccs/components/ccs/dashboard_section/panel.rb +0 -57
  54. data/lib/ccs/components/ccs/dashboard_section.rb +0 -71
  55. data/lib/ccs/components/ccs/footer/link.rb +0 -55
  56. data/lib/ccs/components/ccs/footer/meta.rb +0 -59
  57. data/lib/ccs/components/ccs/footer/navigation.rb +0 -60
  58. data/lib/ccs/components/ccs/footer.rb +0 -95
  59. data/lib/ccs/components/ccs/header/link.rb +0 -60
  60. data/lib/ccs/components/ccs/header/navigation.rb +0 -98
  61. data/lib/ccs/components/ccs/header/service_authentication.rb +0 -53
  62. data/lib/ccs/components/ccs/header.rb +0 -110
  63. data/lib/ccs/components/govuk/accordion/section/content.rb +0 -53
  64. data/lib/ccs/components/govuk/accordion/section/header.rb +0 -57
  65. data/lib/ccs/components/govuk/accordion/section.rb +0 -61
  66. data/lib/ccs/components/govuk/accordion.rb +0 -58
  67. data/lib/ccs/components/govuk/back_link.rb +0 -51
  68. data/lib/ccs/components/govuk/breadcrumbs/link.rb +0 -57
  69. data/lib/ccs/components/govuk/breadcrumbs.rb +0 -55
  70. data/lib/ccs/components/govuk/button.rb +0 -107
  71. data/lib/ccs/components/govuk/cookie_banner/action.rb +0 -60
  72. data/lib/ccs/components/govuk/cookie_banner/message.rb +0 -80
  73. data/lib/ccs/components/govuk/cookie_banner.rb +0 -55
  74. data/lib/ccs/components/govuk/details.rb +0 -53
  75. data/lib/ccs/components/govuk/error_message.rb +0 -60
  76. data/lib/ccs/components/govuk/error_summary/item.rb +0 -54
  77. data/lib/ccs/components/govuk/error_summary.rb +0 -70
  78. data/lib/ccs/components/govuk/field/input/character_count.rb +0 -129
  79. data/lib/ccs/components/govuk/field/input/file_upload.rb +0 -44
  80. data/lib/ccs/components/govuk/field/input/select.rb +0 -82
  81. data/lib/ccs/components/govuk/field/input/text_input/fix.rb +0 -55
  82. data/lib/ccs/components/govuk/field/input/text_input.rb +0 -97
  83. data/lib/ccs/components/govuk/field/input/textarea.rb +0 -59
  84. data/lib/ccs/components/govuk/field/input.rb +0 -62
  85. data/lib/ccs/components/govuk/field/inputs/checkboxes.rb +0 -69
  86. data/lib/ccs/components/govuk/field/inputs/date_input/item.rb +0 -65
  87. data/lib/ccs/components/govuk/field/inputs/date_input.rb +0 -89
  88. data/lib/ccs/components/govuk/field/inputs/item/checkbox/form.rb +0 -47
  89. data/lib/ccs/components/govuk/field/inputs/item/checkbox/tag.rb +0 -43
  90. data/lib/ccs/components/govuk/field/inputs/item/checkbox.rb +0 -50
  91. data/lib/ccs/components/govuk/field/inputs/item/divider.rb +0 -50
  92. data/lib/ccs/components/govuk/field/inputs/item/radio/form.rb +0 -44
  93. data/lib/ccs/components/govuk/field/inputs/item/radio/tag.rb +0 -43
  94. data/lib/ccs/components/govuk/field/inputs/item/radio.rb +0 -50
  95. data/lib/ccs/components/govuk/field/inputs/item.rb +0 -111
  96. data/lib/ccs/components/govuk/field/inputs/radios.rb +0 -69
  97. data/lib/ccs/components/govuk/field/inputs.rb +0 -57
  98. data/lib/ccs/components/govuk/field.rb +0 -108
  99. data/lib/ccs/components/govuk/fieldset/legend.rb +0 -65
  100. data/lib/ccs/components/govuk/fieldset.rb +0 -54
  101. data/lib/ccs/components/govuk/footer/link.rb +0 -55
  102. data/lib/ccs/components/govuk/footer/meta.rb +0 -59
  103. data/lib/ccs/components/govuk/footer/navigation.rb +0 -60
  104. data/lib/ccs/components/govuk/footer.rb +0 -131
  105. data/lib/ccs/components/govuk/form_group.rb +0 -60
  106. data/lib/ccs/components/govuk/header/link.rb +0 -56
  107. data/lib/ccs/components/govuk/header/navigation.rb +0 -71
  108. data/lib/ccs/components/govuk/header.rb +0 -107
  109. data/lib/ccs/components/govuk/hint.rb +0 -49
  110. data/lib/ccs/components/govuk/inset_text.rb +0 -52
  111. data/lib/ccs/components/govuk/label.rb +0 -85
  112. data/lib/ccs/components/govuk/notification_banner.rb +0 -107
  113. data/lib/ccs/components/govuk/pagination/increment/next.rb +0 -44
  114. data/lib/ccs/components/govuk/pagination/increment/previous.rb +0 -43
  115. data/lib/ccs/components/govuk/pagination/increment.rb +0 -98
  116. data/lib/ccs/components/govuk/pagination/item/ellipsis.rb +0 -28
  117. data/lib/ccs/components/govuk/pagination/item/form.rb +0 -49
  118. data/lib/ccs/components/govuk/pagination/item/tag.rb +0 -47
  119. data/lib/ccs/components/govuk/pagination/item.rb +0 -64
  120. data/lib/ccs/components/govuk/pagination.rb +0 -96
  121. data/lib/ccs/components/govuk/panel.rb +0 -62
  122. data/lib/ccs/components/govuk/phase_banner.rb +0 -69
  123. data/lib/ccs/components/govuk/skip_link.rb +0 -51
  124. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list/item.rb +0 -53
  125. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list.rb +0 -50
  126. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/paragraph.rb +0 -45
  127. data/lib/ccs/components/govuk/step_by_step_navigation/section/content.rb +0 -63
  128. data/lib/ccs/components/govuk/step_by_step_navigation/section/heading.rb +0 -69
  129. data/lib/ccs/components/govuk/step_by_step_navigation/section.rb +0 -56
  130. data/lib/ccs/components/govuk/step_by_step_navigation.rb +0 -59
  131. data/lib/ccs/components/govuk/summary_list/action/link.rb +0 -59
  132. data/lib/ccs/components/govuk/summary_list/card/actions.rb +0 -59
  133. data/lib/ccs/components/govuk/summary_list/card/title.rb +0 -51
  134. data/lib/ccs/components/govuk/summary_list/card.rb +0 -63
  135. data/lib/ccs/components/govuk/summary_list/row/actions.rb +0 -59
  136. data/lib/ccs/components/govuk/summary_list/row/key.rb +0 -47
  137. data/lib/ccs/components/govuk/summary_list/row/value.rb +0 -47
  138. data/lib/ccs/components/govuk/summary_list/row.rb +0 -67
  139. data/lib/ccs/components/govuk/summary_list.rb +0 -74
  140. data/lib/ccs/components/govuk/table/body/data_cell.rb +0 -53
  141. data/lib/ccs/components/govuk/table/body/head_cell.rb +0 -52
  142. data/lib/ccs/components/govuk/table/header/head_cell.rb +0 -54
  143. data/lib/ccs/components/govuk/table.rb +0 -111
  144. data/lib/ccs/components/govuk/tabs/panel.rb +0 -58
  145. data/lib/ccs/components/govuk/tabs/tab.rb +0 -56
  146. data/lib/ccs/components/govuk/tabs.rb +0 -66
  147. data/lib/ccs/components/govuk/tag.rb +0 -51
  148. data/lib/ccs/components/govuk/warning_text.rb +0 -61
  149. data/lib/ccs/frontend_helpers/ccs_frontend/dashboard_section.rb +0 -27
  150. data/lib/ccs/frontend_helpers/govuk_frontend/character_count.rb +0 -28
  151. data/lib/ccs/frontend_helpers/govuk_frontend/checkboxes.rb +0 -28
  152. data/lib/ccs/frontend_helpers/govuk_frontend/date_input.rb +0 -28
  153. data/lib/ccs/frontend_helpers/govuk_frontend/file_upload.rb +0 -28
  154. data/lib/ccs/frontend_helpers/govuk_frontend/input.rb +0 -28
  155. data/lib/ccs/frontend_helpers/govuk_frontend/radios.rb +0 -28
  156. data/lib/ccs/frontend_helpers/govuk_frontend/select.rb +0 -28
  157. data/lib/ccs/frontend_helpers/govuk_frontend/textarea.rb +0 -28
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../../components/govuk/fieldset'
3
+ require 'action_view'
4
+
5
+ require_relative '../shared_methods'
4
6
 
5
7
  module CCS
6
8
  module FrontendHelpers
@@ -11,18 +13,57 @@ module CCS
11
13
  # {https://design-system.service.gov.uk/components/fieldset GDS - Components - Fieldset}
12
14
 
13
15
  module Fieldset
16
+ include SharedMethods
17
+ include ActionView::Context
18
+ include ActionView::Helpers::TagHelper
19
+ include ActionView::Helpers::TextHelper
20
+
14
21
  # Generates the HTML for the GOV.UK Fieldset component
15
22
  #
16
- # @param (see CCS::Components::GovUK::Fieldset#initialize)
23
+ # @param govuk_fieldset_options [Hash] options that will be used in customising the HTML
24
+ #
25
+ # @option govuk_fieldset_options [String] :classes additional CSS classes for the fieldset HTML
26
+ # @option govuk_fieldset_options [Hash] :legend options for the legend which are used in {#govuk_legend}
27
+ # @option govuk_fieldset_options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
28
+ #
29
+ # @yield HTML that will be contained within the 'govuk-fieldset' div and under the legend
30
+ #
31
+ # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Fieldset
32
+ # which can then be rendered on the page
33
+
34
+ def govuk_fieldset(**govuk_fieldset_options)
35
+ initialise_attributes_and_set_classes(govuk_fieldset_options, 'govuk-fieldset')
36
+
37
+ tag.fieldset(**govuk_fieldset_options[:attributes]) do
38
+ concat(govuk_legend(govuk_fieldset_options[:legend])) if govuk_fieldset_options[:legend]
39
+ yield
40
+ end
41
+ end
42
+
43
+ private
44
+
45
+ # Generates the HTML for the Legend as part of {#govuk_fieldset}
17
46
  #
18
- # @option (see CCS::Components::GovUK::Fieldset#initialize)
47
+ # @param govuk_legend_options [Hash] options that will be used in the legend
19
48
  #
20
- # @yield (see CCS::Components::GovUK::Fieldset#render)
49
+ # @option govuk_legend_options [String] :classes additional CSS classes for the legend HTML
50
+ # @option govuk_legend_options [String] :text the text for the legend
51
+ # @option govuk_legend_options [boolean] :is_page_heading (false) if the legend is also the heading it will rendered in a h1
52
+ # @option govuk_legend_options [Hash] :caption an optional hash with the +text+ and +classes+ that will be used
53
+ # to render a caption before the h1 if the legend is a page heading
21
54
  #
22
- # @return (see CCS::Components::GovUK::Fieldset#render)
55
+ # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Fieldset
56
+ # which can then be rendered on the page
23
57
 
24
- def govuk_fieldset(**options, &block)
25
- Components::GovUK::Fieldset.new(context: self, **options).render(&block)
58
+ def govuk_legend(govuk_legend_options)
59
+ tag.legend(class: "govuk-fieldset__legend #{govuk_legend_options[:classes]}".rstrip) do
60
+ if govuk_legend_options[:is_page_heading]
61
+ concat(tag.span(govuk_legend_options[:caption][:text], class: govuk_legend_options[:caption][:classes])) if govuk_legend_options[:caption]
62
+ concat(tag.h1(govuk_legend_options[:text], class: 'govuk-fieldset__heading'))
63
+ else
64
+ govuk_legend_options[:text]
65
+ end
66
+ end
26
67
  end
27
68
  end
28
69
  end
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../../components/govuk/footer'
3
+ require 'action_view'
4
+
5
+ require_relative '../shared_methods'
4
6
 
5
7
  module CCS
6
8
  module FrontendHelpers
@@ -11,16 +13,169 @@ module CCS
11
13
  # {https://design-system.service.gov.uk/components/footer GDS - Components - Footer}
12
14
 
13
15
  module Footer
16
+ include SharedMethods
17
+ include ActionView::Context
18
+ include ActionView::Helpers::FormTagHelper
19
+ include ActionView::Helpers::TagHelper
20
+ include ActionView::Helpers::TextHelper
21
+ include ActionView::Helpers::UrlHelper
22
+
23
+ # rubocop:disable Metrics/AbcSize
24
+
14
25
  # Generates the HTML for the GOV.UK Footer component
15
26
  #
16
- # @param (see CCS::Components::GovUK::Footer#initialize)
27
+ # @param govuk_footer_options [Hash] options that will be used in customising the HTML
28
+ #
29
+ # @option govuk_footer_options [String] :classes additional CSS classes for the footer HTML
30
+ # @option govuk_footer_options [String] :container_class classes that can be added to the inner container
31
+ # @option govuk_footer_options [Array] :navigation (see: {govuk_footer_navigation})
32
+ # @option govuk_footer_options [Hash] :meta (see: {govuk_footer_meta})
33
+ # @option govuk_footer_options [ActiveSupport::SafeBuffer,String] :content_licence The content licence information. See {govuk_footer_content_licence}
34
+ # @option govuk_footer_options [ActiveSupport::SafeBuffer,String] :copyright The copyright information. See {govuk_footer_copyright}
35
+ # @option govuk_footer_options [Hash] :attributes additional attributes that will added as part of the HTML
36
+ #
37
+ # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Footer
38
+ # which can then be rendered on the page
39
+
40
+ def govuk_footer(**govuk_footer_options)
41
+ initialise_attributes_and_set_classes(govuk_footer_options, 'govuk-footer')
42
+
43
+ govuk_footer_options[:attributes][:role] = 'contentinfo'
44
+
45
+ tag.footer(**govuk_footer_options[:attributes]) do
46
+ tag.div(class: "govuk-width-container #{govuk_footer_options[:container_classes]}".rstrip) do
47
+ if govuk_footer_options[:navigation]
48
+ concat(tag.div(class: 'govuk-footer__navigation') do
49
+ govuk_footer_options[:navigation].each { |navigation_item| concat(govuk_footer_navigation(navigation_item)) }
50
+ end)
51
+ concat(tag.hr(class: 'govuk-footer__section-break'))
52
+ end
53
+ concat(tag.div(class: 'govuk-footer__meta') do
54
+ concat(tag.div(class: 'govuk-footer__meta-item govuk-footer__meta-item--grow') do
55
+ concat(govuk_footer_meta(govuk_footer_options[:meta])) if govuk_footer_options[:meta]
56
+ concat(govuk_footer_logo)
57
+ concat(govuk_footer_content_licence(govuk_footer_options[:content_licence]))
58
+ end)
59
+ concat(govuk_footer_copyright(govuk_footer_options[:copyright]))
60
+ end)
61
+ end
62
+ end
63
+ end
64
+
65
+ private
66
+
67
+ # Generates the HTML for the navigation section in {govuk_footer}
68
+ #
69
+ # @param navigation_item [Hash] options that will be used for the navigation section
70
+ #
71
+ # @option navigation_item [String] :title title for a section
72
+ # @option navigation_item [String] :width (default: 'fall') width of each navigation section in the footer
73
+ # @option navigation_item [Integer] :columns amount of columns to display items in navigation section of the footer
74
+ # @option navigation_item [Array] :items array of items to display in the list in navigation section of the footer.
75
+ # Each item can have the following options:
76
+ # - +:text+ list item text
77
+ # - +:href+ list item href
78
+ # - +:attributes+ HTML attributes to add to the link
79
+ #
80
+ # @return [ActiveSupport::SafeBuffer] the HTML for the navigation section in {govuk_footer}
81
+
82
+ def govuk_footer_navigation(navigation_item)
83
+ tag.div(class: "govuk-footer__section govuk-grid-column-#{navigation_item[:width] || 'full'}") do
84
+ concat(tag.h2(navigation_item[:title], class: 'govuk-footer__heading govuk-heading-m'))
85
+ concat(tag.ul(class: "govuk-footer__list #{"govuk-footer__list--columns-#{navigation_item[:columns]}" if navigation_item[:columns]}".rstrip) do
86
+ navigation_item[:items].each do |item|
87
+ concat(tag.li(class: 'govuk-footer__list-item') do
88
+ (item[:attributes] ||= {})[:class] = 'govuk-footer__link'
89
+
90
+ link_to(item[:text], item[:href], **item[:attributes])
91
+ end)
92
+ end
93
+ end)
94
+ end
95
+ end
96
+
97
+ # Generates the HTML for the meta section in {govuk_footer}
98
+ #
99
+ # @param meta [Hash] options that will be used for the meta section
100
+ #
101
+ # @option meta [String] :visually_hidden_title (default: 'Support links') title for a meta item section
102
+ # @option meta [ActiveSupport::SafeBuffer,String] :text text to add to the meta section of the footer,
103
+ # which will appear below any links specified using meta.items
104
+ # @option meta [Array] :items array of items to display in the list in meta section of the footer.
105
+ # Each item can have the following options:
106
+ # - +:text+ list item text
107
+ # - +:href+ list item href
108
+ # - +:attributes+ HTML attributes to add to the link
109
+ #
110
+ # @return [ActiveSupport::SafeBuffer] the HTML for the meta section in {govuk_footer}
111
+
112
+ def govuk_footer_meta(meta)
113
+ concat(tag.h2(meta[:visually_hidden_title] || 'Support links', class: 'govuk-visually-hidden'))
114
+ if meta[:items]
115
+ concat(tag.ul(class: 'govuk-footer__inline-list') do
116
+ meta[:items].each do |meta_item|
117
+ concat(tag.li(class: 'govuk-footer__inline-list-item') do
118
+ (meta_item[:attributes] ||= {})[:class] = 'govuk-footer__link'
119
+
120
+ link_to(meta_item[:text], meta_item[:href], **meta_item[:attributes])
121
+ end)
122
+ end
123
+ end)
124
+ end
125
+ concat(tag.div(meta[:text], class: 'govuk-footer__meta-custom')) if meta[:text]
126
+ end
127
+
128
+ # rubocop:enable Metrics/AbcSize
129
+
130
+ # Generates the logo used in {govuk_footer}
131
+ #
132
+ # @return [ActiveSupport::SafeBuffer]
133
+
134
+ def govuk_footer_logo
135
+ tag.svg(
136
+ class: 'govuk-footer__licence-logo',
137
+ aria: { hidden: 'true' },
138
+ focusable: 'false',
139
+ xmlns: 'http://www.w3.org/2000/svg',
140
+ viewBox: '0 0 483.2 195.7',
141
+ height: '17',
142
+ width: '41'
143
+ ) do
144
+ tag.path(
145
+ fill: 'currentColor',
146
+ d: 'M421.5 142.8V.1l-50.7 32.3v161.1h112.4v-50.7zm-122.3-9.6A47.12 47.12 0 0 1 221 97.8c0-26 21.1-47.1 47.1-47.1 16.7 0 31.4 8.7 39.7 21.8l42.7-27.2A97.63 97.63 0 0 0 268.1 0c-36.5 0-68.3 20.1-85.1 49.7A98 98 0 0 0 97.8 0C43.9 0 0 43.9 0 97.8s43.9 97.8 97.8 97.8c36.5 0 68.3-20.1 85.1-49.7a97.76 97.76 0 0 0 149.6 25.4l19.4 22.2h3v-87.8h-80l24.3 27.5zM97.8 145c-26 0-47.1-21.1-47.1-47.1s21.1-47.1 47.1-47.1 47.2 21 47.2 47S123.8 145 97.8 145'
147
+ )
148
+ end
149
+ end
150
+
151
+ # Generates the content licence used in {govuk_footer}
152
+ #
153
+ # @param content_licence [ActiveSupport::SafeBuffer,String] the content licence information. Defaults to Open Government Licence (OGL) v3 licence
154
+ #
155
+ # @return [ActiveSupport::SafeBuffer] the HTML for the content licence used in {govuk_footer}
156
+
157
+ def govuk_footer_content_licence(content_licence)
158
+ tag.span(class: 'govuk-footer__licence-description') do
159
+ if content_licence
160
+ concat(content_licence)
161
+ else
162
+ concat('All content is available under the')
163
+ concat(link_to('Open Government Licence v3.0', 'https://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/', class: 'govuk-footer__link', rel: 'license'))
164
+ concat(', except where otherwise stated')
165
+ end
166
+ end
167
+ end
168
+
169
+ # Generates the copyright used in {govuk_footer}
17
170
  #
18
- # @option (see CCS::Components::GovUK::Footer#initialize)
171
+ # @param copyright [ActiveSupport::SafeBuffer,String] the copyright information, this defaults to Crown Copyright
19
172
  #
20
- # @return (see CCS::Components::GovUK::Footer#render)
173
+ # @return [ActiveSupport::SafeBuffer] the HTML for the copyright used in {govuk_footer}
21
174
 
22
- def govuk_footer(**options)
23
- Components::GovUK::Footer.new(context: self, **options).render
175
+ def govuk_footer_copyright(copyright)
176
+ tag.div(class: 'govuk-footer__meta-item') do
177
+ link_to(copyright || '© Crown copyright', 'https://www.nationalarchives.gov.uk/information-management/re-using-public-sector-information/uk-government-licensing-framework/crown-copyright/', class: 'govuk-footer__link govuk-footer__copyright-logo')
178
+ end
24
179
  end
25
180
  end
26
181
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../../components/govuk/form_group'
3
+ require_relative 'error_message'
4
4
 
5
5
  module CCS
6
6
  module FrontendHelpers
@@ -10,28 +10,39 @@ module CCS
10
10
  # This helper is used for generating the form group component from the Government Design Systems
11
11
 
12
12
  module FormGroup
13
- # Generates the HTML for the GOV.UK Warning text component
13
+ include ErrorMessage
14
+
15
+ # Generates the HTML for the GOV.UK Form Group component
14
16
  #
15
- # @param (see CCS::Components::GovUK::FormGroup#initialize)
17
+ # @param attribute [String, Symbol] the attribute that the form group is for
18
+ # @param govuk_form_group_options [Hash] options that will be used in customising the HTML
16
19
  #
17
- # @option options [String] :classes additional CSS classes for the form group HTML
18
- # @option options [ActiveModel] :model (nil) model that will be used to find an error message
19
- # @option options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
20
+ # @option govuk_form_group_options [String] :classes additional CSS classes for the form group HTML
21
+ # @option govuk_form_group_options [String] :error_message (nil) the error message to be displayed
22
+ # @option govuk_form_group_options [ActiveModel] :model (nil) model that will be used to find an error message
23
+ # @option govuk_form_group_options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
20
24
  #
21
- # @yield (see CCS::Components::GovUK::FormGroup#render)
25
+ # @yield HTML that will be contained within the 'govuk-form-group' div
22
26
  #
23
- # @yieldparam (see CCS::Components::GovUK::FormGroup#render)
27
+ # @yieldparam displayed_error_message [ActiveSupport::SafeBuffer] the HTML for the error message (if there is one)
24
28
  #
25
- # @return (see CCS::Components::GovUK::FormGroup#render)
29
+ # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Form Group
30
+ # which can then be rendered on the page
26
31
 
27
- def govuk_form_group(attribute, **options, &block)
28
- error_message = if options[:model]
32
+ def govuk_form_group(attribute, **govuk_form_group_options)
33
+ error_message = if govuk_form_group_options[:model]
29
34
  model.errors[attribute].first
30
35
  else
31
- options[:error_message]
36
+ govuk_form_group_options[:error_message]
32
37
  end
33
38
 
34
- Components::GovUK::FormGroup.new(context: self, attribute: attribute, error_message: error_message, **options).render(&block)
39
+ initialise_attributes_and_set_classes(govuk_form_group_options, "govuk-form-group #{'govuk-form-group--error' if error_message}".rstrip)
40
+
41
+ govuk_form_group_options[:attributes][:id] ||= "#{attribute}-form-group"
42
+
43
+ tag.div(**govuk_form_group_options[:attributes]) do
44
+ yield((govuk_error_message(error_message, attribute) if error_message))
45
+ end
35
46
  end
36
47
  end
37
48
  end
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../../components/govuk/header'
3
+ require 'action_view'
4
+
5
+ require_relative '../shared_methods'
4
6
 
5
7
  module CCS
6
8
  module FrontendHelpers
@@ -11,16 +13,147 @@ module CCS
11
13
  # {https://design-system.service.gov.uk/components/header GDS - Components - Header}
12
14
 
13
15
  module Header
16
+ include SharedMethods
17
+ include ActionView::Context
18
+ include ActionView::Helpers::FormTagHelper
19
+ include ActionView::Helpers::TagHelper
20
+ include ActionView::Helpers::TextHelper
21
+ include ActionView::Helpers::UrlHelper
22
+
14
23
  # Generates the HTML for the GOV.UK Header component
15
24
  #
16
- # @param (see CCS::Components::GovUK::Header#initialize)
25
+ # @param govuk_header_options [Hash] options that will be used to generate the header
26
+ #
27
+ # @option govuk_header_options [String] :classes additional CSS classes for the header HTML
28
+ # @option govuk_header_options [Hash] :attributes additional attributes that will added as part of the header HTML
29
+ # @option govuk_header_options [String] :container_classes classes for the container
30
+ # @option govuk_header_options [String] :homepage_url URL of the homepage. Defaults to +/+
31
+ # @option govuk_header_options [String] :product_name product name, used when the product name follows on directly from ‘GOV.UK
32
+ # @option govuk_header_options [Hash] :service see {govuk_header_service_name}
33
+ # @option govuk_header_options [Hash] :navigation see {govuk_header_navigation}
34
+ # @option govuk_header_options [Hash] :menu_button see {govuk_header_navigation}
35
+ #
36
+ # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Header
37
+ # which can then be rendered on the page
38
+
39
+ def govuk_header(**govuk_header_options)
40
+ determine_govuk_header_attributes(govuk_header_options)
41
+
42
+ tag.header(**govuk_header_options[:attributes]) do
43
+ tag.div(class: "govuk-header__container #{govuk_header_options[:container_classes] || 'govuk-width-container'}") do
44
+ concat(govuk_header_logo(**govuk_header_options))
45
+ if govuk_header_options[:service] || govuk_header_options[:navigation]
46
+ concat(tag.div(class: 'govuk-header__content') do
47
+ concat(govuk_header_service_name(govuk_header_options[:service])) if govuk_header_options[:service]
48
+ concat(govuk_header_navigation(govuk_header_options[:navigation], govuk_header_options[:menu_button])) if govuk_header_options[:navigation]
49
+ end)
50
+ end
51
+ end
52
+ end
53
+ end
54
+
55
+ private
56
+
57
+ # Generates the logo for {govuk_header}
58
+ #
59
+ # @param govuk_header_options [Hash] options that will be used to generate the header
17
60
  #
18
- # @option (see CCS::Components::GovUK::Header#initialize)
61
+ # @option (see govuk_header)
19
62
  #
20
- # @return (see CCS::Components::GovUK::Header#render)
63
+ # @return [ActiveSupport::SafeBuffer] the HTML for the logo used in {govuk_header}
64
+
65
+ def govuk_header_logo(govuk_header_options)
66
+ tag.div(class: 'govuk-header__logo') do
67
+ link_to(govuk_header_options[:homepage_url] || '/', class: 'govuk-header__link govuk-header__link--homepage') do
68
+ concat(tag.span(class: 'govuk-header__logotype') do
69
+ concat(tag.svg(class: 'govuk-header__logotype-crown', xmlns: 'http://www.w3.org/2000/svg', height: '30', width: '36', aria: { hidden: 'true' }, focusable: 'false', viewBox: '0 0 132 97') do
70
+ tag.path(fill: 'currentColor', 'fill-rule': 'evenodd', d: 'M25 30.2c3.5 1.5 7.7-.2 9.1-3.7 1.5-3.6-.2-7.8-3.9-9.2-3.6-1.4-7.6.3-9.1 3.9-1.4 3.5.3 7.5 3.9 9zM9 39.5c3.6 1.5 7.8-.2 9.2-3.7 1.5-3.6-.2-7.8-3.9-9.1-3.6-1.5-7.6.2-9.1 3.8-1.4 3.5.3 7.5 3.8 9zM4.4 57.2c3.5 1.5 7.7-.2 9.1-3.8 1.5-3.6-.2-7.7-3.9-9.1-3.5-1.5-7.6.3-9.1 3.8-1.4 3.5.3 7.6 3.9 9.1zm38.3-21.4c3.5 1.5 7.7-.2 9.1-3.8 1.5-3.6-.2-7.7-3.9-9.1-3.6-1.5-7.6.3-9.1 3.8-1.3 3.6.4 7.7 3.9 9.1zm64.4-5.6c-3.6 1.5-7.8-.2-9.1-3.7-1.5-3.6.2-7.8 3.8-9.2 3.6-1.4 7.7.3 9.2 3.9 1.3 3.5-.4 7.5-3.9 9zm15.9 9.3c-3.6 1.5-7.7-.2-9.1-3.7-1.5-3.6.2-7.8 3.7-9.1 3.6-1.5 7.7.2 9.2 3.8 1.5 3.5-.3 7.5-3.8 9zm4.7 17.7c-3.6 1.5-7.8-.2-9.2-3.8-1.5-3.6.2-7.7 3.9-9.1 3.6-1.5 7.7.3 9.2 3.8 1.3 3.5-.4 7.6-3.9 9.1zM89.3 35.8c-3.6 1.5-7.8-.2-9.2-3.8-1.4-3.6.2-7.7 3.9-9.1 3.6-1.5 7.7.3 9.2 3.8 1.4 3.6-.3 7.7-3.9 9.1zM69.7 17.7l8.9 4.7V9.3l-8.9 2.8c-.2-.3-.5-.6-.9-.9L72.4 0H59.6l3.5 11.2c-.3.3-.6.5-.9.9l-8.8-2.8v13.1l8.8-4.7c.3.3.6.7.9.9l-5 15.4v.1c-.2.8-.4 1.6-.4 2.4 0 4.1 3.1 7.5 7 8.1h.2c.3 0 .7.1 1 .1.4 0 .7 0 1-.1h.2c4-.6 7.1-4.1 7.1-8.1 0-.8-.1-1.7-.4-2.4V34l-5.1-15.4c.4-.2.7-.6 1-.9zM66 92.8c16.9 0 32.8 1.1 47.1 3.2 4-16.9 8.9-26.7 14-33.5l-9.6-3.4c1 4.9 1.1 7.2 0 10.2-1.5-1.4-3-4.3-4.2-8.7L108.6 76c2.8-2 5-3.2 7.5-3.3-4.4 9.4-10 11.9-13.6 11.2-4.3-.8-6.3-4.6-5.6-7.9 1-4.7 5.7-5.9 8-.5 4.3-8.7-3-11.4-7.6-8.8 7.1-7.2 7.9-13.5 2.1-21.1-8 6.1-8.1 12.3-4.5 20.8-4.7-5.4-12.1-2.5-9.5 6.2 3.4-5.2 7.9-2 7.2 3.1-.6 4.3-6.4 7.8-13.5 7.2-10.3-.9-10.9-8-11.2-13.8 2.5-.5 7.1 1.8 11 7.3L80.2 60c-4.1 4.4-8 5.3-12.3 5.4 1.4-4.4 8-11.6 8-11.6H55.5s6.4 7.2 7.9 11.6c-4.2-.1-8-1-12.3-5.4l1.4 16.4c3.9-5.5 8.5-7.7 10.9-7.3-.3 5.8-.9 12.8-11.1 13.8-7.2.6-12.9-2.9-13.5-7.2-.7-5 3.8-8.3 7.1-3.1 2.7-8.7-4.6-11.6-9.4-6.2 3.7-8.5 3.6-14.7-4.6-20.8-5.8 7.6-5 13.9 2.2 21.1-4.7-2.6-11.9.1-7.7 8.8 2.3-5.5 7.1-4.2 8.1.5.7 3.3-1.3 7.1-5.7 7.9-3.5.7-9-1.8-13.5-11.2 2.5.1 4.7 1.3 7.5 3.3l-4.7-15.4c-1.2 4.4-2.7 7.2-4.3 8.7-1.1-3-.9-5.3 0-10.2l-9.5 3.4c5 6.9 9.9 16.7 14 33.5 14.8-2.1 30.8-3.2 47.7-3.2z')
71
+ end)
72
+ concat(tag.span('GOV.UK', class: 'govuk-header__logotype-text'))
73
+ end)
74
+ concat(tag.span(govuk_header_options[:product_name], class: 'govuk-header__product-name')) if govuk_header_options[:product_name]
75
+ end
76
+ end
77
+ end
78
+
79
+ # Generates the service name section for {govuk_header}
80
+ #
81
+ # @param service [Hash] options that will be used in the service name section
82
+ #
83
+ # @option service [String] :name the name of the service, included in the header
84
+ # @option service [String] :href URL for the service name anchor
85
+ #
86
+ # @return [ActiveSupport::SafeBuffer] the HTML for the service name section which is used in {govuk_header}
87
+
88
+ def govuk_header_service_name(service)
89
+ if service[:href]
90
+ link_to(service[:name], service[:href], class: 'govuk-header__link govuk-header__service-name')
91
+ else
92
+ tag.span(service[:name], class: 'govuk-header__service-name')
93
+ end
94
+ end
95
+
96
+ # Generates the navigation section for {govuk_header}
97
+ #
98
+ # @param navigation [Hash] options for the navigation
99
+ # @param menu_button [Hash] options for the menu button
100
+ #
101
+ # @option navigation [String] :classes additional CSS classes for the navigation HTML
102
+ # @option navigation [String] :label text for the aria-label attribute of the navigation. Defaults to the menu button text
103
+ # @option navigation [Array] :items the navigation items that will be rendered on the page (see {govuk_header_navigation_item})
104
+ #
105
+ # @option menu_button [String] :text text for the button that opens the mobile navigation menu.
106
+ # By default, this is set to +Menu+.
107
+ # @option menu_button [String] :label text for the aria-label attribute of the button that opens the mobile navigation.
108
+ # Defaults to +Show or hide menu+.
109
+ #
110
+ # @return [ActiveSupport::SafeBuffer] the HTML for the navigation section which is used in {govuk_header}
111
+
112
+ def govuk_header_navigation(navigation, menu_button)
113
+ (menu_button ||= {})[:text] ||= 'Menu'
114
+
115
+ tag.nav(aria: { label: navigation[:label] || menu_button[:text] }, class: "govuk-header__navigation #{navigation[:classes]}".rstrip) do
116
+ concat(button_tag(menu_button[:text], type: :button, class: 'govuk-header__menu-button govuk-js-header-toggle', aria: { controls: 'navigation', label: menu_button[:label] || 'Show or hide menu' }, hidden: true))
117
+ concat(tag.ul(id: 'navigation', class: 'govuk-header__navigation-list') do
118
+ navigation[:items].each { |navigation_item| concat(govuk_header_navigation_item(navigation_item)) }
119
+ end)
120
+ end
121
+ end
122
+
123
+ # Generates a navigation item for {govuk_header_navigation}
124
+ #
125
+ # @param navigation_item [Hash] options that will be used in customising the HTML
126
+ #
127
+ # @option navigation_item [Boolean] :active flag to mark the navigation item as active or not
128
+ # @option navigation_item [String] :text text for the navigation item
129
+ # @option navigation_item [String] :href URL of the navigation item anchor
130
+ # @option navigation_item [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
131
+ #
132
+ # @return [ActiveSupport::SafeBuffer] the HTML for a navigation item which is used in {govuk_header_navigation}
133
+
134
+ def govuk_header_navigation_item(navigation_item)
135
+ tag.li(class: "govuk-header__navigation-item #{'govuk-header__navigation-item--active' if navigation_item[:active]}".rstrip) do
136
+ if navigation_item[:href]
137
+ (navigation_item[:attributes] ||= {})[:class] = 'govuk-header__link'
138
+
139
+ link_to(navigation_item[:text], navigation_item[:href], **navigation_item[:attributes])
140
+ else
141
+ navigation_item[:text]
142
+ end
143
+ end
144
+ end
145
+
146
+ # Sets the default attributes for {govuk_header}
147
+ #
148
+ # @param govuk_header_options [Hash] options that will be used in customising the HTML
149
+ #
150
+ # @option (see govuk_header)
151
+
152
+ def determine_govuk_header_attributes(govuk_header_options)
153
+ initialise_attributes_and_set_classes(govuk_header_options, 'govuk-header')
154
+ set_data_module(govuk_header_options, 'govuk-header')
21
155
 
22
- def govuk_header(**options)
23
- Components::GovUK::Header.new(context: self, **options).render
156
+ govuk_header_options[:attributes][:role] = 'banner'
24
157
  end
25
158
  end
26
159
  end
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../../components/govuk/hint'
3
+ require 'action_view'
4
+
5
+ require_relative '../shared_methods'
4
6
 
5
7
  module CCS
6
8
  module FrontendHelpers
@@ -10,18 +12,25 @@ module CCS
10
12
  # This helper is used for generating the hint text component from the Government Design Systems
11
13
 
12
14
  module Hint
15
+ include SharedMethods
16
+ include ActionView::Context
17
+ include ActionView::Helpers::TagHelper
18
+
13
19
  # Generates the HTML for the GOV.UK Hint component
14
20
  #
15
- # @param (see CCS::Components::GovUK::Hint#initialize)
21
+ # @param hint_text [String] the hint text
22
+ # @param govuk_hint_options [Hash] options that will be used in customising the HTML
16
23
  #
17
- # @option (see CCS::Components::GovUK::Hint#initialize)
24
+ # @option govuk_hint_options [String] :classes additional CSS classes for the hint HTML
25
+ # @option govuk_hint_options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
18
26
  #
19
- # @yield (see CCS::Components::GovUK::Hint#render)
20
- #
21
- # @return (see CCS::Components::GovUK::Hint#render)
27
+ # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Hint
28
+ # which can then be rendered on the page
29
+
30
+ def govuk_hint(hint_text, **govuk_hint_options)
31
+ initialise_attributes_and_set_classes(govuk_hint_options, 'govuk-hint')
22
32
 
23
- def govuk_hint(text = nil, **options, &block)
24
- Components::GovUK::Hint.new(context: self, text: text, **options).render(&block)
33
+ tag.div(hint_text, **govuk_hint_options[:attributes])
25
34
  end
26
35
  end
27
36
  end
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../../components/govuk/inset_text'
3
+ require 'action_view'
4
+
5
+ require_relative '../shared_methods'
4
6
 
5
7
  module CCS
6
8
  module FrontendHelpers
@@ -11,18 +13,30 @@ module CCS
11
13
  # {https://design-system.service.gov.uk/components/inset-text GDS - Components - Inset text}
12
14
 
13
15
  module InsetText
16
+ include SharedMethods
17
+ include ActionView::Context
18
+ include ActionView::Helpers::TagHelper
19
+ include ActionView::Helpers::TextHelper
20
+
14
21
  # Generates the HTML for the GOV.UK Inset text component
15
22
  #
16
- # @param (see CCS::Components::GovUK::InsetText#initialize)
23
+ # @param inset_text [String] text to use within the inset text component
24
+ # @param govuk_inset_text_options [Hash] options that will be used in customising the HTML
17
25
  #
18
- # @option (see CCS::Components::GovUK::InsetText#initialize)
26
+ # @option govuk_inset_text_options [String] :classes additional CSS classes for the inset text HTML
27
+ # @option govuk_inset_text_options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
19
28
  #
20
- # @yield (see CCS::Components::GovUK::InsetText#render)
29
+ # @yield HTML that will be contained within the inset text div. Ignored if inset text is given
21
30
  #
22
- # @return (see CCS::Components::GovUK::InsetText#render)
31
+ # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Inset text
32
+ # which can then be rendered on the page
33
+
34
+ def govuk_inset_text(inset_text = nil, **govuk_inset_text_options)
35
+ initialise_attributes_and_set_classes(govuk_inset_text_options, 'govuk-inset-text')
23
36
 
24
- def govuk_inset_text(text = nil, **options, &block)
25
- Components::GovUK::InsetText.new(context: self, text: text, **options).render(&block)
37
+ tag.div(**govuk_inset_text_options[:attributes]) do
38
+ inset_text || yield
39
+ end
26
40
  end
27
41
  end
28
42
  end