express_templates 0.11.8 → 0.11.9

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: 4832cfc78c6baa394a408ea32aa18c66b4cb7ed7
4
- data.tar.gz: 912d50b9d688c7a24a57f719abf36d33d63eb286
3
+ metadata.gz: b662a57e856dd89321c96091431adb2331ce4c0d
4
+ data.tar.gz: 5f3847dda42dec6989c7e85e86d6afd6f64100f1
5
5
  SHA512:
6
- metadata.gz: cd44543aab5ff5b20c9dabd5543e50f683c567e7b756fa5884dde1f40980329d1ccd3ccf70dc70132f2371708d91a30c47ec2df139624be471177c03f6bf9f32
7
- data.tar.gz: 7d836dd3ce6851b16efc2f300a38686cf42963d01532b78b3fa118f4353d2e84972283c2bd00ebc31f088cd0a632aae07f7fc4d3d7791814019ef74e72edeb8f
6
+ metadata.gz: 5461e2ef314e4a4bf8e3d4a291fce3f261ac539baac42ae20b8b36b093355ddb4f4effe60ab61c9d8c5dae9ebb1477c5eed0d401e416612fb9a32bdbdedb30c3
7
+ data.tar.gz: 23fbaaf48a9ed88fd36d53311a8fd46d0c510110b220fd9d21b39f6df717dc95cea5088029146b50ab01420f6a40d508b6319ca6c3e5cbbda22e5546142dcb9f
@@ -6,6 +6,11 @@ module ExpressTemplates
6
6
 
7
7
  has_option :options, 'Supplies a list of options for the radio tag'
8
8
  has_option :label_wrapper_class, 'Specify a class for labels which wrap each radio option.'
9
+ has_option(
10
+ :label_after,
11
+ "Specify (true of false) if the label should appear after the input (they will be siblings)",
12
+ default: false
13
+ )
9
14
 
10
15
  contains -> {
11
16
  label_tag(label_name, label_text)
@@ -35,23 +40,36 @@ module ExpressTemplates
35
40
  end
36
41
 
37
42
  def generate_options_from_specified_values
38
- case
39
- when option_collection.kind_of?(Array)
40
- option_collection.each_with_index do |option, index|
41
- label(class: config[:label_wrapper_class]) {
42
- radio_button(resource_name, field_name.to_sym, option, class: 'radio')
43
- current_arbre_element.add_child option
44
- }
43
+ if !option_collection.kind_of?(Array) &&
44
+ !option_collection.kind_of?(Hash)
45
+ raise ArgumentError, "Radio collection should be Array or Hash: #{option_collection.inspect}"
46
+ end
47
+
48
+ option_collection_hash = option_collection
49
+ if option_collection.kind_of?(Array)
50
+ option_collection_hash = option_collection.inject({}) do |hash, val|
51
+ hash[val] = val
52
+ hash
45
53
  end
46
- when option_collection.kind_of?(Hash)
47
- option_collection.each_pair do |key, value|
54
+ end
55
+
56
+ option_collection_hash.each_pair do |key, value|
57
+ if label_after?
58
+ div(class: "radio-input-container") {
59
+ radio_button(resource_name, field_name.to_sym, key, class: 'radio')
60
+ label({
61
+ class: config[:label_wrapper_class],
62
+ for: "#{resource_name}_#{field_name}_#{key}",
63
+ }) {
64
+ current_arbre_element.add_child value
65
+ }
66
+ }
67
+ else
48
68
  label(class: config[:label_wrapper_class]) {
49
69
  radio_button(resource_name, field_name.to_sym, key, class: 'radio')
50
70
  current_arbre_element.add_child value
51
71
  }
52
72
  end
53
- else
54
- raise "Radio collection should be Array or Hash: #{option_collection.inspect}"
55
73
  end
56
74
  end
57
75
 
@@ -59,6 +77,12 @@ module ExpressTemplates
59
77
  related_collection or raise "No association collection for: #{resource_name}.#{field_name}"
60
78
  end
61
79
 
80
+ protected
81
+
82
+ def label_after?
83
+ !!config[:label_after]
84
+ end
85
+
62
86
  end
63
87
  end
64
88
  end
@@ -1,3 +1,3 @@
1
1
  module ExpressTemplates
2
- VERSION = "0.11.8"
2
+ VERSION = "0.11.9"
3
3
  end
@@ -100,6 +100,44 @@ class RadioTest < ActiveSupport::TestCase
100
100
  radio_with_options_omitted
101
101
  end
102
102
 
103
+ test "label_after is true, options specified is an array - label appears after the input" do
104
+ html = arbre {
105
+ express_form(:person) {
106
+ radio :subscribed, options: ['Yes', 'No'], label_after: true
107
+ }
108
+ }
109
+
110
+ document = Nokogiri::HTML.parse(html)
111
+ radio_input_containers = document.css(".radio-input-container")
112
+
113
+ container_1 = radio_input_containers[0]
114
+ assert_equal "input", container_1.element_children[0].name
115
+ assert_equal "label", container_1.element_children[1].name
116
+
117
+ container_2 = radio_input_containers[1]
118
+ assert_equal "input", container_2.element_children[0].name
119
+ assert_equal "label", container_2.element_children[1].name
120
+ end
121
+
122
+ test "label_after is true, options specified is a hash - label appears after the input" do
123
+ html = arbre {
124
+ express_form(:person) {
125
+ radio :subscribed, options: {0 => 'Yes', 1 => 'No'}, label_after: true
126
+ }
127
+ }
128
+
129
+ document = Nokogiri::HTML.parse(html)
130
+ radio_input_containers = document.css(".radio-input-container")
131
+
132
+ container_1 = radio_input_containers[0]
133
+ assert_equal "input", container_1.element_children[0].name
134
+ assert_equal "label", container_1.element_children[1].name
135
+
136
+ container_2 = radio_input_containers[1]
137
+ assert_equal "input", container_2.element_children[0].name
138
+ assert_equal "label", container_2.element_children[1].name
139
+ end
140
+
103
141
  # test "radio supports html options"
104
142
 
105
143
  # test "html_options passed correctly when collection is omitted"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: express_templates
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.8
4
+ version: 0.11.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Talcott Smith
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-11-27 00:00:00.000000000 Z
12
+ date: 2016-01-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport