govuk_elements_form_builder 0.0.4 → 0.0.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 475401203a5c26078dbc79f8f6d6c494b01728a5
4
- data.tar.gz: e61aa54296d87f99ac76edd48fb39cf9279e5ceb
3
+ metadata.gz: 843a031b73d07acdc383b877b9f8e89633643973
4
+ data.tar.gz: 536f03612b0bf4a5ca317dd2077aa9ba9faca839
5
5
  SHA512:
6
- metadata.gz: 76a3eaeb0c325a24b1071df6e1d7db2a6c9653b14910b0ef373c4b00a6c1b17ddfa7b87de92877b62ac501761cc217efa68060e13bbc6a095a6313bd04bc01d5
7
- data.tar.gz: 27f5f53f9da16ab85175ab5410ebc7d1be5e54d8b9d9919b93ec4153bcc16d55cacdb5c5c057148d63ab296613e1e0942a6470f8399d748ce48f2816e2735810
6
+ metadata.gz: abb4867e3a120e9e73a9e372fc257fe288d96e13a4818d6612be9a8753bbe676e92b74b52630abb0408374eb3d45a8e1e00d49a88905d6deb49500306fc53563
7
+ data.tar.gz: 522235932ca947ca2ef1d37220f09f1047010e4e2c9eaebb77cdc2cd4b3f00f57c432b0db06026510aaf72ed81067ca2e46c803421a545ebccf8b9d1bfd5598f
@@ -178,8 +178,9 @@ module GovukElementsErrorsHelper
178
178
  end
179
179
  end
180
180
 
181
+ # `underscore` changes '::' to '/' to convert namespaces to paths
181
182
  def self.underscore_name object
182
- object.class.name.underscore
183
+ object.class.name.underscore.tr('/'.freeze, '_'.freeze)
183
184
  end
184
185
 
185
186
  private_class_method :error_summary_div
@@ -28,11 +28,15 @@ module GovukElementsFormBuilder
28
28
  define_method(method_name) do |attribute, *args|
29
29
  content_tag :div, class: form_group_classes(attribute), id: form_group_id(attribute) do
30
30
  options = args.extract_options!
31
+
32
+ set_label_classes! options
31
33
  set_field_classes! options
32
34
 
33
- label = label(attribute, class: "form-label")
35
+ label = label(attribute, options[:label_options])
36
+
34
37
  add_hint :label, label, attribute
35
- (label + super(attribute, options.except(:label)) ).html_safe
38
+
39
+ (label + super(attribute, options.except(:label, :label_options))).html_safe
36
40
  end
37
41
  end
38
42
  end
@@ -92,6 +96,26 @@ module GovukElementsFormBuilder
92
96
  end
93
97
  end
94
98
 
99
+ 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
+
117
+ end
118
+
95
119
  def check_box_inputs attributes
96
120
  attributes.map do |attribute|
97
121
  label(attribute, class: 'block-label selection-button-checkbox') do |tag|
@@ -1,3 +1,3 @@
1
1
  module GovukElementsFormBuilder
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
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.4
4
+ version: 0.0.5
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-03-29 00:00:00.000000000 Z
12
+ date: 2017-05-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails