crown_marketplace_utils 0.1.0.beta.6 → 0.1.0.beta.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/accordion.rb +91 -89
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/back_link.rb +24 -22
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/breadcrumbs.rb +56 -54
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/button.rb +109 -107
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/details.rb +33 -31
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/error_message.rb +53 -46
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/character_count.rb +144 -142
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/checkboxes.rb +176 -174
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/date_input.rb +126 -124
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/file_upload.rb +75 -73
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/input.rb +137 -135
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/radios.rb +176 -174
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/select.rb +111 -109
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/textarea.rb +86 -84
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field.rb +181 -179
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/fieldset.rb +56 -54
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/form_group.rb +37 -35
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/header.rb +142 -140
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/hint.rb +25 -23
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/label.rb +69 -67
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/notification_banner.rb +121 -119
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/pagination.rb +290 -288
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/step_by_step_navigation.rb +187 -185
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/tag.rb +29 -27
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/warning_text.rb +39 -37
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper.rb +31 -29
- data/lib/crown_marketplace_utils/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8ff7350d450cf26c0a9c0e0c5f215c8b0b79768081899bd3bd0abbbf40a3a16
|
4
|
+
data.tar.gz: 8d45b24b65f109bafc768b632410914efc7226f55b9e8903d9460780e9c80486
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f560935447ef4b6171da259337d13843fa46331c37a5d3838695753fe38252b47f3af64dacc9aa4cc59f065296f78f63f595df6d3ea0ec03a1b855848b44ae61
|
7
|
+
data.tar.gz: f5430c2deb151ae09a4b6d3f6dad2dbeb2e32f6393d69a31a45f9697567197b2367fbf88487108e1615fa15363d4dd5e2ddaf659c0ff485014d17146e63fcdd6
|
data/Gemfile.lock
CHANGED
@@ -2,112 +2,114 @@
|
|
2
2
|
|
3
3
|
require 'action_view'
|
4
4
|
|
5
|
-
module CrownMarketplaceUtils
|
6
|
-
module
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
module CrownMarketplaceUtils
|
6
|
+
module Helpers
|
7
|
+
module GovUkHelper
|
8
|
+
# = GOV.UK Accordion
|
9
|
+
#
|
10
|
+
# This helper is used for generating the accordion component from the
|
11
|
+
# {https://design-system.service.gov.uk/accordion/back-link GDS - Components - Accordion}
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
module Accordion
|
14
|
+
include ActionView::Context
|
15
|
+
include ActionView::Helpers::TagHelper
|
16
|
+
include ActionView::Helpers::TextHelper
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
18
|
+
# Generates the HTML for the GOV.UK accordion component
|
19
|
+
#
|
20
|
+
# @param accordion_id [String] used as an id in the HTML for the accordion as a whole,
|
21
|
+
# and also as a prefix for the ids of the section contents
|
22
|
+
# and the buttons that open them
|
23
|
+
# @param accordion_items [Array<Hash>] an array of accordion items.
|
24
|
+
# See {#govuk_accordion_section} for details of the items in the array.
|
25
|
+
# @param govuk_accordion_options [Hash] options that will be used in customising the HTML
|
26
|
+
#
|
27
|
+
# @option govuk_accordion_options [String] :classes additional CSS classes for the accordion HTML
|
28
|
+
# @option govuk_accordion_options [Integer] :heading_level (2) heading level, from 1 to 6
|
29
|
+
# @option govuk_accordion_options [Hash] :attributes ({ data: { module: 'govuk-accordion' } }) any additional
|
30
|
+
# attributes that will added as part of the HTML
|
31
|
+
#
|
32
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Accordion
|
33
|
+
# which can then be rendered on the page
|
33
34
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
35
|
+
def govuk_accordion(accordion_id, accordion_items, **govuk_accordion_options)
|
36
|
+
(govuk_accordion_options[:attributes] ||= {})[:data] ||= {}
|
37
|
+
govuk_accordion_options[:attributes][:class] = "govuk-accordion #{govuk_accordion_options[:classes]}".rstrip
|
38
|
+
govuk_accordion_options[:attributes][:id] = accordion_id
|
39
|
+
govuk_accordion_options[:attributes][:data][:module] = 'govuk-accordion'
|
40
|
+
govuk_accordion_options[:heading_level] ||= 2
|
40
41
|
|
41
|
-
|
42
|
-
|
43
|
-
|
42
|
+
tag.div(**govuk_accordion_options[:attributes]) do
|
43
|
+
capture do
|
44
|
+
accordion_items.each.with_index(1) { |accordion_item, index| concat(govuk_accordion_section(accordion_id, accordion_item, index, govuk_accordion_options[:heading_level])) }
|
45
|
+
end
|
44
46
|
end
|
45
47
|
end
|
46
|
-
end
|
47
48
|
|
48
|
-
|
49
|
+
private
|
49
50
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
51
|
+
# Generates the HTML for an accordion section, used by {govuk_accordion}
|
52
|
+
#
|
53
|
+
# @param accordion_id [String] used as an id in the HTML for the accordion
|
54
|
+
# @param index [Integer] the index of the accordion item
|
55
|
+
# @param heading_level [Integer] heading level, from 1 to 6
|
56
|
+
#
|
57
|
+
# @option accordion_item [Boolean] :expanded sets whether the section should be expanded
|
58
|
+
# when the page loads for the first time.
|
59
|
+
# @option accordion_item [String] :heading_level (2) Heading level, from 1 to 6
|
60
|
+
# @option accordion_item [String] :heading the heading text for the accordion
|
61
|
+
# @option accordion_item [String] :summary (nil) optional summary text for the accordion header
|
62
|
+
# @option accordion_item [String, ActiveSupport::SafeBuffer] the content within the accordion section
|
63
|
+
#
|
64
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for an accordion section
|
65
|
+
# which is used in {govuk_accordion}
|
65
66
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
67
|
+
def govuk_accordion_section(accordion_id, accordion_item, index, heading_level)
|
68
|
+
tag.div(class: "govuk-accordion__section #{'govuk-accordion__section--expanded' if accordion_item[:expanded]}".rstrip) do
|
69
|
+
capture do
|
70
|
+
concat(govuk_accordion_section_header(accordion_id, accordion_item, index, heading_level))
|
71
|
+
concat(govuk_accordion_section_content(accordion_id, accordion_item, index))
|
72
|
+
end
|
71
73
|
end
|
72
74
|
end
|
73
|
-
end
|
74
75
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
76
|
+
# Generates the HTML for an accordion section heading, used by {govuk_accordion_section}
|
77
|
+
#
|
78
|
+
# @param (see govuk_accordion_section)
|
79
|
+
#
|
80
|
+
# @option (see govuk_accordion_section)
|
81
|
+
#
|
82
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for an accordion section heading
|
83
|
+
# which is used in {govuk_accordion_section}
|
83
84
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
85
|
+
def govuk_accordion_section_header(accordion_id, accordion_item, index, heading_level)
|
86
|
+
tag.div(class: 'govuk-accordion__section-header') do
|
87
|
+
capture do
|
88
|
+
concat(tag.send("h#{heading_level}", class: 'govuk-accordion__section-heading') do
|
89
|
+
tag.span(accordion_item[:heading], class: 'govuk-accordion__section-button', id: "#{accordion_id}-heading-#{index}")
|
90
|
+
end)
|
91
|
+
concat(tag.div(accordion_item[:summary], class: 'govuk-accordion__section-summary govuk-body', id: "#{accordion_id}-summary-#{index}")) if accordion_item[:summary]
|
92
|
+
end
|
91
93
|
end
|
92
94
|
end
|
93
|
-
end
|
94
95
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
96
|
+
# Generates the HTML for an accordion sections content, used by {govuk_accordion_section}
|
97
|
+
#
|
98
|
+
# @param accordion_id [String] used as an id in the HTML for the accordion
|
99
|
+
# @param index [Integer] the index of the accordion item
|
100
|
+
#
|
101
|
+
# @option (see govuk_accordion_section)
|
102
|
+
#
|
103
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for an accordion sections content
|
104
|
+
# which is used in {govuk_accordion_section}
|
104
105
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
106
|
+
def govuk_accordion_section_content(accordion_id, accordion_item, index)
|
107
|
+
tag.div(class: 'govuk-accordion__section-content', id: "#{accordion_id}-content-#{index}", aria: { labelledby: "#{accordion_id}-heading-#{index}" }) do
|
108
|
+
if accordion_item[:content].is_a? ActiveSupport::SafeBuffer
|
109
|
+
accordion_item[:content]
|
110
|
+
else
|
111
|
+
tag.p(accordion_item[:content], class: 'govuk-body')
|
112
|
+
end
|
111
113
|
end
|
112
114
|
end
|
113
115
|
end
|
@@ -2,32 +2,34 @@
|
|
2
2
|
|
3
3
|
require 'action_view'
|
4
4
|
|
5
|
-
module CrownMarketplaceUtils
|
6
|
-
module
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
module CrownMarketplaceUtils
|
6
|
+
module Helpers
|
7
|
+
module GovUkHelper
|
8
|
+
# = GOV.UK Back Link
|
9
|
+
#
|
10
|
+
# This helper is used for generating the back link component from the
|
11
|
+
# {https://design-system.service.gov.uk/components/back-link GDS - Components - Back link}
|
11
12
|
|
12
|
-
|
13
|
-
|
13
|
+
module BackLink
|
14
|
+
include ActionView::Helpers::UrlHelper
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
16
|
+
# Generates the HTML for the GOV.UK Back link component
|
17
|
+
#
|
18
|
+
# @param text [String] the text for the back link
|
19
|
+
# @param href [String] the href for the back link
|
20
|
+
# @param govuk_back_link_options [Hash] options that will be used in customising the HTML
|
21
|
+
#
|
22
|
+
# @option govuk_back_link_options [String] :classes additional CSS classes for the tag HTML
|
23
|
+
# @option govuk_back_link_options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
|
24
|
+
#
|
25
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Back link
|
26
|
+
# which can then be rendered on the page
|
26
27
|
|
27
|
-
|
28
|
-
|
28
|
+
def govuk_back_link(text, href, **govuk_back_link_options)
|
29
|
+
govuk_back_link_options[:class] = "govuk-back-link #{govuk_back_link_options[:classes]}".rstrip
|
29
30
|
|
30
|
-
|
31
|
+
link_to(text, href, class: govuk_back_link_options[:class], **(govuk_back_link_options[:attributes] || {}))
|
32
|
+
end
|
31
33
|
end
|
32
34
|
end
|
33
35
|
end
|
@@ -2,72 +2,74 @@
|
|
2
2
|
|
3
3
|
require 'action_view'
|
4
4
|
|
5
|
-
module CrownMarketplaceUtils
|
6
|
-
module
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
module CrownMarketplaceUtils
|
6
|
+
module Helpers
|
7
|
+
module GovUkHelper
|
8
|
+
# = GOV.UK Breadcrumbs
|
9
|
+
#
|
10
|
+
# This helper is used for generating the breadcrumbs component from the
|
11
|
+
# {https://design-system.service.gov.uk/components/breadcrumbs GDS - Components - Breadcrumbs}
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
module Breadcrumbs
|
14
|
+
include ActionView::Context
|
15
|
+
include ActionView::Helpers::TagHelper
|
16
|
+
include ActionView::Helpers::TextHelper
|
17
|
+
include ActionView::Helpers::UrlHelper
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
19
|
+
# Generates the HTML for the GOV.UK breadcrumbs component
|
20
|
+
#
|
21
|
+
# @param govuk_breadcrumb_items [Array<Hash>] An array of links for the breadcrumbs list. See {#govuk_breadcrumb_link} for details of the items in the array.
|
22
|
+
# @param govuk_breadcrumbs_options [Hash] options that will be used in customising the HTML
|
23
|
+
#
|
24
|
+
# @option govuk_breadcrumbs_options [String] :classes additional CSS classes for the breadcrumbs HTML
|
25
|
+
# @option govuk_breadcrumbs_options [Boolean] :collapse_on_mobile indicates if it is to colapse breadcrumbs on mobile
|
26
|
+
# @option govuk_breadcrumbs_options [Hash] :attributes any additional attributes that will added as part of the HTML
|
27
|
+
#
|
28
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Breadcrumbs
|
29
|
+
# which can then be rendered on the page
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
31
|
+
def govuk_breadcrumbs(govuk_breadcrumb_items, **govuk_breadcrumbs_options)
|
32
|
+
govuk_breadcrumbs_classes = ['govuk-breadcrumbs']
|
33
|
+
govuk_breadcrumbs_classes << govuk_breadcrumbs_options[:classes]
|
34
|
+
govuk_breadcrumbs_classes << 'govuk-breadcrumbs--collapse-on-mobile' if govuk_breadcrumbs_options[:collapse_on_mobile]
|
35
|
+
govuk_breadcrumbs_options[:attributes] ||= {}
|
35
36
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
37
|
+
tag.div(class: govuk_breadcrumbs_classes, **govuk_breadcrumbs_options[:attributes]) do
|
38
|
+
tag.ol(class: 'govuk-breadcrumbs__list') do
|
39
|
+
capture do
|
40
|
+
govuk_breadcrumb_items.each { |govuk_breadcrumb_item| concat(govuk_breadcrumb_link(govuk_breadcrumb_item)) }
|
41
|
+
end
|
40
42
|
end
|
41
43
|
end
|
42
44
|
end
|
43
|
-
end
|
44
45
|
|
45
|
-
|
46
|
+
private
|
46
47
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
48
|
+
# Generates the HTML for each link in the breadcrumbs.
|
49
|
+
# It is called by {#govuk_breadcrumbs} which will pass in the breadcrum item.
|
50
|
+
#
|
51
|
+
# @param govuk_breadcrumb_item [Hash] a hash containg options for the breadcrumb item
|
52
|
+
#
|
53
|
+
# @option govuk_breadcrumb_item [String] :text the text for the link
|
54
|
+
# @option govuk_breadcrumb_item [String] :href the URI for the link. If blank it is assumed that this item relates to current page
|
55
|
+
# @option govuk_breadcrumb_item [Hash] :attributes any additional attributes that will added as part of the HTML.
|
56
|
+
# If the link is blank then it defaults to +{ aria: { current: 'page' } }+
|
57
|
+
#
|
58
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Breadcrumb list item
|
58
59
|
|
59
|
-
|
60
|
-
|
60
|
+
def govuk_breadcrumb_link(govuk_breadcrumb_item)
|
61
|
+
govuk_breadcrumb_item[:attributes] ||= {}
|
61
62
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
63
|
+
if govuk_breadcrumb_item[:href].present?
|
64
|
+
tag.li(class: 'govuk-breadcrumbs__list-item', **govuk_breadcrumb_item[:attributes]) do
|
65
|
+
link_to govuk_breadcrumb_item[:text], govuk_breadcrumb_item[:href], class: 'govuk-breadcrumbs__link'
|
66
|
+
end
|
67
|
+
else
|
68
|
+
(govuk_breadcrumb_item[:attributes][:aria] ||= {}).merge!({ current: 'page' })
|
68
69
|
|
69
|
-
|
70
|
-
|
70
|
+
tag.li(class: 'govuk-breadcrumbs__list-item', **govuk_breadcrumb_item[:attributes]) do
|
71
|
+
govuk_breadcrumb_item[:text]
|
72
|
+
end
|
71
73
|
end
|
72
74
|
end
|
73
75
|
end
|