govuk_elements_rails 0.3.0 → 1.1.2

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.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +19 -0
  3. data/README.md +165 -46
  4. data/lib/govuk_elements_rails.rb +0 -1
  5. data/lib/govuk_elements_rails/engine.rb +0 -10
  6. data/vendor/assets/javascripts/details.polyfill.js +29 -43
  7. data/vendor/assets/stylesheets/_govuk-elements.scss +54 -0
  8. data/vendor/assets/stylesheets/elements/_base.scss +126 -0
  9. data/vendor/assets/stylesheets/elements/_breadcrumbs.scss +6 -0
  10. data/vendor/assets/stylesheets/elements/_buttons.scss +5 -5
  11. data/vendor/assets/stylesheets/elements/_components.scss +9 -0
  12. data/vendor/assets/stylesheets/elements/_details.scss +3 -9
  13. data/vendor/assets/stylesheets/elements/_elements-typography.scss +102 -9
  14. data/vendor/assets/stylesheets/elements/_forms.scss +84 -61
  15. data/vendor/assets/stylesheets/elements/_helpers.scss +6 -12
  16. data/vendor/assets/stylesheets/elements/_icons.scss +63 -207
  17. data/vendor/assets/stylesheets/elements/_layout.scss +9 -22
  18. data/vendor/assets/stylesheets/elements/_lists.scss +10 -13
  19. data/vendor/assets/stylesheets/elements/_panels.scss +24 -17
  20. data/vendor/assets/stylesheets/elements/_phase-banner.scss +10 -0
  21. data/vendor/assets/stylesheets/elements/_tables.scss +1 -5
  22. data/vendor/assets/stylesheets/elements/forms/_form-block-labels.scss +8 -7
  23. data/vendor/assets/stylesheets/elements/forms/_form-validation.scss +0 -3
  24. metadata +33 -49
  25. data/LICENCE +0 -20
  26. data/app/builders/govuk_elements_form_builder.rb +0 -77
  27. data/app/builders/labelling_form_builder.rb +0 -316
  28. data/lib/govuk_elements_rails/version.rb +0 -5
  29. data/vendor/assets/images/icons/accordian-arrow-2x.png +0 -0
  30. data/vendor/assets/images/icons/accordian-arrow.png +0 -0
  31. data/vendor/assets/images/icons/arrow-sprite.png +0 -0
  32. data/vendor/assets/images/icons/icon-calendar-2x.png +0 -0
  33. data/vendor/assets/images/icons/icon-calendar.png +0 -0
  34. data/vendor/assets/images/icons/icon-file-download-2x.png +0 -0
  35. data/vendor/assets/images/icons/icon-file-download.png +0 -0
  36. data/vendor/assets/images/icons/icon-important-2x.png +0 -0
  37. data/vendor/assets/images/icons/icon-important.png +0 -0
  38. data/vendor/assets/images/icons/icon-information-2x.png +0 -0
  39. data/vendor/assets/images/icons/icon-information.png +0 -0
  40. data/vendor/assets/images/icons/icon-locator-2x.png +0 -0
  41. data/vendor/assets/images/icons/icon-locator.png +0 -0
  42. data/vendor/assets/images/icons/icon-pointer-2x.png +0 -0
  43. data/vendor/assets/images/icons/icon-pointer-black-2x.png +0 -0
  44. data/vendor/assets/images/icons/icon-pointer-black.png +0 -0
  45. data/vendor/assets/images/icons/icon-pointer-indexed.png +0 -0
  46. data/vendor/assets/images/icons/icon-pointer.png +0 -0
  47. data/vendor/assets/images/icons/icon-search-2x.png +0 -0
  48. data/vendor/assets/images/icons/icon-search.png +0 -0
  49. data/vendor/assets/images/icons/player-icon-forward.png +0 -0
  50. data/vendor/assets/images/icons/player-icon-pause.png +0 -0
  51. data/vendor/assets/images/icons/player-icon-play.png +0 -0
  52. data/vendor/assets/images/icons/player-icon-rewind.png +0 -0
  53. data/vendor/assets/images/icons/player-icon-volume.png +0 -0
  54. data/vendor/assets/javascripts/application.js +0 -157
  55. data/vendor/assets/javascripts/bind.js +0 -40
  56. data/vendor/assets/javascripts/selection-buttons.js +0 -111
  57. data/vendor/assets/stylesheets/elements-page-ie6.scss +0 -5
  58. data/vendor/assets/stylesheets/elements-page-ie7.scss +0 -4
  59. data/vendor/assets/stylesheets/elements-page-ie8.scss +0 -4
  60. data/vendor/assets/stylesheets/elements-page.scss +0 -386
  61. data/vendor/assets/stylesheets/main-ie6.scss +0 -5
  62. data/vendor/assets/stylesheets/main-ie7.scss +0 -4
  63. data/vendor/assets/stylesheets/main-ie8.scss +0 -4
  64. data/vendor/assets/stylesheets/main.scss +0 -36
  65. data/vendor/assets/stylesheets/prism.scss +0 -144
  66. data/vendor/assets/stylesheets/service-design-manual/helpers/_breadcrumbs.scss +0 -81
  67. data/vendor/assets/stylesheets/service-design-manual/helpers/_page-header.scss +0 -28
  68. data/vendor/assets/stylesheets/service-design-manual/styleguide/_colours.scss +0 -3
@@ -1,29 +1,36 @@
1
1
  // Panels
2
2
  // ==========================================================================
3
- // GOV.UK front end toolkit dependencies
4
- @import "helpers";
5
3
 
6
-
7
- // Indented panels with a grey left hand border
8
- .panel-indent {
4
+ .panel {
9
5
  @extend %contain-floats;
10
6
  clear: both;
11
- border-left: 4px solid $border-colour;
7
+ border-left-style: solid;
8
+ border-color: $border-colour;
12
9
 
13
- padding: 10px 0 10px $gutter-half;
14
- margin: ($gutter $gutter-half $gutter*1.5 0);
10
+ padding: em(15,19);
11
+ margin-bottom: em(15,19);
15
12
 
16
- legend {
13
+ :first-child {
17
14
  margin-top: 0;
18
15
  }
19
-
20
- // Remove bottom margin on last paragraph
21
- p:only-child,
22
- p:last-child {
23
- margin-bottom: 0;
24
- }
25
-
26
- .form-group:last-child {
16
+
17
+ :only-child,
18
+ :last-child {
27
19
  margin-bottom: 0;
28
20
  }
29
21
  }
22
+
23
+ .panel-border-wide {
24
+ border-left-width: 10px;
25
+ }
26
+
27
+ // Used to show the left edge of "toggled" content
28
+ .panel-border-narrow {
29
+ border-left-width: 5px;
30
+ }
31
+
32
+ // Panels within form groups
33
+ // Remove the bottom padding as .form-group sets a bottom margin
34
+ .form-group .panel-border-narrow {
35
+ padding-bottom: 0;
36
+ }
@@ -0,0 +1,10 @@
1
+ // Phase banners
2
+ // ==========================================================================
3
+
4
+ .phase-banner-alpha {
5
+ @include phase-banner($state: alpha);
6
+ }
7
+
8
+ .phase-banner-beta {
9
+ @include phase-banner($state: beta);
10
+ }
@@ -1,9 +1,5 @@
1
1
  // Tables
2
2
  // ==========================================================================
3
- // GOV.UK front end toolkit dependencies
4
- @import "typography";
5
- @import "colours";
6
-
7
3
 
8
4
  table {
9
5
  border-collapse: collapse;
@@ -25,7 +21,7 @@ table {
25
21
  // Right align headings for numeric content
26
22
  &.numeric {
27
23
  text-align: right;
28
- }
24
+ }
29
25
  }
30
26
 
31
27
  // Use tabular numbers for numeric table cells
@@ -1,11 +1,6 @@
1
1
  // Large hit area
2
2
  // Radio buttons & checkboxes
3
3
 
4
- @import "colours";
5
- @import "measurements";
6
- @import "conditionals";
7
-
8
-
9
4
  // By default, block labels stack vertically
10
5
  .block-label {
11
6
 
@@ -16,7 +11,7 @@
16
11
 
17
12
  background: $panel-colour;
18
13
  border: 1px solid $panel-colour;
19
- padding: (18px $gutter $gutter-half $gutter*1.5);
14
+ padding: (18px $gutter $gutter-half $gutter*1.8);
20
15
 
21
16
  margin-bottom: 10px;
22
17
  cursor: pointer; // Encourage clicking on block labels
@@ -29,9 +24,15 @@
29
24
  // Absolutely position inputs within label, to allow text to wrap
30
25
  input {
31
26
  position: absolute;
32
- top: 18px;
27
+ top: 15px;
33
28
  left: $gutter-half;
34
29
  cursor: pointer;
30
+ margin: 0;
31
+ width: 29px;
32
+ height: 29px;
33
+ @include ie(8) {
34
+ top: 12px;
35
+ }
35
36
  }
36
37
 
37
38
  // Change border on hover
@@ -1,9 +1,6 @@
1
1
  // Form validation
2
2
  // ==========================================================================
3
3
 
4
- // Update the error colour in the govuk frontend toolkit
5
- $error-colour: #b10e1e;
6
-
7
4
  // Using the classname .error as it's shorter than .validation and easier to type!
8
5
  .error {
9
6
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_elements_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob McKinnon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-04 00:00:00.000000000 Z
11
+ date: 2016-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -50,55 +50,46 @@ dependencies:
50
50
  - - ">="
51
51
  - !ruby/object:Gem::Version
52
52
  version: 3.2.0
53
- description: A gem wrapper around SHA 281fb6b9e14129a6c3f982c46c43970e3f2f7f78 govuk_elements
54
- (heads/master) that pulls stylesheet and javascript files into a Rails app.
53
+ - !ruby/object:Gem::Dependency
54
+ name: govuk_frontend_toolkit
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: 4.6.1
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 4.6.1
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: 4.6.1
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 4.6.1
73
+ description: |-
74
+ A gem wrapper around govuk_elements v1.1.2
75
+ that pulls stylesheet and javascript files into a Rails app. Changelog: https://github.com/alphagov/govuk_elements/blob/c19cf54ebf507b7e22b8a5e4df030b4f480f765d
76
+ /CHANGELOG.md
55
77
  email: rob.mckinnon ~@nospam@~ digital.justice.gov.uk
56
78
  executables: []
57
79
  extensions: []
58
80
  extra_rdoc_files:
59
81
  - README.md
60
82
  files:
61
- - LICENCE
83
+ - LICENSE
62
84
  - README.md
63
- - app/builders/govuk_elements_form_builder.rb
64
- - app/builders/labelling_form_builder.rb
65
85
  - lib/govuk_elements_rails.rb
66
86
  - lib/govuk_elements_rails/engine.rb
67
- - lib/govuk_elements_rails/version.rb
68
- - vendor/assets/images/icons/accordian-arrow-2x.png
69
- - vendor/assets/images/icons/accordian-arrow.png
70
- - vendor/assets/images/icons/arrow-sprite.png
71
- - vendor/assets/images/icons/icon-calendar-2x.png
72
- - vendor/assets/images/icons/icon-calendar.png
73
- - vendor/assets/images/icons/icon-file-download-2x.png
74
- - vendor/assets/images/icons/icon-file-download.png
75
- - vendor/assets/images/icons/icon-important-2x.png
76
- - vendor/assets/images/icons/icon-important.png
77
- - vendor/assets/images/icons/icon-information-2x.png
78
- - vendor/assets/images/icons/icon-information.png
79
- - vendor/assets/images/icons/icon-locator-2x.png
80
- - vendor/assets/images/icons/icon-locator.png
81
- - vendor/assets/images/icons/icon-pointer-2x.png
82
- - vendor/assets/images/icons/icon-pointer-black-2x.png
83
- - vendor/assets/images/icons/icon-pointer-black.png
84
- - vendor/assets/images/icons/icon-pointer-indexed.png
85
- - vendor/assets/images/icons/icon-pointer.png
86
- - vendor/assets/images/icons/icon-search-2x.png
87
- - vendor/assets/images/icons/icon-search.png
88
- - vendor/assets/images/icons/player-icon-forward.png
89
- - vendor/assets/images/icons/player-icon-pause.png
90
- - vendor/assets/images/icons/player-icon-play.png
91
- - vendor/assets/images/icons/player-icon-rewind.png
92
- - vendor/assets/images/icons/player-icon-volume.png
93
- - vendor/assets/javascripts/application.js
94
- - vendor/assets/javascripts/bind.js
95
87
  - vendor/assets/javascripts/details.polyfill.js
96
- - vendor/assets/javascripts/selection-buttons.js
97
- - vendor/assets/stylesheets/elements-page-ie6.scss
98
- - vendor/assets/stylesheets/elements-page-ie7.scss
99
- - vendor/assets/stylesheets/elements-page-ie8.scss
100
- - vendor/assets/stylesheets/elements-page.scss
88
+ - vendor/assets/stylesheets/_govuk-elements.scss
89
+ - vendor/assets/stylesheets/elements/_base.scss
90
+ - vendor/assets/stylesheets/elements/_breadcrumbs.scss
101
91
  - vendor/assets/stylesheets/elements/_buttons.scss
92
+ - vendor/assets/stylesheets/elements/_components.scss
102
93
  - vendor/assets/stylesheets/elements/_details.scss
103
94
  - vendor/assets/stylesheets/elements/_elements-typography.scss
104
95
  - vendor/assets/stylesheets/elements/_forms.scss
@@ -107,19 +98,12 @@ files:
107
98
  - vendor/assets/stylesheets/elements/_layout.scss
108
99
  - vendor/assets/stylesheets/elements/_lists.scss
109
100
  - vendor/assets/stylesheets/elements/_panels.scss
101
+ - vendor/assets/stylesheets/elements/_phase-banner.scss
110
102
  - vendor/assets/stylesheets/elements/_reset.scss
111
103
  - vendor/assets/stylesheets/elements/_tables.scss
112
104
  - vendor/assets/stylesheets/elements/forms/_form-block-labels.scss
113
105
  - vendor/assets/stylesheets/elements/forms/_form-date.scss
114
106
  - vendor/assets/stylesheets/elements/forms/_form-validation.scss
115
- - vendor/assets/stylesheets/main-ie6.scss
116
- - vendor/assets/stylesheets/main-ie7.scss
117
- - vendor/assets/stylesheets/main-ie8.scss
118
- - vendor/assets/stylesheets/main.scss
119
- - vendor/assets/stylesheets/prism.scss
120
- - vendor/assets/stylesheets/service-design-manual/helpers/_breadcrumbs.scss
121
- - vendor/assets/stylesheets/service-design-manual/helpers/_page-header.scss
122
- - vendor/assets/stylesheets/service-design-manual/styleguide/_colours.scss
123
107
  homepage: https://github.com/ministryofjustice/govuk_elements_rails
124
108
  licenses: []
125
109
  metadata: {}
@@ -142,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
142
126
  version: '0'
143
127
  requirements: []
144
128
  rubyforge_project:
145
- rubygems_version: 2.4.5
129
+ rubygems_version: 2.2.2
146
130
  signing_key:
147
131
  specification_version: 4
148
132
  summary: A gem wrapper around http://github.com/alphagov/govuk_elements that pulls
data/LICENCE DELETED
@@ -1,20 +0,0 @@
1
- Copyright (c) 2014 HM Government
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,77 +0,0 @@
1
- class GovukElementsFormBuilder < ActionView::Helpers::FormBuilder
2
- attr_reader :template, :object_name
3
-
4
- def text_area(method, **options)
5
- with_label(method) {
6
- super(method, add_class(options, 'text form-control'))
7
- }
8
- end
9
-
10
- def bold_label(method, text: nil, **options)
11
- label(method, text, add_class(options, 'form-label'))
12
- end
13
-
14
- def radio_buttons(method, values, labeler: labeler, **options)
15
- radio_button_fieldset(method, options) {
16
- with_label(method) {
17
- values.map { |value|
18
- label(method, value: value, class: 'block-label') {
19
- radio_button(method, value) + labeler.call(value)
20
- }
21
- }.join.html_safe
22
- }
23
- }
24
- end
25
-
26
- def text_field(method, **options)
27
- with_label(method) {
28
- super(method, add_class(options, 'form-control'))
29
- }
30
- end
31
-
32
- def password_field(method, **options)
33
- with_label(method) {
34
- super(method, add_class(options, 'form-control'))
35
- }
36
- end
37
-
38
- def file_field(method, **options)
39
- with_label(method) {
40
- super(method, add_class(options, 'form-control'))
41
- }
42
- end
43
-
44
- def collection_select(method, values, valuer: nil, labeler: nil, **options)
45
- valuer ||= ->(a) { a.respond_to?(:to_param) ? a.to_param : a }
46
- labeler ||= ->(a) { a }
47
- with_label(method) {
48
- super(
49
- method, values, valuer, labeler, options,
50
- class: 'select form-control'
51
- )
52
- }
53
- end
54
-
55
- def button(value = nil, **options)
56
- super(value, add_class(options, 'button'))
57
- end
58
-
59
- def with_label(method, &content)
60
- error_messages = object.errors[method].map { |error|
61
- template.content_tag(:p, class: 'error') { error }
62
- }.join.html_safe
63
- bold_label(method) + content.call + error_messages
64
- end
65
-
66
- def add_class(options, klass)
67
- options.merge(class: [options[:class], klass].compact.join(' '))
68
- end
69
-
70
- private
71
-
72
- def radio_button_fieldset(method, options, &blk)
73
- id = [object_name, method].join('_')
74
- klass = options[:inline] ? 'inline' : ''
75
- template.content_tag(:fieldset, id: id, class: klass, &blk)
76
- end
77
- end
@@ -1,316 +0,0 @@
1
-
2
- class LabellingFormBuilder < ActionView::Helpers::FormBuilder
3
-
4
- include ActionView::Helpers::CaptureHelper
5
- include ActionView::Helpers::TagHelper
6
- include ActionView::Context
7
-
8
- def text_field_row(attribute, options={})
9
- row_input attribute, :text_field, options
10
- end
11
-
12
- def text_area_row(attribute, options={})
13
- row_input attribute, :text_area, options
14
- end
15
-
16
- def moj_date_fieldset attribute, legend, options = {}, example_date = Date.today, explanatory_text = nil
17
- df = MojDateFieldset.new(self, attribute, legend, options, example_date, explanatory_text)
18
- df.emit
19
- end
20
-
21
- # produces an postcode picker widget - this will produce an address/street and postcode attributes for the given object type
22
- # @param [String] attribute: the name of the attribute on Claim which is to have the street and postcode attributes (e.g. property, defendant_1)
23
- # @param [Hash] options: options to control the way in which the potcode picker is displayed, and what html is generated in the form:
24
- # :prefix - the prefix to be applied to each element in the form
25
- # :postcode_attr - the name of the postcode attribute if not 'postcode'
26
- # :address_attr - the name of the address attribute if not 'street'
27
- # :name - the prefix of the name given to the street and postcode attributes if not 'claim['xxxx'] where xxxx is the attribute
28
- # :street_hint - and html which is to be inserted as a hint above the street textarea
29
- # :vc - list of valid countries: postcodes that return a country not in the supplied list will be marked as invalid.
30
- # If not supplied or blank, all countries are valid. Countries should be joined by '+' and spaces in country names should be replaced
31
- # by underscores, e.g "england+wales+channel_islands+isle_of_man"
32
- # :button_label - the text to use on the Find UK Address button if not 'Find Uk Address'
33
- #
34
- def moj_postcode_picker attribute, options = {}
35
- default_options = {
36
- :prefix => "claim_#{attribute}",
37
- :postcode_attr => :postcode,
38
- :address_attr => :street,
39
- :name => "claim[#{attribute}]"
40
- }
41
- options = default_options.merge(options)
42
- mpp = MojPostcodePicker.new(self, options)
43
- mpp.emit
44
- end
45
-
46
- # Defaults to "Yes" "No" labels on radio inputs
47
- def radio_button_fieldset attribute, legend, options={}
48
- translation_key = translation_key(attribute)
49
- raise "TBD: #{translation_key} #{options[:choice]}" if options[:choice].is_a?(Hash)
50
-
51
- virtual_pageview = options[:data] ? options[:data].delete('virtual-pageview') : nil
52
- input_class = options.delete(:input_class)
53
-
54
- set_class_and_id attribute, options
55
-
56
- options[:choice] ||= [ 'Yes', 'No' ]
57
-
58
- options_class = options[:class][/inline/] ? 'inline' : 'options'
59
-
60
- data_reverse = options.delete(:toggle_fieldset) ? ' data-reverse="true"' : ''
61
-
62
- fieldset_tag attribute, legend, options do
63
- @template.surround("<div class='#{options_class}'#{data_reverse}>".html_safe, "</div>".html_safe) do
64
- options[:choice].map do |choice|
65
- radio_button_row(attribute, choice, virtual_pageview, input_class)
66
- end.join("\n")
67
- end
68
- end
69
- end
70
-
71
- def row attribute, options={}
72
- @template.haml_tag haml_tag_text('div option', attribute, options) do
73
- yield
74
- end
75
- end
76
-
77
- def error_for? attribute
78
- # if @object.is_a?(Claim)
79
- # subkey = "claim_#{attribute}_error"
80
- # base_errors = error_message_for(:base)
81
- # base_errors && base_errors.to_h.key?(subkey) && !base_errors.to_h[subkey].empty?
82
- # else
83
- attribute_errors = error_message_for(attribute)
84
- attribute_errors && !attribute_errors.empty?
85
- # end
86
- end
87
-
88
- def error_span attribute, options={}
89
- @template.surround(error_span_open_tag(options), "</span>".html_safe) do
90
- error_span_message(attribute)
91
- end
92
- end
93
-
94
- # Creates key for lookup of translation text.
95
- # E.g. translation_key(hearing, {:choice=>"No"}) when in possession form
96
- # returns "claim.possession.hearing.no"
97
- def translation_key attribute, options={}
98
- key = "#{ parent_id.gsub('_','.') }.#{attribute}".squeeze('.')
99
- key.gsub!(/\.\d+\./, '.')
100
- if choice = options[:choice]
101
- choice = 'na' if choice == ''
102
- key += ".#{choice.downcase}"
103
- end
104
- key
105
- end
106
-
107
- def error_id_for attribute
108
- field_id = "#{parent_id}_#{attribute}".squeeze('_')
109
- "#{field_id}_error"
110
- end
111
-
112
- def parent_id
113
- @object_name.to_s.tr('[]','_').squeeze('_')
114
- end
115
-
116
- def labelled_check_box attribute, label, yes='Yes', no='No', options={}
117
- set_class_and_id attribute, options
118
- hidden_input = check_box_input_hidden attribute, options, yes, no
119
-
120
- labeled_input = label(attribute) do
121
- check_box_input(attribute, options, yes, no) + label
122
- end
123
-
124
- list = [hidden_input]
125
-
126
- if error_for?(attribute)
127
- id = error_id_for(attribute)
128
- labeled_input.sub!(%Q[id="#{id}"], %Q[id="#{id.sub('_error','')}"])
129
- list << hidden_fullstop(options)
130
- list << error_span(attribute)
131
- end
132
-
133
- list << labeled_input
134
-
135
- list.join("\n").html_safe
136
- end
137
-
138
- def set_class_and_id attribute, options
139
- options[:class] = css_for(attribute, options)
140
- options[:id] = id_for(attribute) unless id_for(attribute).blank?
141
- end
142
-
143
- def fieldset_tag(attribute, legend_text, options = {}, &block)
144
- fieldset = tag(:fieldset, options_for_fieldset(options), true)
145
-
146
- fieldset.safe_concat legend_for(attribute, legend_text, options) unless legend_text.blank?
147
-
148
- fieldset.concat(capture(&block)) if block_given?
149
- fieldset.safe_concat("</fieldset>")
150
- end
151
-
152
- private
153
-
154
- def fieldset attribute, options={}
155
- options.delete(:id) unless options[:id].present?
156
- @template.haml_tag haml_tag_text('fieldset', attribute, options) do
157
- yield
158
- end
159
- end
160
-
161
- def id_for attribute, default=nil
162
- error_for?(attribute) ? error_id_for(attribute) : (default || '')
163
- end
164
-
165
- def label_content_for attribute, label, options={}
166
- label ||= attribute.to_s.humanize
167
- label = ["#{label}"]
168
- hint = hint_span(options)
169
- label << hint if hint
170
- if error_for?(attribute)
171
- last = label.pop
172
- label << ( ends_with_punctuation?(last) ? last : (last + hidden_fullstop(options)) )
173
- label << error_span(attribute, options)
174
- end
175
- label.join(" ").html_safe
176
- end
177
-
178
- def hint_span options
179
- options[:hint] ? "<span class='hint block'>#{options[:hint]}</span>".html_safe : nil
180
- end
181
-
182
- def ends_with_punctuation? span
183
- span[/\?<\/span/] || span[/\.<\/span>/] || span[/\.|\?$/]
184
- end
185
-
186
- def legend_for attribute, legend_text, options
187
- label = label_content_for(attribute, legend_text, hint: options[:hint])
188
- content_tag(:legend, label)
189
- end
190
-
191
- def hidden_fullstop options
192
- '<span class="visuallyhidden">.</span>'.html_safe
193
- end
194
-
195
- def error_span_message attribute
196
- if @object.is_a? Claim
197
- error_message_for(:base).to_h["claim_#{attribute}_error"]
198
- else
199
- error_message_for(attribute)[0]
200
- end
201
- end
202
-
203
- def error_span_open_tag options
204
- " <span class='error#{error_classes(options)}'#{error_span_id(options)}>".html_safe
205
- end
206
-
207
- def error_span_id options
208
- options.has_key?(:id)? " id='#{options[:id]}'" : nil
209
- end
210
-
211
- def error_classes options
212
- ' visuallyhidden' if options[:hidden]
213
- end
214
-
215
- def options_for_fieldset options
216
- options.delete(:class) if options[:class].blank?
217
- options = {}.merge(options)
218
- options.delete(:hint)
219
- options.delete(:choice)
220
- options.delete(:date_select_options)
221
- options
222
- end
223
-
224
- def error_message_for symbol
225
- @object.errors.messages[symbol]
226
- end
227
-
228
- def check_box_input attribute, options, yes, no
229
- html = check_box(attribute, options, yes, no)
230
- html.gsub!(/<[^<]*type="hidden"[^>]*>/,'')
231
- html.html_safe
232
- end
233
-
234
- def check_box_input_hidden attribute, options, yes, no
235
- html = check_box(attribute, options, yes, no)
236
- html.gsub!(/.*(<[^<]*type="hidden"[^>]*>).*/, '\1')
237
- html.html_safe
238
- end
239
-
240
- def radio_button_row attribute, choice, virtual_pageview, input_class
241
- translation_key = translation_key(attribute, choice: choice)
242
-
243
- translation = I18n.t(translation_key)
244
- raise "translation missing: #{translation_key}" if translation[/translation missing/]
245
- label = translation unless translation[/translation missing/]
246
-
247
- options = {}
248
- options.merge!(class: input_class) if input_class
249
- options.merge!(data: { 'virtual_pageview' => virtual_pageview }) if virtual_pageview
250
-
251
- input = radio_button(attribute, choice, options)
252
-
253
- id = input[/id="([^"]+)"/,1]
254
-
255
- @template.surround("<div class='option'>".html_safe, "</div>".html_safe) do
256
- @template.surround("<label for='#{id}'>".html_safe, "</label>".html_safe) do
257
- # errors = error_span(attribute, {hidden: true}) if error_for?(attribute)
258
- [
259
- # errors,
260
- input,
261
- label
262
- ].compact.join("\n")
263
- end
264
- end
265
- end
266
-
267
- def css_for attribute, options
268
- css = ''
269
- css += " #{options[:class]}" if options[:class].present?
270
- css += ' error' if error_for?(attribute)
271
- css.strip
272
- end
273
-
274
- def haml_tag_text tag, attribute, options
275
- tag += " #{css_for(attribute, options)}"
276
- haml_tag_text = tag.squeeze(' ').strip.gsub(' ','.')
277
- end
278
-
279
- def row_input attribute, input_type, options
280
- virtual_pageview = options[:data] ? options[:data].delete('virtual-pageview') : nil
281
- css = "form-group #{css_for(attribute, options)}".strip
282
- id = id_for(attribute).blank? ? '' : "id='#{id_for(attribute)}' "
283
-
284
- @template.surround("<div #{id}class='#{css}'>".html_safe, "</div>".html_safe) do
285
- input_options = options.merge(class: "form-control #{options[:input_class]}".strip)
286
- input_options.merge!(data: {'virtual_pageview' => virtual_pageview}) if virtual_pageview
287
- input_options.delete(:label)
288
- input_options.delete(:input_class)
289
-
290
- labelled_input attribute, input_type, input_options, options[:label]
291
- end
292
- end
293
-
294
- def labelled_input attribute, input_type, input_options, label=nil
295
- label = label(attribute, label_content_for(attribute, label), class: 'form-label')
296
-
297
- if max_length = max_length(attribute)
298
- input_options.merge!(maxlength: max_length)
299
- end
300
-
301
- value = send(input_type, attribute, input_options)
302
-
303
- [ label, value ].join("\n").html_safe
304
- end
305
-
306
- def max_length attribute
307
- if validator = validators(attribute).detect{|x| x.is_a?(ActiveModel::Validations::LengthValidator)}
308
- validator.options[:maximum]
309
- end
310
- end
311
-
312
- def validators attribute
313
- @object.class.validators_on(attribute)
314
- end
315
-
316
- end