crown_marketplace_utils 0.1.0.beta.2 → 0.1.0.beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,225 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'action_view'
4
+
5
+ module CrownMarketplaceUtils
6
+ module GovUkHelper
7
+ # = GOV.UK Step by step navigation
8
+ #
9
+ # This helper is used for generating the Step by step navigation component from the
10
+ # {https://design-system.service.gov.uk/patterns/step-by-step-navigation/ GDS - Pages - Step by step navigation}
11
+ #
12
+ # To use this component you need the following from {https://github.com/alphagov/govuk_publishing_components GOV.UK Publishing Components}.
13
+ # For the SCSS components you should add:
14
+ # - {https://github.com/alphagov/govuk_publishing_components/blob/main/app/assets/stylesheets/govuk_publishing_components/components/_step-by-step-nav.scss _step-by-step-nav.scss}
15
+ # - {https://github.com/alphagov/govuk_publishing_components/blob/main/app/assets/stylesheets/govuk_publishing_components/components/_step-by-step-nav-related.scss _step-by-step-nav-related.scss}
16
+ # - {https://github.com/alphagov/govuk_publishing_components/blob/main/app/assets/stylesheets/govuk_publishing_components/components/_step-by-step-nav-header.scss _step-by-step-nav-header.scss}
17
+ # For the JavaScript you should add:
18
+ # - {https://github.com/alphagov/govuk_publishing_components/blob/main/app/assets/javascripts/govuk_publishing_components/components/step-by-step-nav.js step-by-step-nav.js}
19
+
20
+ module StepByStepNavigation
21
+ include ActionView::Helpers
22
+ include ActionView::Context
23
+
24
+ # Generates the HTML for the GOV.UK Step by step navigation component (experimental)
25
+ #
26
+ # @param step_by_step_sections [Array] the navigation items that will be rendered to the page.
27
+ # See {govuk_step_by_step_navigation_section} for more details
28
+ # @param govuk_step_by_step_navigation_options [Hash] options that will be used in customising the HTML
29
+ #
30
+ # @option govuk_step_by_step_navigation_options [String] :classes additional CSS classes for the step by step navigation HTML
31
+ # @option govuk_step_by_step_navigation_options [Hash] :attributes ({data: { module: 'govuk-step-by-step-navigation', 'show-text': 'Show', 'hide-text': 'Hide', 'show-all-text': 'Show all', 'hide-all-text': 'Hide all' } })
32
+ # any additional attributes that will added as part of the HTML
33
+ #
34
+ # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Step by step navigation
35
+ # which can then be rendered on the page
36
+
37
+ def govuk_step_by_step_navigation(step_by_step_sections, **govuk_step_by_step_navigation_options)
38
+ govuk_step_by_step_navigation_classes = ['gem-c-step-nav gem-c-step-nav--large gem-c-step-nav--active']
39
+ govuk_step_by_step_navigation_classes << govuk_step_by_step_navigation_options[:classes]
40
+
41
+ tag.div(class: govuk_step_by_step_navigation_classes, **govuk_step_by_step_navigation_attributes(**govuk_step_by_step_navigation_options)) do
42
+ tag.ol(class: 'gem-c-step-nav__steps') do
43
+ capture do
44
+ step_by_step_sections.each.with_index(1) { |step_by_step_section, section_index| concat(govuk_step_by_step_navigation_section(step_by_step_section, section_index.to_s)) }
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ private
51
+
52
+ # The HTML for a section within GOV.UK Step by step navigation, used by {govuk_step_by_step_navigation}
53
+ #
54
+ # @param step_by_step_section [Hash] the parameters that will be used to create the section
55
+ # @param section_index [String] the index of the section
56
+ #
57
+ # @option step_by_step_section [Hash] :heading the paramaters for the section heading,
58
+ # see {govuk_step_by_step_navigation_heading} for more details
59
+ # @option step_by_step_section [Array] :content the paramaters for the section content,
60
+ # see {govuk_step_by_step_navigation_content} for more details
61
+ #
62
+ # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Step by step navigation section
63
+ # which is used in {govuk_step_by_step_navigation}
64
+
65
+ def govuk_step_by_step_navigation_section(step_by_step_section, section_index)
66
+ section_id = convert_to_id(step_by_step_section[:heading][:text])
67
+
68
+ tag.li(class: 'gem-c-step-nav__step js-step', id: section_id) do
69
+ capture do
70
+ concat(govuk_step_by_step_navigation_heading(step_by_step_section[:heading], section_index))
71
+ concat(govuk_step_by_step_navigation_content(step_by_step_section[:content], section_id, section_index))
72
+ end
73
+ end
74
+ end
75
+
76
+ # The HTML for a section heading within GOV.UK Step by step navigation, used by {govuk_step_by_step_navigation_section}
77
+ #
78
+ # @param section_heading [Hash] the parameters that will be used to create the heading
79
+ # @param section_index [String] the index of the section
80
+ #
81
+ # @option section_heading [Hash] :text text for the section heading
82
+ # @option section_heading [Hash] :logic (nil) text to show instead of a number in the sidebar
83
+ #
84
+ # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Step by step navigation section heading
85
+ # which is used in {govuk_step_by_step_navigation_section}
86
+
87
+ def govuk_step_by_step_navigation_heading(section_heading, section_index)
88
+ logic = section_heading[:logic]
89
+
90
+ tag.div(class: 'gem-c-step-nav__header js-toggle-panel', data: { position: section_index }) do
91
+ tag.h2(class: 'gem-c-step-nav__title') do
92
+ capture do
93
+ concat(tag.span(class: "gem-c-step-nav__circle gem-c-step-nav__circle--#{logic ? 'logic' : 'number'}") do
94
+ tag.span(class: 'gem-c-step-nav__circle-inner') do
95
+ tag.span(class: 'gem-c-step-nav__circle-background') do
96
+ capture do
97
+ concat(tag.span('Step', class: 'govuk-visually-hidden'))
98
+ concat(logic || section_index)
99
+ end
100
+ end
101
+ end
102
+ end)
103
+ concat(tag.span(class: 'js-step-title') do
104
+ tag.span(section_heading[:text], class: 'js-step-title-text')
105
+ end)
106
+ end
107
+ end
108
+ end
109
+ end
110
+
111
+ # The HTML for a section content within GOV.UK Step by step navigation, used by {govuk_step_by_step_navigation_section}
112
+ #
113
+ # @param content [Array] an array of the content items that will be rendered within the section.
114
+ # Only two types of content are allowed:
115
+ # - +:paragraph+ - see {govuk_step_by_step_navigation_paragraph}
116
+ # - +:list+ - see {govuk_step_by_step_navigation_list}
117
+ # @param section_id [String] the id of the section
118
+ # @param section_index [String] the index of the section
119
+ #
120
+ # @option content [Symbol] :type the type of content, either +:paragraph+ or +list+
121
+ # @option content [Symbol] :text the text for the paragraph. Ignored unless the +type+ is +:list+
122
+ # @option content [Symbol] :items the items for the list. Ignored unless the +type+ is +:paragraph+
123
+ #
124
+ # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Step by step navigation section content
125
+ # which is used in {govuk_step_by_step_navigation_section}
126
+
127
+ def govuk_step_by_step_navigation_content(content, section_id, section_index)
128
+ tag.div(class: 'gem-c-step-nav__panel js-panel', id: "step-panel-#{section_id}-#{section_index}") do
129
+ capture do
130
+ content.each do |element|
131
+ concat(
132
+ case element[:type]
133
+ when :paragraph
134
+ govuk_step_by_step_navigation_paragraph(element[:text])
135
+ when :list
136
+ govuk_step_by_step_navigation_list(element[:items])
137
+ end
138
+ )
139
+ end
140
+ end
141
+ end
142
+ end
143
+
144
+ # The HTML for the paragraph item within the GOV.UK Step by step navigation content, used by {govuk_step_by_step_navigation_content}
145
+ #
146
+ # @param text [String] the text for the paragraph
147
+ #
148
+ # @return [ActiveSupport::SafeBuffer] the HTML for the paragraph
149
+ # which is used in {govuk_step_by_step_navigation_content}
150
+
151
+ def govuk_step_by_step_navigation_paragraph(text)
152
+ tag.p(
153
+ text,
154
+ class: 'gem-c-step-nav__paragraph',
155
+ )
156
+ end
157
+
158
+ # The HTML for the list items within the GOV.UK Step by step navigation content, used by {govuk_step_by_step_navigation_content}
159
+ #
160
+ # @param items [Array] an array of the list items,
161
+ # see {govuk_step_by_step_navigation_list_item} for more details
162
+ #
163
+ # @return [ActiveSupport::SafeBuffer] the HTML for the list
164
+ # which is used in {govuk_step_by_step_navigation_content}
165
+
166
+ def govuk_step_by_step_navigation_list(items)
167
+ tag.ul(class: 'gem-c-step-nav__list gem-c-step-nav__list--choice', data: { length: items.length.to_s }) do
168
+ capture do
169
+ items.each do |item|
170
+ concat(govuk_step_by_step_navigation_list_item(item[:text], item[:no_marker]))
171
+ end
172
+ end
173
+ end
174
+ end
175
+
176
+ # The HTML for a list item, used by {govuk_step_by_step_navigation_list}
177
+ #
178
+ # @param text [Symbol] the text of the list item
179
+ # @param no_marker [Symbol] (nil) switch to hide the bullet marker
180
+ #
181
+ # @return [ActiveSupport::SafeBuffer] the HTML for the list item
182
+ # which is used in {govuk_step_by_step_navigation_list}
183
+
184
+ def govuk_step_by_step_navigation_list_item(text, no_marker)
185
+ list_item_classes = ['gem-c-step-nav__list-item js-list-item']
186
+ list_item_classes << 'gem-c-step-nav__list--no-marker' if no_marker
187
+
188
+ tag.li(class: list_item_classes) do
189
+ tag.span(text)
190
+ end
191
+ end
192
+
193
+ # Converts the title text into a string to be used as the section id
194
+ #
195
+ # @param title [String] the section title that will be converted
196
+ #
197
+ # @return [String] the section id
198
+
199
+ def convert_to_id(title)
200
+ title.downcase.gsub(' ', '-').gsub('(', '').gsub(')', '')
201
+ end
202
+
203
+ # Generates a hash with the attributes used in {govuk_step_by_step_navigation}
204
+ #
205
+ # @param govuk_step_by_step_navigation_options [Hash] options that will be used in customising the HTML
206
+ #
207
+ # @option (see govuk_step_by_step_navigation)
208
+ #
209
+ # @return [Hash] contains the HTMl attributes used in {govuk_step_by_step_navigation}
210
+
211
+ def govuk_step_by_step_navigation_attributes(**govuk_step_by_step_navigation_options)
212
+ govuk_step_by_step_navigation_options[:attributes] ||= {}
213
+ (govuk_step_by_step_navigation_options[:attributes][:data] ||= {}).merge!({ module: 'govuk-step-by-step-navigation' })
214
+
215
+ DEFAULT_SHOW_HIDE_TEXT.each { |key, value| govuk_step_by_step_navigation_options[:attributes][:data][key] ||= value }
216
+
217
+ govuk_step_by_step_navigation_options[:attributes]
218
+ end
219
+
220
+ # Default text for the show and hide buttons which are part of each section
221
+
222
+ DEFAULT_SHOW_HIDE_TEXT = { 'show-text': 'Show', 'hide-text': 'Hide', 'show-all-text': 'Show all', 'hide-all-text': 'Hide all' }.freeze
223
+ end
224
+ end
225
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'action_view'
4
+
5
+ module CrownMarketplaceUtils
6
+ module GovUkHelper
7
+ # = GOV.UK Tag
8
+ #
9
+ # This helper is used for generating the tag component from the
10
+ # {https://design-system.service.gov.uk/components/tag GDS - Components - Tag}
11
+
12
+ module Tag
13
+ include ActionView::Context
14
+ include ActionView::Helpers::TagHelper
15
+
16
+ # Generates the HTML for the GOV.UK Tag component
17
+ #
18
+ # @param text [String] the text for the tag
19
+ # @param colour [String] optional colour for the tag,
20
+ # see {https://design-system.service.gov.uk/components/tag/#additional-colours Tag - Additional colours}
21
+ # for available colours in GOV.UK Frontend
22
+ # @param govuk_tag_options [Hash] options that will be used in customising the HTML
23
+ #
24
+ # @option govuk_tag_options [String] :classes additional CSS classes for the tag HTML
25
+ # @option govuk_tag_options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
26
+ #
27
+ # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Tag
28
+ # which can then be rendered on the page
29
+
30
+ def govuk_tag(text, colour = nil, **govuk_tag_options)
31
+ govuk_tag_classes = ['govuk-tag']
32
+ govuk_tag_classes << "govuk-tag--#{colour}" if colour
33
+ govuk_tag_classes << govuk_tag_options[:classes]
34
+
35
+ tag.strong(text, class: govuk_tag_classes, **(govuk_tag_options[:attributes] || {}))
36
+ end
37
+ end
38
+ end
39
+ end
@@ -4,8 +4,22 @@ require_relative 'gov_uk_helper/breadcrumbs'
4
4
  require_relative 'gov_uk_helper/button'
5
5
  require_relative 'gov_uk_helper/details'
6
6
  require_relative 'gov_uk_helper/error_message'
7
+ require_relative 'gov_uk_helper/field'
8
+ require_relative 'gov_uk_helper/field/character_count'
9
+ require_relative 'gov_uk_helper/field/checkboxes'
10
+ require_relative 'gov_uk_helper/field/input'
11
+ require_relative 'gov_uk_helper/field/select'
12
+ require_relative 'gov_uk_helper/field/textarea'
13
+ require_relative 'gov_uk_helper/field/radios'
14
+ require_relative 'gov_uk_helper/fieldset'
7
15
  require_relative 'gov_uk_helper/form_group'
16
+ require_relative 'gov_uk_helper/header'
8
17
  require_relative 'gov_uk_helper/hint'
18
+ require_relative 'gov_uk_helper/label'
19
+ require_relative 'gov_uk_helper/notification_banner'
20
+ require_relative 'gov_uk_helper/pagination'
21
+ require_relative 'gov_uk_helper/step_by_step_navigation'
22
+ require_relative 'gov_uk_helper/tag'
9
23
 
10
24
  module CrownMarketplaceUtils
11
25
  # This module loads in all the GOV.UK Helper methods.
@@ -16,7 +30,21 @@ module CrownMarketplaceUtils
16
30
  include Button
17
31
  include Details
18
32
  include ErrorMessage
33
+ include Field
34
+ include Field::CharacterCount
35
+ include Field::Checkboxes
36
+ include Field::Input
37
+ include Field::Radios
38
+ include Field::Select
39
+ include Field::Textarea
40
+ include Fieldset
19
41
  include FormGroup
42
+ include Header
20
43
  include Hint
44
+ include Label
45
+ include NotificationBanner
46
+ include Pagination
47
+ include StepByStepNavigation
48
+ include Tag
21
49
  end
22
50
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CrownMarketplaceUtils
4
- VERSION = '0.1.0.beta.2'
4
+ VERSION = '0.1.0.beta.3'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crown_marketplace_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.beta.2
4
+ version: 0.1.0.beta.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - tim-s-ccs
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-10-21 00:00:00.000000000 Z
11
+ date: 2022-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionview
@@ -28,114 +28,128 @@ dependencies:
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '2.3'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '2.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: capybara
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 3.38.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.38.0
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rails
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
59
  - - ">="
46
60
  - !ruby/object:Gem::Version
47
- version: '0'
61
+ version: '6.0'
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
66
  - - ">="
53
67
  - !ruby/object:Gem::Version
54
- version: '0'
68
+ version: '6.0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rspec
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - "~>"
60
74
  - !ruby/object:Gem::Version
61
- version: '3.2'
75
+ version: '3.12'
62
76
  type: :development
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
80
  - - "~>"
67
81
  - !ruby/object:Gem::Version
68
- version: '3.2'
82
+ version: '3.12'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: rubocop
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
- - - ">="
87
+ - - "~>"
74
88
  - !ruby/object:Gem::Version
75
- version: '0'
89
+ version: '1.36'
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
- - - ">="
94
+ - - "~>"
81
95
  - !ruby/object:Gem::Version
82
- version: '0'
96
+ version: '1.36'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: rubocop-rails
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
- - - ">="
101
+ - - "~>"
88
102
  - !ruby/object:Gem::Version
89
- version: '0'
103
+ version: '2.16'
90
104
  type: :development
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
- - - ">="
108
+ - - "~>"
95
109
  - !ruby/object:Gem::Version
96
- version: '0'
110
+ version: '2.16'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: rubocop-rake
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
- - - ">="
115
+ - - "~>"
102
116
  - !ruby/object:Gem::Version
103
- version: '0'
117
+ version: '0.6'
104
118
  type: :development
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
107
121
  requirements:
108
- - - ">="
122
+ - - "~>"
109
123
  - !ruby/object:Gem::Version
110
- version: '0'
124
+ version: '0.6'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: rubocop-rspec
113
127
  requirement: !ruby/object:Gem::Requirement
114
128
  requirements:
115
- - - ">="
129
+ - - "~>"
116
130
  - !ruby/object:Gem::Version
117
- version: '0'
131
+ version: '2.13'
118
132
  type: :development
119
133
  prerelease: false
120
134
  version_requirements: !ruby/object:Gem::Requirement
121
135
  requirements:
122
- - - ">="
136
+ - - "~>"
123
137
  - !ruby/object:Gem::Version
124
- version: '0'
138
+ version: '2.13'
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: yard
127
141
  requirement: !ruby/object:Gem::Requirement
128
142
  requirements:
129
- - - ">="
143
+ - - "~>"
130
144
  - !ruby/object:Gem::Version
131
- version: '0'
145
+ version: '0.9'
132
146
  type: :development
133
147
  prerelease: false
134
148
  version_requirements: !ruby/object:Gem::Requirement
135
149
  requirements:
136
- - - ">="
150
+ - - "~>"
137
151
  - !ruby/object:Gem::Version
138
- version: '0'
152
+ version: '0.9'
139
153
  description: A Gem containing shared code for the CCS Crown Marketplace projects,
140
154
  for example view helpers
141
155
  email:
@@ -159,8 +173,22 @@ files:
159
173
  - lib/crown_marketplace_utils/gov_uk_helper/button.rb
160
174
  - lib/crown_marketplace_utils/gov_uk_helper/details.rb
161
175
  - lib/crown_marketplace_utils/gov_uk_helper/error_message.rb
176
+ - lib/crown_marketplace_utils/gov_uk_helper/field.rb
177
+ - lib/crown_marketplace_utils/gov_uk_helper/field/character_count.rb
178
+ - lib/crown_marketplace_utils/gov_uk_helper/field/checkboxes.rb
179
+ - lib/crown_marketplace_utils/gov_uk_helper/field/input.rb
180
+ - lib/crown_marketplace_utils/gov_uk_helper/field/radios.rb
181
+ - lib/crown_marketplace_utils/gov_uk_helper/field/select.rb
182
+ - lib/crown_marketplace_utils/gov_uk_helper/field/textarea.rb
183
+ - lib/crown_marketplace_utils/gov_uk_helper/fieldset.rb
162
184
  - lib/crown_marketplace_utils/gov_uk_helper/form_group.rb
185
+ - lib/crown_marketplace_utils/gov_uk_helper/header.rb
163
186
  - lib/crown_marketplace_utils/gov_uk_helper/hint.rb
187
+ - lib/crown_marketplace_utils/gov_uk_helper/label.rb
188
+ - lib/crown_marketplace_utils/gov_uk_helper/notification_banner.rb
189
+ - lib/crown_marketplace_utils/gov_uk_helper/pagination.rb
190
+ - lib/crown_marketplace_utils/gov_uk_helper/step_by_step_navigation.rb
191
+ - lib/crown_marketplace_utils/gov_uk_helper/tag.rb
164
192
  - lib/crown_marketplace_utils/version.rb
165
193
  - sig/crown_marketplace_utils.rbs
166
194
  homepage: https://github.com/tim-s-ccs/crown_marketplace_utils