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

Sign up to get free protection for your applications and to get access to all the features.
Files changed (156) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +5 -1
  3. data/.ruby-version +1 -0
  4. data/CHANGELOG.md +4 -1
  5. data/Gemfile.lock +71 -71
  6. data/lib/ccs/components/base.rb +64 -0
  7. data/lib/ccs/components/ccs/dashboard_section/panel.rb +55 -0
  8. data/lib/ccs/components/ccs/dashboard_section.rb +71 -0
  9. data/lib/ccs/components/ccs/footer/link.rb +53 -0
  10. data/lib/ccs/components/ccs/footer/meta.rb +58 -0
  11. data/lib/ccs/components/ccs/footer/navigation.rb +59 -0
  12. data/lib/ccs/components/ccs/footer.rb +93 -0
  13. data/lib/ccs/components/ccs/header/link.rb +58 -0
  14. data/lib/ccs/components/ccs/header/navigation.rb +97 -0
  15. data/lib/ccs/components/ccs/header/service_authentication.rb +52 -0
  16. data/lib/ccs/components/ccs/header.rb +108 -0
  17. data/lib/ccs/components/ccs/logo.rb +45 -0
  18. data/lib/ccs/components/govuk/accordion/section/content.rb +53 -0
  19. data/lib/ccs/components/govuk/accordion/section/header.rb +57 -0
  20. data/lib/ccs/components/govuk/accordion/section.rb +60 -0
  21. data/lib/ccs/components/govuk/accordion.rb +56 -0
  22. data/lib/ccs/components/govuk/back_link.rb +49 -0
  23. data/lib/ccs/components/govuk/breadcrumbs/link.rb +55 -0
  24. data/lib/ccs/components/govuk/breadcrumbs.rb +53 -0
  25. data/lib/ccs/components/govuk/button.rb +105 -0
  26. data/lib/ccs/components/govuk/cookie_banner/action.rb +58 -0
  27. data/lib/ccs/components/govuk/cookie_banner/message.rb +78 -0
  28. data/lib/ccs/components/govuk/cookie_banner.rb +53 -0
  29. data/lib/ccs/components/govuk/details.rb +51 -0
  30. data/lib/ccs/components/govuk/error_message.rb +58 -0
  31. data/lib/ccs/components/govuk/error_summary/item.rb +52 -0
  32. data/lib/ccs/components/govuk/error_summary.rb +68 -0
  33. data/lib/ccs/components/govuk/field/input/character_count.rb +127 -0
  34. data/lib/ccs/components/govuk/field/input/file_upload.rb +42 -0
  35. data/lib/ccs/components/govuk/field/input/select.rb +80 -0
  36. data/lib/ccs/components/govuk/field/input/text_input/fix.rb +53 -0
  37. data/lib/ccs/components/govuk/field/input/text_input.rb +95 -0
  38. data/lib/ccs/components/govuk/field/input/textarea.rb +57 -0
  39. data/lib/ccs/components/govuk/field/input.rb +60 -0
  40. data/lib/ccs/components/govuk/field/inputs/checkboxes.rb +67 -0
  41. data/lib/ccs/components/govuk/field/inputs/date_input/item.rb +63 -0
  42. data/lib/ccs/components/govuk/field/inputs/date_input.rb +87 -0
  43. data/lib/ccs/components/govuk/field/inputs/item/checkbox/form.rb +45 -0
  44. data/lib/ccs/components/govuk/field/inputs/item/checkbox/tag.rb +41 -0
  45. data/lib/ccs/components/govuk/field/inputs/item/checkbox.rb +48 -0
  46. data/lib/ccs/components/govuk/field/inputs/item/divider.rb +48 -0
  47. data/lib/ccs/components/govuk/field/inputs/item/radio/form.rb +42 -0
  48. data/lib/ccs/components/govuk/field/inputs/item/radio/tag.rb +41 -0
  49. data/lib/ccs/components/govuk/field/inputs/item/radio.rb +48 -0
  50. data/lib/ccs/components/govuk/field/inputs/item.rb +109 -0
  51. data/lib/ccs/components/govuk/field/inputs/radios.rb +67 -0
  52. data/lib/ccs/components/govuk/field/inputs.rb +55 -0
  53. data/lib/ccs/components/govuk/field.rb +106 -0
  54. data/lib/ccs/components/govuk/fieldset/legend.rb +63 -0
  55. data/lib/ccs/components/govuk/fieldset.rb +52 -0
  56. data/lib/ccs/components/govuk/footer/link.rb +53 -0
  57. data/lib/ccs/components/govuk/footer/meta.rb +58 -0
  58. data/lib/ccs/components/govuk/footer/navigation.rb +59 -0
  59. data/lib/ccs/components/govuk/footer.rb +129 -0
  60. data/lib/ccs/components/govuk/form_group.rb +58 -0
  61. data/lib/ccs/components/govuk/header/link.rb +54 -0
  62. data/lib/ccs/components/govuk/header/navigation.rb +70 -0
  63. data/lib/ccs/components/govuk/header.rb +105 -0
  64. data/lib/ccs/components/govuk/hint.rb +47 -0
  65. data/lib/ccs/components/govuk/inset_text.rb +50 -0
  66. data/lib/ccs/components/govuk/label.rb +83 -0
  67. data/lib/ccs/components/govuk/notification_banner.rb +105 -0
  68. data/lib/ccs/components/govuk/pagination/increment/next.rb +42 -0
  69. data/lib/ccs/components/govuk/pagination/increment/previous.rb +41 -0
  70. data/lib/ccs/components/govuk/pagination/increment.rb +96 -0
  71. data/lib/ccs/components/govuk/pagination/item/ellipsis.rb +26 -0
  72. data/lib/ccs/components/govuk/pagination/item/form.rb +47 -0
  73. data/lib/ccs/components/govuk/pagination/item/tag.rb +45 -0
  74. data/lib/ccs/components/govuk/pagination/item.rb +62 -0
  75. data/lib/ccs/components/govuk/pagination.rb +94 -0
  76. data/lib/ccs/components/govuk/panel.rb +60 -0
  77. data/lib/ccs/components/govuk/phase_banner.rb +67 -0
  78. data/lib/ccs/components/govuk/skip_link.rb +49 -0
  79. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list/item.rb +51 -0
  80. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list.rb +48 -0
  81. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/paragraph.rb +43 -0
  82. data/lib/ccs/components/govuk/step_by_step_navigation/section/content.rb +61 -0
  83. data/lib/ccs/components/govuk/step_by_step_navigation/section/heading.rb +67 -0
  84. data/lib/ccs/components/govuk/step_by_step_navigation/section.rb +54 -0
  85. data/lib/ccs/components/govuk/step_by_step_navigation.rb +57 -0
  86. data/lib/ccs/components/govuk/summary_list/action/link.rb +57 -0
  87. data/lib/ccs/components/govuk/summary_list/card/actions.rb +57 -0
  88. data/lib/ccs/components/govuk/summary_list/card/title.rb +49 -0
  89. data/lib/ccs/components/govuk/summary_list/card.rb +61 -0
  90. data/lib/ccs/components/govuk/summary_list/row/actions.rb +57 -0
  91. data/lib/ccs/components/govuk/summary_list/row/key.rb +45 -0
  92. data/lib/ccs/components/govuk/summary_list/row/value.rb +45 -0
  93. data/lib/ccs/components/govuk/summary_list/row.rb +63 -0
  94. data/lib/ccs/components/govuk/summary_list.rb +72 -0
  95. data/lib/ccs/components/govuk/table/body/data_cell.rb +51 -0
  96. data/lib/ccs/components/govuk/table/body/head_cell.rb +50 -0
  97. data/lib/ccs/components/govuk/table/header/head_cell.rb +52 -0
  98. data/lib/ccs/components/govuk/table.rb +109 -0
  99. data/lib/ccs/components/govuk/tabs/panel.rb +56 -0
  100. data/lib/ccs/components/govuk/tabs/tab.rb +54 -0
  101. data/lib/ccs/components/govuk/tabs.rb +64 -0
  102. data/lib/ccs/components/govuk/tag.rb +49 -0
  103. data/lib/ccs/components/govuk/warning_text.rb +59 -0
  104. data/lib/ccs/frontend_helpers/ccs_frontend/dashboard_section.rb +25 -0
  105. data/lib/ccs/frontend_helpers/ccs_frontend/footer.rb +16 -131
  106. data/lib/ccs/frontend_helpers/ccs_frontend/header.rb +16 -195
  107. data/lib/ccs/frontend_helpers/ccs_frontend.rb +2 -4
  108. data/lib/ccs/frontend_helpers/govuk_frontend/accordion.rb +16 -105
  109. data/lib/ccs/frontend_helpers/govuk_frontend/back_link.rb +16 -29
  110. data/lib/ccs/frontend_helpers/govuk_frontend/breadcrumbs.rb +16 -66
  111. data/lib/ccs/frontend_helpers/govuk_frontend/button.rb +16 -117
  112. data/lib/ccs/frontend_helpers/govuk_frontend/character_count.rb +26 -0
  113. data/lib/ccs/frontend_helpers/govuk_frontend/checkboxes.rb +26 -0
  114. data/lib/ccs/frontend_helpers/govuk_frontend/cookie_banner.rb +16 -126
  115. data/lib/ccs/frontend_helpers/govuk_frontend/date_input.rb +26 -0
  116. data/lib/ccs/frontend_helpers/govuk_frontend/details.rb +18 -36
  117. data/lib/ccs/frontend_helpers/govuk_frontend/error_message.rb +31 -54
  118. data/lib/ccs/frontend_helpers/govuk_frontend/error_summary.rb +32 -86
  119. data/lib/ccs/frontend_helpers/govuk_frontend/fieldset.rb +18 -61
  120. data/lib/ccs/frontend_helpers/govuk_frontend/file_upload.rb +26 -0
  121. data/lib/ccs/frontend_helpers/govuk_frontend/footer.rb +16 -173
  122. data/lib/ccs/frontend_helpers/govuk_frontend/form_group.rb +26 -39
  123. data/lib/ccs/frontend_helpers/govuk_frontend/header.rb +16 -151
  124. data/lib/ccs/frontend_helpers/govuk_frontend/hint.rb +17 -28
  125. data/lib/ccs/frontend_helpers/govuk_frontend/input.rb +26 -0
  126. data/lib/ccs/frontend_helpers/govuk_frontend/inset_text.rb +18 -34
  127. data/lib/ccs/frontend_helpers/govuk_frontend/label.rb +17 -82
  128. data/lib/ccs/frontend_helpers/govuk_frontend/notification_banner.rb +18 -126
  129. data/lib/ccs/frontend_helpers/govuk_frontend/pagination.rb +16 -326
  130. data/lib/ccs/frontend_helpers/govuk_frontend/panel.rb +18 -41
  131. data/lib/ccs/frontend_helpers/govuk_frontend/phase_banner.rb +18 -39
  132. data/lib/ccs/frontend_helpers/govuk_frontend/radios.rb +26 -0
  133. data/lib/ccs/frontend_helpers/govuk_frontend/select.rb +26 -0
  134. data/lib/ccs/frontend_helpers/govuk_frontend/skip_link.rb +16 -30
  135. data/lib/ccs/frontend_helpers/govuk_frontend/step_by_step_navigation.rb +23 -204
  136. data/lib/ccs/frontend_helpers/govuk_frontend/summary_list.rb +16 -216
  137. data/lib/ccs/frontend_helpers/govuk_frontend/table.rb +16 -114
  138. data/lib/ccs/frontend_helpers/govuk_frontend/tabs.rb +16 -85
  139. data/lib/ccs/frontend_helpers/govuk_frontend/tag.rb +16 -32
  140. data/lib/ccs/frontend_helpers/govuk_frontend/textarea.rb +26 -0
  141. data/lib/ccs/frontend_helpers/govuk_frontend/warning_text.rb +18 -43
  142. data/lib/ccs/frontend_helpers/govuk_frontend.rb +17 -19
  143. data/lib/ccs/frontend_helpers/version.rb +1 -1
  144. metadata +110 -14
  145. data/lib/ccs/frontend_helpers/ccs_frontend/dashboard_panels.rb +0 -79
  146. data/lib/ccs/frontend_helpers/ccs_frontend/logo.rb +0 -49
  147. data/lib/ccs/frontend_helpers/govuk_frontend/field/character_count.rb +0 -165
  148. data/lib/ccs/frontend_helpers/govuk_frontend/field/checkboxes.rb +0 -200
  149. data/lib/ccs/frontend_helpers/govuk_frontend/field/date_input.rb +0 -153
  150. data/lib/ccs/frontend_helpers/govuk_frontend/field/file_upload.rb +0 -83
  151. data/lib/ccs/frontend_helpers/govuk_frontend/field/input.rb +0 -153
  152. data/lib/ccs/frontend_helpers/govuk_frontend/field/radios.rb +0 -201
  153. data/lib/ccs/frontend_helpers/govuk_frontend/field/select.rb +0 -124
  154. data/lib/ccs/frontend_helpers/govuk_frontend/field/textarea.rb +0 -106
  155. data/lib/ccs/frontend_helpers/govuk_frontend/field.rb +0 -213
  156. data/lib/ccs/frontend_helpers/shared_methods.rb +0 -27
@@ -1,99 +1,45 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'action_view'
4
-
5
- require_relative '../shared_methods'
3
+ require_relative '../../components/govuk/error_summary'
6
4
 
7
5
  module CCS
8
- module FrontendHelpers
9
- module GovUKFrontend
10
- # = GOV.UK Error Summary
6
+ module FrontendHelpers::GovUKFrontend
7
+ # = GOV.UK Error Summary
8
+ #
9
+ # This helper is used for generating the error summary component from the
10
+ # {https://design-system.service.gov.uk/components/error-summary GDS - Components - Error summary}
11
+
12
+ module ErrorSummary
13
+ # Generates the HTML for the GOV.UK Error summary component
11
14
  #
12
- # This helper is used for generating the error summary component from the
13
- # {https://design-system.service.gov.uk/components/error-summary GDS - Components - Error summary}
14
-
15
- module ErrorSummary
16
- include SharedMethods
17
- include ActionView::Context
18
- include ActionView::Helpers::TagHelper
19
- include ActionView::Helpers::TextHelper
20
- include ActionView::Helpers::UrlHelper
21
-
22
- # Generates the HTML for the GOV.UK Error summary component
23
- #
24
- # @param title [String] text to use for the heading of the error summary block
25
- # @param error_list [Array] the list of errors to include in the summary. See {govuk_error_summary_list}
26
- # @param description [String] optional text to use for the description of the errors
27
- # @param govuk_error_summary_options [Hash] options that will be used in customising the HTML
28
- #
29
- # @option govuk_error_summary_options [String] :classes additional CSS classes for the error summary HTML
30
- # @option govuk_error_summary_options [Hash] :attributes ({}) any additional attributes that will be added as part of the HTML
31
- #
32
- # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Error summary
33
- # which can then be rendered on the page
34
-
35
- def govuk_error_summary(title, error_list, description = nil, **govuk_error_summary_options)
36
- initialise_attributes_and_set_classes(govuk_error_summary_options, 'govuk-error-summary')
37
- set_data_module(govuk_error_summary_options, 'govuk-error-summary')
38
-
39
- tag.div(**govuk_error_summary_options[:attributes]) do
40
- tag.div(role: 'alert') do
41
- concat(tag.h2(title, class: 'govuk-error-summary__title'))
42
- concat(tag.div(class: 'govuk-error-summary__body') do
43
- concat(tag.p(description)) if description
44
- concat(govuk_error_summary_list(error_list))
45
- end)
46
- end
47
- end
48
- end
49
-
50
- # Generates the HTML for the GOV.UK Error summary component using the error messages in an ActiveModel
51
- #
52
- # @param model [ActiveModel] model that will be used to find the error messages to list
53
- # @param title [String] text to use for the heading of the error summary block
54
- # @param description [String] (nil) optional text to use for the description of the errors
55
- # @param govuk_error_summary_options [Hash] options that will be used in customising the HTML
56
- #
57
- # @option (see #govuk_error_summary)
58
- #
59
- # @return [NilClass, ActiveSupport::SafeBuffer] if there are no errors on the model it will return nil,
60
- # otherwise the HTML for the GOV.UK Error summary
61
- # which can then be rendered on the page is returned
62
-
63
- def govuk_error_summary_with_model(model, title, description = nil, **govuk_error_summary_options)
64
- return if model.errors.blank?
15
+ # @param (see CCS::Components::GovUK::ErrorSummary#initialize)
16
+ #
17
+ # @option (see CCS::Components::GovUK::ErrorSummary#initialize)
18
+ #
19
+ # @return (see CCS::Components::GovUK::ErrorSummary#render)
65
20
 
66
- error_list = model.errors.map { |error| { text: error.message, href: "##{error.attribute}-error" } }
21
+ def govuk_error_summary(title, error_summary_items, description = nil, **options)
22
+ Components::GovUK::ErrorSummary.new(context: self, title: title, error_summary_items: error_summary_items, description: description, **options).render
23
+ end
67
24
 
68
- govuk_error_summary(title, error_list, description, **govuk_error_summary_options)
69
- end
25
+ # Generates the HTML for the GOV.UK Error summary component using the error messages in an ActiveModel
26
+ #
27
+ # @param model [ActiveModel] model that will be used to find the error messages to list
28
+ # @param title [String] text to use for the heading of the error summary block
29
+ # @param description [String] (nil) optional text to use for the description of the errors
30
+ # @param options [Hash] options that will be used in customising the HTML
31
+ #
32
+ # @option (see CCS::Components::GovUK::ErrorSummary#initialize)
33
+ #
34
+ # @return [NilClass, ActiveSupport::SafeBuffer] if error messages are not on the model it will return nil,
35
+ # otherwise it returns the error summary HTML.
70
36
 
71
- private
37
+ def govuk_error_summary_with_model(model, title, description = nil, **options)
38
+ return if model.errors.blank?
72
39
 
73
- # Generates the HTML for the error list in {govuk_error_summary}
74
- #
75
- # @param error_list [Array] The list of errors to include in the summary. See {#govuk_error_summary_list}
76
- #
77
- # @option error_list [String] :href href for the error link item. If provided item will be a link
78
- # @option error_list [String] :text Text for the error link item
79
- # @option error_list [Hash] :attributes ({}) any additional attributes that will be added as part of the link item
80
- #
81
- # @return [ActiveSupport::SafeBuffer] the HTML for the error list
82
- # which is used in {govuk_error_summary}
40
+ error_summary_items = model.errors.map { |error| { text: error.message, href: "##{error.attribute}-error" } }
83
41
 
84
- def govuk_error_summary_list(error_list)
85
- tag.ul(class: 'govuk-list govuk-error-summary__list') do
86
- error_list.each do |error|
87
- concat(tag.li do
88
- if error[:href]
89
- link_to(error[:text], error[:href], **(error[:attributes] || {}))
90
- else
91
- error[:text]
92
- end
93
- end)
94
- end
95
- end
96
- end
42
+ Components::GovUK::ErrorSummary.new(context: self, title: title, error_summary_items: error_summary_items, description: description, **options).render
97
43
  end
98
44
  end
99
45
  end
@@ -1,70 +1,27 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'action_view'
4
-
5
- require_relative '../shared_methods'
3
+ require_relative '../../components/govuk/fieldset'
6
4
 
7
5
  module CCS
8
- module FrontendHelpers
9
- module GovUKFrontend
10
- # = GOV.UK Fieldset
6
+ module FrontendHelpers::GovUKFrontend
7
+ # = GOV.UK Fieldset
8
+ #
9
+ # This helper is used for generating the fieldset component from the
10
+ # {https://design-system.service.gov.uk/components/fieldset GDS - Components - Fieldset}
11
+
12
+ module Fieldset
13
+ # Generates the HTML for the GOV.UK Fieldset component
11
14
  #
12
- # This helper is used for generating the fieldset component from the
13
- # {https://design-system.service.gov.uk/components/fieldset GDS - Components - Fieldset}
14
-
15
- module Fieldset
16
- include SharedMethods
17
- include ActionView::Context
18
- include ActionView::Helpers::TagHelper
19
- include ActionView::Helpers::TextHelper
20
-
21
- # Generates the HTML for the GOV.UK Fieldset component
22
- #
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}
46
- #
47
- # @param govuk_legend_options [Hash] options that will be used in the legend
48
- #
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
54
- #
55
- # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Fieldset
56
- # which can then be rendered on the page
15
+ # @param (see CCS::Components::GovUK::Fieldset#initialize)
16
+ #
17
+ # @option (see CCS::Components::GovUK::Fieldset#initialize)
18
+ #
19
+ # @yield (see CCS::Components::GovUK::Fieldset#render)
20
+ #
21
+ # @return (see CCS::Components::GovUK::Fieldset#render)
57
22
 
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
67
- end
23
+ def govuk_fieldset(**options, &block)
24
+ Components::GovUK::Fieldset.new(context: self, **options).render(&block)
68
25
  end
69
26
  end
70
27
  end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../components/govuk/field/input/file_upload'
4
+
5
+ module CCS
6
+ module FrontendHelpers::GovUKFrontend
7
+ # = GOV.UK File Upload
8
+ #
9
+ # This helper is used for generating the file upload component from the
10
+ # {https://design-system.service.gov.uk/components/file-upload GDS - Components - File Upload}
11
+
12
+ module FileUpload
13
+ # Generates the HTML for the GOV.UK File Upload component
14
+ #
15
+ # @param (see CCS::Components::GovUK::Input::FileUpload#initialize)
16
+ #
17
+ # @option (see CCS::Components::GovUK::Input::FileUpload#initialize)
18
+ #
19
+ # @return (see CCS::Components::GovUK::Input::FileUpload#render)
20
+
21
+ def govuk_file_upload(attribute, **options)
22
+ Components::GovUK::Field::Input::FileUpload.new(context: self, attribute: attribute, **options).render
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,182 +1,25 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'action_view'
4
-
5
- require_relative '../shared_methods'
3
+ require_relative '../../components/govuk/footer'
6
4
 
7
5
  module CCS
8
- module FrontendHelpers
9
- module GovUKFrontend
10
- # = GOV.UK Footer
6
+ module FrontendHelpers::GovUKFrontend
7
+ # = GOV.UK Footer
8
+ #
9
+ # This helper is used for generating the footer component from the
10
+ # {https://design-system.service.gov.uk/components/footer GDS - Components - Footer}
11
+
12
+ module Footer
13
+ # Generates the HTML for the GOV.UK Footer component
11
14
  #
12
- # This helper is used for generating the footer component from the
13
- # {https://design-system.service.gov.uk/components/footer GDS - Components - Footer}
14
-
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
-
25
- # Generates the HTML for the GOV.UK Footer component
26
- #
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}
170
- #
171
- # @param copyright [ActiveSupport::SafeBuffer,String] the copyright information, this defaults to Crown Copyright
172
- #
173
- # @return [ActiveSupport::SafeBuffer] the HTML for the copyright used in {govuk_footer}
15
+ # @param (see CCS::Components::GovUK::Footer#initialize)
16
+ #
17
+ # @option (see CCS::Components::GovUK::Footer#initialize)
18
+ #
19
+ # @return (see CCS::Components::GovUK::Footer#render)
174
20
 
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
179
- end
21
+ def govuk_footer(**options)
22
+ Components::GovUK::Footer.new(context: self, **options).render
180
23
  end
181
24
  end
182
25
  end
@@ -1,49 +1,36 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'error_message'
3
+ require_relative '../../components/govuk/form_group'
4
4
 
5
5
  module CCS
6
- module FrontendHelpers
7
- module GovUKFrontend
8
- # = GOV.UK FormGroup
9
- #
10
- # This helper is used for generating the form group component from the Government Design Systems
11
-
12
- module FormGroup
13
- include ErrorMessage
14
-
15
- # Generates the HTML for the GOV.UK Form Group component
16
- #
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
19
- #
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
24
- #
25
- # @yield HTML that will be contained within the 'govuk-form-group' div
26
- #
27
- # @yieldparam displayed_error_message [ActiveSupport::SafeBuffer] the HTML for the error message (if there is one)
28
- #
29
- # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Form Group
30
- # which can then be rendered on the page
6
+ module FrontendHelpers::GovUKFrontend
7
+ # = GOV.UK FormGroup
8
+ #
9
+ # This helper is used for generating the form group component from the Government Design Systems
31
10
 
32
- def govuk_form_group(attribute, **govuk_form_group_options)
33
- error_message = if govuk_form_group_options[:model]
34
- model.errors[attribute].first
35
- else
36
- govuk_form_group_options[:error_message]
37
- end
38
-
39
- initialise_attributes_and_set_classes(govuk_form_group_options, "govuk-form-group #{'govuk-form-group--error' if error_message}".rstrip)
11
+ module FormGroup
12
+ # Generates the HTML for the GOV.UK Warning text component
13
+ #
14
+ # @param (see CCS::Components::GovUK::FormGroup#initialize)
15
+ #
16
+ # @option options [String] :classes additional CSS classes for the form group HTML
17
+ # @option options [ActiveModel] :model (nil) model that will be used to find an error message
18
+ # @option options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
19
+ #
20
+ # @yield (see CCS::Components::GovUK::FormGroup#render)
21
+ #
22
+ # @yieldparam (see CCS::Components::GovUK::FormGroup#render)
23
+ #
24
+ # @return (see CCS::Components::GovUK::FormGroup#render)
40
25
 
41
- govuk_form_group_options[:attributes][:id] ||= "#{attribute}-form-group"
26
+ def govuk_form_group(attribute, **options, &block)
27
+ error_message = if options[:model]
28
+ model.errors[attribute].first
29
+ else
30
+ options[:error_message]
31
+ end
42
32
 
43
- tag.div(**govuk_form_group_options[:attributes]) do
44
- yield((govuk_error_message(error_message, attribute) if error_message))
45
- end
46
- end
33
+ Components::GovUK::FormGroup.new(context: self, attribute: attribute, error_message: error_message, **options).render(&block)
47
34
  end
48
35
  end
49
36
  end