ccs-frontend_helpers 0.1.0 → 0.1.1.rc.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +11 -2
- data/.ruby-version +1 -0
- data/CHANGELOG.md +4 -1
- data/Gemfile +15 -1
- data/Gemfile.lock +153 -114
- data/ccs-frontend_helpers.gemspec +1 -11
- data/lib/ccs/components/base.rb +64 -0
- data/lib/ccs/components/ccs/dashboard_section/panel.rb +57 -0
- data/lib/ccs/components/ccs/dashboard_section.rb +71 -0
- data/lib/ccs/components/ccs/footer/link.rb +55 -0
- data/lib/ccs/components/ccs/footer/meta.rb +59 -0
- data/lib/ccs/components/ccs/footer/navigation.rb +60 -0
- data/lib/ccs/components/ccs/footer.rb +95 -0
- data/lib/ccs/components/ccs/header/link.rb +60 -0
- data/lib/ccs/components/ccs/header/navigation.rb +98 -0
- data/lib/ccs/components/ccs/header/service_authentication.rb +53 -0
- data/lib/ccs/components/ccs/header.rb +110 -0
- data/lib/ccs/{frontend_helpers/ccs_frontend → components/ccs}/logo.rb +10 -12
- data/lib/ccs/components/govuk/accordion/section/content.rb +53 -0
- data/lib/ccs/components/govuk/accordion/section/header.rb +57 -0
- data/lib/ccs/components/govuk/accordion/section.rb +61 -0
- data/lib/ccs/components/govuk/accordion.rb +58 -0
- data/lib/ccs/components/govuk/back_link.rb +51 -0
- data/lib/ccs/components/govuk/breadcrumbs/link.rb +57 -0
- data/lib/ccs/components/govuk/breadcrumbs.rb +55 -0
- data/lib/ccs/components/govuk/button.rb +107 -0
- data/lib/ccs/components/govuk/cookie_banner/action.rb +60 -0
- data/lib/ccs/components/govuk/cookie_banner/message.rb +80 -0
- data/lib/ccs/components/govuk/cookie_banner.rb +55 -0
- data/lib/ccs/components/govuk/details.rb +53 -0
- data/lib/ccs/components/govuk/error_message.rb +60 -0
- data/lib/ccs/components/govuk/error_summary/item.rb +54 -0
- data/lib/ccs/components/govuk/error_summary.rb +70 -0
- data/lib/ccs/components/govuk/field/input/character_count.rb +129 -0
- data/lib/ccs/components/govuk/field/input/file_upload.rb +44 -0
- data/lib/ccs/components/govuk/field/input/select.rb +82 -0
- data/lib/ccs/components/govuk/field/input/text_input/fix.rb +55 -0
- data/lib/ccs/components/govuk/field/input/text_input.rb +97 -0
- data/lib/ccs/components/govuk/field/input/textarea.rb +59 -0
- data/lib/ccs/components/govuk/field/input.rb +62 -0
- data/lib/ccs/components/govuk/field/inputs/checkboxes.rb +69 -0
- data/lib/ccs/components/govuk/field/inputs/date_input/item.rb +65 -0
- data/lib/ccs/components/govuk/field/inputs/date_input.rb +89 -0
- data/lib/ccs/components/govuk/field/inputs/item/checkbox/form.rb +47 -0
- data/lib/ccs/components/govuk/field/inputs/item/checkbox/tag.rb +43 -0
- data/lib/ccs/components/govuk/field/inputs/item/checkbox.rb +50 -0
- data/lib/ccs/components/govuk/field/inputs/item/divider.rb +50 -0
- data/lib/ccs/components/govuk/field/inputs/item/radio/form.rb +44 -0
- data/lib/ccs/components/govuk/field/inputs/item/radio/tag.rb +43 -0
- data/lib/ccs/components/govuk/field/inputs/item/radio.rb +50 -0
- data/lib/ccs/components/govuk/field/inputs/item.rb +111 -0
- data/lib/ccs/components/govuk/field/inputs/radios.rb +69 -0
- data/lib/ccs/components/govuk/field/inputs.rb +57 -0
- data/lib/ccs/components/govuk/field.rb +108 -0
- data/lib/ccs/components/govuk/fieldset/legend.rb +65 -0
- data/lib/ccs/components/govuk/fieldset.rb +54 -0
- data/lib/ccs/components/govuk/footer/link.rb +55 -0
- data/lib/ccs/components/govuk/footer/meta.rb +59 -0
- data/lib/ccs/components/govuk/footer/navigation.rb +60 -0
- data/lib/ccs/components/govuk/footer.rb +131 -0
- data/lib/ccs/components/govuk/form_group.rb +60 -0
- data/lib/ccs/components/govuk/header/link.rb +56 -0
- data/lib/ccs/components/govuk/header/navigation.rb +71 -0
- data/lib/ccs/components/govuk/header.rb +107 -0
- data/lib/ccs/components/govuk/hint.rb +49 -0
- data/lib/ccs/components/govuk/inset_text.rb +52 -0
- data/lib/ccs/components/govuk/label.rb +85 -0
- data/lib/ccs/components/govuk/notification_banner.rb +107 -0
- data/lib/ccs/components/govuk/pagination/increment/next.rb +44 -0
- data/lib/ccs/components/govuk/pagination/increment/previous.rb +43 -0
- data/lib/ccs/components/govuk/pagination/increment.rb +98 -0
- data/lib/ccs/components/govuk/pagination/item/ellipsis.rb +28 -0
- data/lib/ccs/components/govuk/pagination/item/form.rb +49 -0
- data/lib/ccs/components/govuk/pagination/item/tag.rb +47 -0
- data/lib/ccs/components/govuk/pagination/item.rb +64 -0
- data/lib/ccs/components/govuk/pagination.rb +96 -0
- data/lib/ccs/components/govuk/panel.rb +62 -0
- data/lib/ccs/components/govuk/phase_banner.rb +69 -0
- data/lib/ccs/components/govuk/skip_link.rb +51 -0
- data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list/item.rb +53 -0
- data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list.rb +50 -0
- data/lib/ccs/components/govuk/step_by_step_navigation/section/content/paragraph.rb +45 -0
- data/lib/ccs/components/govuk/step_by_step_navigation/section/content.rb +63 -0
- data/lib/ccs/components/govuk/step_by_step_navigation/section/heading.rb +69 -0
- data/lib/ccs/components/govuk/step_by_step_navigation/section.rb +56 -0
- data/lib/ccs/components/govuk/step_by_step_navigation.rb +59 -0
- data/lib/ccs/components/govuk/summary_list/action/link.rb +59 -0
- data/lib/ccs/components/govuk/summary_list/card/actions.rb +59 -0
- data/lib/ccs/components/govuk/summary_list/card/title.rb +51 -0
- data/lib/ccs/components/govuk/summary_list/card.rb +63 -0
- data/lib/ccs/components/govuk/summary_list/row/actions.rb +59 -0
- data/lib/ccs/components/govuk/summary_list/row/key.rb +47 -0
- data/lib/ccs/components/govuk/summary_list/row/value.rb +47 -0
- data/lib/ccs/components/govuk/summary_list/row.rb +67 -0
- data/lib/ccs/components/govuk/summary_list.rb +74 -0
- data/lib/ccs/components/govuk/table/body/data_cell.rb +53 -0
- data/lib/ccs/components/govuk/table/body/head_cell.rb +52 -0
- data/lib/ccs/components/govuk/table/header/head_cell.rb +54 -0
- data/lib/ccs/components/govuk/table.rb +111 -0
- data/lib/ccs/components/govuk/tabs/panel.rb +58 -0
- data/lib/ccs/components/govuk/tabs/tab.rb +56 -0
- data/lib/ccs/components/govuk/tabs.rb +66 -0
- data/lib/ccs/components/govuk/tag.rb +51 -0
- data/lib/ccs/components/govuk/warning_text.rb +61 -0
- data/lib/ccs/frontend_helpers/ccs_frontend/dashboard_section.rb +27 -0
- data/lib/ccs/frontend_helpers/ccs_frontend/footer.rb +6 -119
- data/lib/ccs/frontend_helpers/ccs_frontend/header.rb +6 -183
- data/lib/ccs/frontend_helpers/ccs_frontend.rb +2 -4
- data/lib/ccs/frontend_helpers/govuk_frontend/accordion.rb +8 -95
- data/lib/ccs/frontend_helpers/govuk_frontend/back_link.rb +6 -17
- data/lib/ccs/frontend_helpers/govuk_frontend/breadcrumbs.rb +6 -54
- data/lib/ccs/frontend_helpers/govuk_frontend/button.rb +6 -105
- data/lib/ccs/frontend_helpers/govuk_frontend/character_count.rb +28 -0
- data/lib/ccs/frontend_helpers/govuk_frontend/checkboxes.rb +28 -0
- data/lib/ccs/frontend_helpers/govuk_frontend/cookie_banner.rb +6 -114
- data/lib/ccs/frontend_helpers/govuk_frontend/date_input.rb +28 -0
- data/lib/ccs/frontend_helpers/govuk_frontend/details.rb +7 -23
- data/lib/ccs/frontend_helpers/govuk_frontend/error_message.rb +11 -32
- data/lib/ccs/frontend_helpers/govuk_frontend/error_summary.rb +13 -65
- data/lib/ccs/frontend_helpers/govuk_frontend/fieldset.rb +7 -48
- data/lib/ccs/frontend_helpers/govuk_frontend/file_upload.rb +28 -0
- data/lib/ccs/frontend_helpers/govuk_frontend/footer.rb +6 -161
- data/lib/ccs/frontend_helpers/govuk_frontend/form_group.rb +13 -24
- data/lib/ccs/frontend_helpers/govuk_frontend/header.rb +6 -139
- data/lib/ccs/frontend_helpers/govuk_frontend/hint.rb +8 -17
- data/lib/ccs/frontend_helpers/govuk_frontend/input.rb +28 -0
- data/lib/ccs/frontend_helpers/govuk_frontend/inset_text.rb +7 -21
- data/lib/ccs/frontend_helpers/govuk_frontend/label.rb +7 -70
- data/lib/ccs/frontend_helpers/govuk_frontend/notification_banner.rb +7 -113
- data/lib/ccs/frontend_helpers/govuk_frontend/pagination.rb +6 -314
- data/lib/ccs/frontend_helpers/govuk_frontend/panel.rb +7 -28
- data/lib/ccs/frontend_helpers/govuk_frontend/phase_banner.rb +8 -27
- data/lib/ccs/frontend_helpers/govuk_frontend/radios.rb +28 -0
- data/lib/ccs/frontend_helpers/govuk_frontend/select.rb +28 -0
- data/lib/ccs/frontend_helpers/govuk_frontend/skip_link.rb +6 -18
- data/lib/ccs/frontend_helpers/govuk_frontend/step_by_step_navigation.rb +7 -186
- data/lib/ccs/frontend_helpers/govuk_frontend/summary_list.rb +6 -204
- data/lib/ccs/frontend_helpers/govuk_frontend/table.rb +11 -100
- data/lib/ccs/frontend_helpers/govuk_frontend/tabs.rb +6 -73
- data/lib/ccs/frontend_helpers/govuk_frontend/tag.rb +7 -21
- data/lib/ccs/frontend_helpers/govuk_frontend/textarea.rb +28 -0
- data/lib/ccs/frontend_helpers/govuk_frontend/warning_text.rb +7 -30
- data/lib/ccs/frontend_helpers/govuk_frontend.rb +17 -19
- data/lib/ccs/frontend_helpers/version.rb +1 -1
- metadata +117 -147
- data/lib/ccs/frontend_helpers/ccs_frontend/dashboard_panels.rb +0 -79
- data/lib/ccs/frontend_helpers/govuk_frontend/field/character_count.rb +0 -165
- data/lib/ccs/frontend_helpers/govuk_frontend/field/checkboxes.rb +0 -200
- data/lib/ccs/frontend_helpers/govuk_frontend/field/date_input.rb +0 -153
- data/lib/ccs/frontend_helpers/govuk_frontend/field/file_upload.rb +0 -83
- data/lib/ccs/frontend_helpers/govuk_frontend/field/input.rb +0 -153
- data/lib/ccs/frontend_helpers/govuk_frontend/field/radios.rb +0 -201
- data/lib/ccs/frontend_helpers/govuk_frontend/field/select.rb +0 -124
- data/lib/ccs/frontend_helpers/govuk_frontend/field/textarea.rb +0 -106
- data/lib/ccs/frontend_helpers/govuk_frontend/field.rb +0 -213
- data/lib/ccs/frontend_helpers/shared_methods.rb +0 -27
@@ -1,8 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
require_relative '../shared_methods'
|
3
|
+
require_relative '../../components/govuk/back_link'
|
6
4
|
|
7
5
|
module CCS
|
8
6
|
module FrontendHelpers
|
@@ -13,53 +11,34 @@ module CCS
|
|
13
11
|
# {https://design-system.service.gov.uk/components/error-message GDS - Components - Error message}
|
14
12
|
|
15
13
|
module ErrorMessage
|
16
|
-
include SharedMethods
|
17
|
-
include ActionView::Context
|
18
|
-
include ActionView::Helpers::TagHelper
|
19
|
-
include ActionView::Helpers::TextHelper
|
20
|
-
|
21
14
|
# Generates the HTML for the GOV.UK Error message component
|
22
15
|
#
|
23
|
-
# @param
|
24
|
-
# @param attribute [String, Symbol] the attribute that has an error
|
25
|
-
# @param govuk_error_message_options [Hash] options that will be used in customising the HTML
|
16
|
+
# @param (see CCS::Components::GovUK::ErrorMessage#initialize)
|
26
17
|
#
|
27
|
-
# @option
|
28
|
-
# @option govuk_error_message_options [String] :visually_hidden_text ('Error') visualy hidden text before the error message
|
29
|
-
# @option govuk_error_message_options [Hash] :attributes ({}) any additional attributes that will be added as part of the HTML
|
18
|
+
# @option (see CCS::Components::GovUK::ErrorMessage#initialize)
|
30
19
|
#
|
31
|
-
# @return
|
32
|
-
# which can then be rendered on the page
|
33
|
-
|
34
|
-
def govuk_error_message(message, attribute, **govuk_error_message_options)
|
35
|
-
initialise_attributes_and_set_classes(govuk_error_message_options, 'govuk-error-message')
|
36
|
-
|
37
|
-
govuk_error_message_options[:attributes][:id] ||= "#{attribute}-error"
|
38
|
-
visually_hidden_text = govuk_error_message_options[:visually_hidden_text] || 'Error'
|
20
|
+
# @return (see CCS::Components::GovUK::ErrorMessage#render)
|
39
21
|
|
40
|
-
|
41
|
-
|
42
|
-
concat(message)
|
43
|
-
end
|
22
|
+
def govuk_error_message(error_message, attribute, **options)
|
23
|
+
Components::GovUK::ErrorMessage.new(context: self, message: error_message, attribute: attribute, **options).render
|
44
24
|
end
|
45
25
|
|
46
26
|
# Generates the HTML for the GOV.UK Error message component using the error messages in an ActiveModel
|
47
27
|
#
|
48
28
|
# @param model [ActiveModel] model that will be used to find the error message
|
49
29
|
# @param attribute [String, Symbol] the attribute that has an error
|
50
|
-
# @param
|
30
|
+
# @param options [Hash] options that will be used in customising the HTML
|
51
31
|
#
|
52
|
-
# @option (see #
|
32
|
+
# @option (see CCS::Components::GovUK::ErrorMessage#initialize)
|
53
33
|
#
|
54
34
|
# @return [NilClass, ActiveSupport::SafeBuffer] if the error message is not on the model it will return nil,
|
55
|
-
# otherwise
|
56
|
-
# which can then be rendered on the page is returned
|
35
|
+
# otherwise it returns the error message HTML
|
57
36
|
|
58
|
-
def govuk_error_message_with_model(model, attribute, **
|
37
|
+
def govuk_error_message_with_model(model, attribute, **options)
|
59
38
|
error_message = model.errors[attribute].first
|
60
39
|
return unless error_message
|
61
40
|
|
62
|
-
|
41
|
+
Components::GovUK::ErrorMessage.new(context: self, message: error_message, attribute: attribute, **options).render
|
63
42
|
end
|
64
43
|
end
|
65
44
|
end
|
@@ -1,8 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
require_relative '../shared_methods'
|
3
|
+
require_relative '../../components/govuk/error_summary'
|
6
4
|
|
7
5
|
module CCS
|
8
6
|
module FrontendHelpers
|
@@ -13,38 +11,16 @@ module CCS
|
|
13
11
|
# {https://design-system.service.gov.uk/components/error-summary GDS - Components - Error summary}
|
14
12
|
|
15
13
|
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
14
|
# Generates the HTML for the GOV.UK Error summary component
|
23
15
|
#
|
24
|
-
# @param
|
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
|
16
|
+
# @param (see CCS::Components::GovUK::ErrorSummary#initialize)
|
28
17
|
#
|
29
|
-
# @option
|
30
|
-
# @option govuk_error_summary_options [Hash] :attributes ({}) any additional attributes that will be added as part of the HTML
|
18
|
+
# @option (see CCS::Components::GovUK::ErrorSummary#initialize)
|
31
19
|
#
|
32
|
-
# @return
|
33
|
-
# which can then be rendered on the page
|
20
|
+
# @return (see CCS::Components::GovUK::ErrorSummary#render)
|
34
21
|
|
35
|
-
def govuk_error_summary(title,
|
36
|
-
|
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
|
22
|
+
def govuk_error_summary(title, error_summary_items, description = nil, **options)
|
23
|
+
Components::GovUK::ErrorSummary.new(context: self, title: title, error_summary_items: error_summary_items, description: description, **options).render
|
48
24
|
end
|
49
25
|
|
50
26
|
# Generates the HTML for the GOV.UK Error summary component using the error messages in an ActiveModel
|
@@ -52,47 +28,19 @@ module CCS
|
|
52
28
|
# @param model [ActiveModel] model that will be used to find the error messages to list
|
53
29
|
# @param title [String] text to use for the heading of the error summary block
|
54
30
|
# @param description [String] (nil) optional text to use for the description of the errors
|
55
|
-
# @param
|
31
|
+
# @param options [Hash] options that will be used in customising the HTML
|
56
32
|
#
|
57
|
-
# @option (see #
|
33
|
+
# @option (see CCS::Components::GovUK::ErrorSummary#initialize)
|
58
34
|
#
|
59
|
-
# @return [NilClass, ActiveSupport::SafeBuffer] if
|
60
|
-
# otherwise
|
61
|
-
# which can then be rendered on the page is returned
|
35
|
+
# @return [NilClass, ActiveSupport::SafeBuffer] if error messages are not on the model it will return nil,
|
36
|
+
# otherwise it returns the error summary HTML.
|
62
37
|
|
63
|
-
def govuk_error_summary_with_model(model, title, description = nil, **
|
38
|
+
def govuk_error_summary_with_model(model, title, description = nil, **options)
|
64
39
|
return if model.errors.blank?
|
65
40
|
|
66
|
-
|
67
|
-
|
68
|
-
govuk_error_summary(title, error_list, description, **govuk_error_summary_options)
|
69
|
-
end
|
70
|
-
|
71
|
-
private
|
72
|
-
|
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}
|
41
|
+
error_summary_items = model.errors.map { |error| { text: error.message, href: "##{error.attribute}-error" } }
|
83
42
|
|
84
|
-
|
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
|
43
|
+
Components::GovUK::ErrorSummary.new(context: self, title: title, error_summary_items: error_summary_items, description: description, **options).render
|
96
44
|
end
|
97
45
|
end
|
98
46
|
end
|
@@ -1,8 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
require_relative '../shared_methods'
|
3
|
+
require_relative '../../components/govuk/fieldset'
|
6
4
|
|
7
5
|
module CCS
|
8
6
|
module FrontendHelpers
|
@@ -13,57 +11,18 @@ module CCS
|
|
13
11
|
# {https://design-system.service.gov.uk/components/fieldset GDS - Components - Fieldset}
|
14
12
|
|
15
13
|
module Fieldset
|
16
|
-
include SharedMethods
|
17
|
-
include ActionView::Context
|
18
|
-
include ActionView::Helpers::TagHelper
|
19
|
-
include ActionView::Helpers::TextHelper
|
20
|
-
|
21
14
|
# Generates the HTML for the GOV.UK Fieldset component
|
22
15
|
#
|
23
|
-
# @param
|
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}
|
16
|
+
# @param (see CCS::Components::GovUK::Fieldset#initialize)
|
46
17
|
#
|
47
|
-
# @
|
18
|
+
# @option (see CCS::Components::GovUK::Fieldset#initialize)
|
48
19
|
#
|
49
|
-
# @
|
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
|
20
|
+
# @yield (see CCS::Components::GovUK::Fieldset#render)
|
54
21
|
#
|
55
|
-
# @return
|
56
|
-
# which can then be rendered on the page
|
22
|
+
# @return (see CCS::Components::GovUK::Fieldset#render)
|
57
23
|
|
58
|
-
def
|
59
|
-
|
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
|
24
|
+
def govuk_fieldset(**options, &block)
|
25
|
+
Components::GovUK::Fieldset.new(context: self, **options).render(&block)
|
67
26
|
end
|
68
27
|
end
|
69
28
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../components/govuk/field/input/file_upload'
|
4
|
+
|
5
|
+
module CCS
|
6
|
+
module FrontendHelpers
|
7
|
+
module GovUKFrontend
|
8
|
+
# = GOV.UK File Upload
|
9
|
+
#
|
10
|
+
# This helper is used for generating the file upload component from the
|
11
|
+
# {https://design-system.service.gov.uk/components/file-upload GDS - Components - File Upload}
|
12
|
+
|
13
|
+
module FileUpload
|
14
|
+
# Generates the HTML for the GOV.UK File Upload component
|
15
|
+
#
|
16
|
+
# @param (see CCS::Components::GovUK::Input::FileUpload#initialize)
|
17
|
+
#
|
18
|
+
# @option (see CCS::Components::GovUK::Input::FileUpload#initialize)
|
19
|
+
#
|
20
|
+
# @return (see CCS::Components::GovUK::Input::FileUpload#render)
|
21
|
+
|
22
|
+
def govuk_file_upload(attribute, **options)
|
23
|
+
Components::GovUK::Field::Input::FileUpload.new(context: self, attribute: attribute, **options).render
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -1,8 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
require_relative '../shared_methods'
|
3
|
+
require_relative '../../components/govuk/footer'
|
6
4
|
|
7
5
|
module CCS
|
8
6
|
module FrontendHelpers
|
@@ -13,169 +11,16 @@ module CCS
|
|
13
11
|
# {https://design-system.service.gov.uk/components/footer GDS - Components - Footer}
|
14
12
|
|
15
13
|
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
14
|
# Generates the HTML for the GOV.UK Footer component
|
26
15
|
#
|
27
|
-
# @param
|
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}
|
16
|
+
# @param (see CCS::Components::GovUK::Footer#initialize)
|
170
17
|
#
|
171
|
-
# @
|
18
|
+
# @option (see CCS::Components::GovUK::Footer#initialize)
|
172
19
|
#
|
173
|
-
# @return
|
20
|
+
# @return (see CCS::Components::GovUK::Footer#render)
|
174
21
|
|
175
|
-
def
|
176
|
-
|
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
|
22
|
+
def govuk_footer(**options)
|
23
|
+
Components::GovUK::Footer.new(context: self, **options).render
|
179
24
|
end
|
180
25
|
end
|
181
26
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative '
|
3
|
+
require_relative '../../components/govuk/form_group'
|
4
4
|
|
5
5
|
module CCS
|
6
6
|
module FrontendHelpers
|
@@ -10,39 +10,28 @@ 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
|
-
|
14
|
-
|
15
|
-
# Generates the HTML for the GOV.UK Form Group component
|
13
|
+
# Generates the HTML for the GOV.UK Warning text component
|
16
14
|
#
|
17
|
-
# @param
|
18
|
-
# @param govuk_form_group_options [Hash] options that will be used in customising the HTML
|
15
|
+
# @param (see CCS::Components::GovUK::FormGroup#initialize)
|
19
16
|
#
|
20
|
-
# @option
|
21
|
-
# @option
|
22
|
-
# @option
|
23
|
-
# @option govuk_form_group_options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
|
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
|
24
20
|
#
|
25
|
-
# @yield
|
21
|
+
# @yield (see CCS::Components::GovUK::FormGroup#render)
|
26
22
|
#
|
27
|
-
# @yieldparam
|
23
|
+
# @yieldparam (see CCS::Components::GovUK::FormGroup#render)
|
28
24
|
#
|
29
|
-
# @return
|
30
|
-
# which can then be rendered on the page
|
25
|
+
# @return (see CCS::Components::GovUK::FormGroup#render)
|
31
26
|
|
32
|
-
def govuk_form_group(attribute, **
|
33
|
-
error_message = if
|
27
|
+
def govuk_form_group(attribute, **options, &block)
|
28
|
+
error_message = if options[:model]
|
34
29
|
model.errors[attribute].first
|
35
30
|
else
|
36
|
-
|
31
|
+
options[:error_message]
|
37
32
|
end
|
38
33
|
|
39
|
-
|
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
|
34
|
+
Components::GovUK::FormGroup.new(context: self, attribute: attribute, error_message: error_message, **options).render(&block)
|
46
35
|
end
|
47
36
|
end
|
48
37
|
end
|