govuk_elements_form_builder 0.0.5 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 843a031b73d07acdc383b877b9f8e89633643973
4
- data.tar.gz: 536f03612b0bf4a5ca317dd2077aa9ba9faca839
3
+ metadata.gz: 3927b7f760b5e6e30f00313e8340dd4967d6b012
4
+ data.tar.gz: 4b8d9592192896e4b407e33efba591c919ed8827
5
5
  SHA512:
6
- metadata.gz: abb4867e3a120e9e73a9e372fc257fe288d96e13a4818d6612be9a8753bbe676e92b74b52630abb0408374eb3d45a8e1e00d49a88905d6deb49500306fc53563
7
- data.tar.gz: 522235932ca947ca2ef1d37220f09f1047010e4e2c9eaebb77cdc2cd4b3f00f57c432b0db06026510aaf72ed81067ca2e46c803421a545ebccf8b9d1bfd5598f
6
+ metadata.gz: 0a0fc0512b037756437895aeb25aca5b60e7265416b7a33c06fd54127f35f71918c1e0fb8d216d8bd522da40e188214ec05690bdce1d22405660ccea29100059
7
+ data.tar.gz: e80d7e0157a766a60febc560ec13f571f4de2e6710ca08b8056fb87e97ca9959468659c6cae382f6020b76f0b91939e911bdd56f7a26771d49f5f490d8747734
@@ -47,7 +47,7 @@ module GovukElementsFormBuilder
47
47
  id: form_group_id(attribute) do
48
48
  content_tag :fieldset, fieldset_options(attribute, options) do
49
49
  safe_join([
50
- fieldset_legend(attribute),
50
+ fieldset_legend(attribute, options),
51
51
  radio_inputs(attribute, options)
52
52
  ], "\n")
53
53
  end
@@ -60,7 +60,7 @@ module GovukElementsFormBuilder
60
60
  id: form_group_id(attributes) do
61
61
  content_tag :fieldset, fieldset_options(attributes, options) do
62
62
  safe_join([
63
- fieldset_legend(legend_key),
63
+ fieldset_legend(legend_key, options),
64
64
  check_box_inputs(attributes)
65
65
  ], "\n")
66
66
  end
@@ -84,36 +84,29 @@ module GovukElementsFormBuilder
84
84
 
85
85
  private
86
86
 
87
+ # Given an attributes hash that could include any number of arbitrary keys, this method
88
+ # ensure we merge one or more 'default' attributes into the hash, creating the keys if
89
+ # don't exist, or merging the defaults if the keys already exists.
90
+ # It supports strings or arrays as values.
91
+ #
92
+ def merge_attributes attributes, default:
93
+ hash = attributes || {}
94
+ hash.merge(default) { |_key, oldval, newval| Array(newval) + Array(oldval) }
95
+ end
96
+
87
97
  def set_field_classes! options
88
- text_field_class = "form-control"
89
- options[:class] = case options[:class]
90
- when String
91
- [text_field_class, options[:class]]
92
- when Array
93
- options[:class].unshift text_field_class
94
- else
95
- options[:class] = text_field_class
96
- end
98
+ options ||= {}
99
+ options.merge!(
100
+ merge_attributes(options, default: {class: 'form-control'})
101
+ )
97
102
  end
98
103
 
99
104
  def set_label_classes! options
100
- text_field_class = "form-label"
101
-
102
- if options.present? && options[:label_options].present?
103
- options[:label_options][:class] = case options[:label_options][:class]
104
- when String
105
- [text_field_class, options[:label_options][:class]]
106
- when Array
107
- options[:label_options][:class].unshift text_field_class
108
- else
109
- options[:label_options][:class] = text_field_class
110
- end
111
- else
112
- options ||= {}
113
- options[:label_options] ||= {}
114
- options[:label_options][:class] = text_field_class
115
- end
116
-
105
+ options ||= {}
106
+ options[:label_options] ||= {}
107
+ options[:label_options].merge!(
108
+ merge_attributes(options[:label_options], default: {class: 'form-label'})
109
+ )
117
110
  end
118
111
 
119
112
  def check_box_inputs attributes
@@ -143,12 +136,12 @@ module GovukElementsFormBuilder
143
136
  end
144
137
  end
145
138
 
146
- def fieldset_legend attribute
139
+ def fieldset_legend attribute, options
147
140
  legend = content_tag(:legend) do
148
141
  tags = [content_tag(
149
142
  :span,
150
143
  fieldset_text(attribute),
151
- class: 'form-label-bold'
144
+ merge_attributes(options[:legend_options], default: {class: 'form-label-bold'})
152
145
  )]
153
146
 
154
147
  if error_for? attribute
@@ -1,3 +1,3 @@
1
1
  module GovukElementsFormBuilder
2
- VERSION = "0.0.5"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_elements_form_builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alistair Laing
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-05-09 00:00:00.000000000 Z
12
+ date: 2018-01-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails