hanami-helpers 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +6 -0
- data/hanami-helpers.gemspec +1 -1
- data/lib/hanami/helpers/form_helper/form_builder.rb +51 -21
- data/lib/hanami/helpers/version.rb +1 -1
- metadata +12 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1505baa1639a4a9bfbf8a7ea317e2385ade8783fe446f526162f26152d0c1c84
|
4
|
+
data.tar.gz: 0071b68be742ee837514e1457fad8503a78cacde1d3d61ea45f8b611a7df9160
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c80db19544ca884289e9086132b611b2ebc7924b5f0de03ed0bf6bd39d2205d0ccfd1f3999735068255d4a61dc1824b5c6d72e3c38cf5d23528abad6b042ea87
|
7
|
+
data.tar.gz: 7e2cf205cae822a23199bfae9787426e55a66ff8118f14cd1235ba0ff4cfd63190eb2f883e651599dbdda39fae9dc589985da7181212996f82004737bb1b8d7e
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
# Hanami::Helpers
|
2
2
|
View helpers for Ruby web applications
|
3
3
|
|
4
|
+
## v1.1.1 - 2017-11-28
|
5
|
+
### Fixed
|
6
|
+
- [Alfonso Uceda] Ensure `#select` form helper to not select options with `nil` value
|
7
|
+
- [Alfonso Uceda] Ensure `#fields_for_collection` form helper to produce input fields with correct `name` attribute
|
8
|
+
- [Luca Guidi] Ensure `#select` form helper to respect `:selected` option
|
9
|
+
|
4
10
|
## v1.1.0 - 2017-10-25
|
5
11
|
|
6
12
|
## v1.1.0.rc1 - 2017-10-16
|
data/hanami-helpers.gemspec
CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_dependency 'hanami-utils', '~> 1.1'
|
24
24
|
|
25
25
|
spec.add_development_dependency 'bundler', '~> 1.6'
|
26
|
+
spec.add_development_dependency 'dry-struct', '~> 0.3'
|
26
27
|
spec.add_development_dependency 'rake', '~> 12'
|
27
28
|
spec.add_development_dependency 'rspec', '~> 3.7'
|
28
|
-
spec.add_development_dependency 'dry-struct', '~> 0.3'
|
29
29
|
end
|
@@ -814,7 +814,7 @@ module Hanami
|
|
814
814
|
# <input type="file" name="user[resume]" id="user-resume" multiple="multiple">
|
815
815
|
def file_field(name, attributes = {})
|
816
816
|
attributes[:accept] = Array(attributes[:accept]).join(ACCEPT_SEPARATOR) if attributes.key?(:accept)
|
817
|
-
attributes = { type: :file, name:
|
817
|
+
attributes = { type: :file, name: _displayed_input_name(name), id: _input_id(name) }.merge(attributes)
|
818
818
|
|
819
819
|
input(attributes)
|
820
820
|
end
|
@@ -937,7 +937,7 @@ module Hanami
|
|
937
937
|
content = nil
|
938
938
|
end
|
939
939
|
|
940
|
-
attributes = { name:
|
940
|
+
attributes = { name: _displayed_input_name(name), id: _input_id(name) }.merge(attributes)
|
941
941
|
textarea(content || _value(name), attributes)
|
942
942
|
end
|
943
943
|
|
@@ -1049,7 +1049,7 @@ module Hanami
|
|
1049
1049
|
# <input type="radio" name="book[category]" value="Fiction">
|
1050
1050
|
# <input type="radio" name="book[category]" value="Non-Fiction" checked="checked">
|
1051
1051
|
def radio_button(name, value, attributes = {})
|
1052
|
-
attributes = { type: :radio, name:
|
1052
|
+
attributes = { type: :radio, name: _displayed_input_name(name), value: value }.merge(attributes)
|
1053
1053
|
attributes[:checked] = CHECKED if _value(name).to_s == value.to_s
|
1054
1054
|
input(attributes)
|
1055
1055
|
end
|
@@ -1070,16 +1070,19 @@ module Hanami
|
|
1070
1070
|
# <!-- output -->
|
1071
1071
|
# <input type="password" name="signup[password]" id="signup-password" value="">
|
1072
1072
|
def password_field(name, attributes = {})
|
1073
|
-
input({ type: :password, name:
|
1073
|
+
input({ type: :password, name: _displayed_input_name(name), id: _input_id(name), value: nil }.merge(attributes))
|
1074
1074
|
end
|
1075
1075
|
|
1076
1076
|
# Select input
|
1077
1077
|
#
|
1078
1078
|
# @param name [Symbol] the input name
|
1079
1079
|
# @param values [Hash] a Hash to generate <tt><option></tt> tags.
|
1080
|
-
# Values correspond to <tt>value</tt> and keys correspond to the content.
|
1081
1080
|
# @param attributes [Hash] HTML attributes to pass to the input tag
|
1082
1081
|
#
|
1082
|
+
# Values is used to generate the list of <tt><option></tt> tags, it is an
|
1083
|
+
# <tt>Enumerable</tt> of pairs of content (the displayed text) and value (the tag's
|
1084
|
+
# attribute), in that respective order (please refer to the examples for more clarity).
|
1085
|
+
#
|
1083
1086
|
# If request params have a value that corresponds to one of the given values,
|
1084
1087
|
# it automatically sets the <tt>selected</tt> attribute on the <tt><option></tt> tag.
|
1085
1088
|
# This Hanami::Controller integration happens without any developer intervention.
|
@@ -1090,11 +1093,11 @@ module Hanami
|
|
1090
1093
|
# <%=
|
1091
1094
|
# # ...
|
1092
1095
|
# values = Hash['Italy' => 'it', 'United States' => 'us']
|
1093
|
-
# select :store, values
|
1096
|
+
# select :store, values
|
1094
1097
|
# %>
|
1095
1098
|
#
|
1096
1099
|
# <!-- output -->
|
1097
|
-
# <select name="book[store]" id="book-store"
|
1100
|
+
# <select name="book[store]" id="book-store">
|
1098
1101
|
# <option value="it">Italy</option>
|
1099
1102
|
# <option value="us">United States</option>
|
1100
1103
|
# </select>
|
@@ -1103,11 +1106,11 @@ module Hanami
|
|
1103
1106
|
# <%=
|
1104
1107
|
# # ...
|
1105
1108
|
# values = Hash['Italy' => 'it', 'United States' => 'us']
|
1106
|
-
# select :store, values
|
1109
|
+
# select :store, values, class: "form-control"
|
1107
1110
|
# %>
|
1108
1111
|
#
|
1109
1112
|
# <!-- output -->
|
1110
|
-
# <select name="book[store]" id="book-store">
|
1113
|
+
# <select name="book[store]" id="book-store" class="form-control">
|
1111
1114
|
# <option value="it">Italy</option>
|
1112
1115
|
# <option value="us">United States</option>
|
1113
1116
|
# </select>
|
@@ -1121,7 +1124,7 @@ module Hanami
|
|
1121
1124
|
#
|
1122
1125
|
# <%=
|
1123
1126
|
# # ...
|
1124
|
-
# values = Hash['
|
1127
|
+
# values = Hash['Italy' => 'it', 'United States' => 'us']
|
1125
1128
|
# select :store, values
|
1126
1129
|
# %>
|
1127
1130
|
#
|
@@ -1134,7 +1137,7 @@ module Hanami
|
|
1134
1137
|
# @example Prompt option
|
1135
1138
|
# <%=
|
1136
1139
|
# # ...
|
1137
|
-
# values = Hash['
|
1140
|
+
# values = Hash['Italy' => 'it', 'United States' => 'us']
|
1138
1141
|
# select :store, values, options: { prompt: 'Select a store' }
|
1139
1142
|
# %>
|
1140
1143
|
#
|
@@ -1148,7 +1151,7 @@ module Hanami
|
|
1148
1151
|
# @example Selected option
|
1149
1152
|
# <%=
|
1150
1153
|
# # ...
|
1151
|
-
# values = Hash['
|
1154
|
+
# values = Hash['Italy' => 'it', 'United States' => 'us']
|
1152
1155
|
# select :store, values, options: { selected: book.store }
|
1153
1156
|
# %>
|
1154
1157
|
#
|
@@ -1161,7 +1164,7 @@ module Hanami
|
|
1161
1164
|
# @example Prompt option and HTML attributes
|
1162
1165
|
# <%=
|
1163
1166
|
# # ...
|
1164
|
-
# values = Hash['
|
1167
|
+
# values = Hash['Italy' => 'it', 'United States' => 'us']
|
1165
1168
|
# select :store, values, options: { prompt: 'Select a store' }, class: "form-control"
|
1166
1169
|
# %>
|
1167
1170
|
#
|
@@ -1175,7 +1178,7 @@ module Hanami
|
|
1175
1178
|
# @example Multiple select
|
1176
1179
|
# <%=
|
1177
1180
|
# # ...
|
1178
|
-
# values = Hash['
|
1181
|
+
# values = Hash['Italy' => 'it', 'United States' => 'us']
|
1179
1182
|
# select :stores, values, multiple: true
|
1180
1183
|
# %>
|
1181
1184
|
#
|
@@ -1188,7 +1191,7 @@ module Hanami
|
|
1188
1191
|
# @example Multiple select and HTML attributes
|
1189
1192
|
# <%=
|
1190
1193
|
# # ...
|
1191
|
-
# values = Hash['
|
1194
|
+
# values = Hash['Italy' => 'it', 'United States' => 'us']
|
1192
1195
|
# select :stores, values, multiple: true, class: "form-control"
|
1193
1196
|
# %>
|
1194
1197
|
#
|
@@ -1197,6 +1200,30 @@ module Hanami
|
|
1197
1200
|
# <option value="it">Italy</option>
|
1198
1201
|
# <option value="us">United States</option>
|
1199
1202
|
# </select>
|
1203
|
+
#
|
1204
|
+
# @example Array with repeated entries
|
1205
|
+
# <%=
|
1206
|
+
# # ...
|
1207
|
+
# values = [['Italy', 'it'],
|
1208
|
+
# ['---', ''],
|
1209
|
+
# ['Afghanistan', 'af'],
|
1210
|
+
# ...
|
1211
|
+
# ['Italy', 'it'],
|
1212
|
+
# ...
|
1213
|
+
# ['Zimbabwe', 'zw']]
|
1214
|
+
# select :stores, values
|
1215
|
+
# %>
|
1216
|
+
#
|
1217
|
+
# <!-- output -->
|
1218
|
+
# <select name="book[store]" id="book-store">
|
1219
|
+
# <option value="it">Italy</option>
|
1220
|
+
# <option value="">---</option>
|
1221
|
+
# <option value="af">Afghanistan</option>
|
1222
|
+
# ...
|
1223
|
+
# <option value="it">Italy</option>
|
1224
|
+
# ...
|
1225
|
+
# <option value="zw">Zimbabwe</option>
|
1226
|
+
# </select>
|
1200
1227
|
def select(name, values, attributes = {}) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
1201
1228
|
options = attributes.delete(:options) { {} }
|
1202
1229
|
attributes = { name: _select_input_name(name, attributes[:multiple]), id: _input_id(name) }.merge(attributes)
|
@@ -1206,8 +1233,9 @@ module Hanami
|
|
1206
1233
|
super(attributes) do
|
1207
1234
|
option(prompt) unless prompt.nil?
|
1208
1235
|
|
1236
|
+
already_selected = nil
|
1209
1237
|
values.each do |content, value|
|
1210
|
-
if _select_option_selected?(value, selected, _value(name), attributes[:multiple])
|
1238
|
+
if (attributes[:multiple] || !already_selected) && (already_selected = _select_option_selected?(value, selected, _value(name), attributes[:multiple]))
|
1211
1239
|
option(content, { value: value, selected: SELECTED }.merge(options))
|
1212
1240
|
else
|
1213
1241
|
option(content, { value: value }.merge(options))
|
@@ -1509,7 +1537,7 @@ module Hanami
|
|
1509
1537
|
|
1510
1538
|
input(
|
1511
1539
|
type: :hidden,
|
1512
|
-
name: attributes[:name] ||
|
1540
|
+
name: attributes[:name] || _displayed_input_name(name),
|
1513
1541
|
value: attributes.delete(:unchecked_value) || DEFAULT_UNCHECKED_VALUE
|
1514
1542
|
)
|
1515
1543
|
end
|
@@ -1523,7 +1551,7 @@ module Hanami
|
|
1523
1551
|
def _attributes_for_check_box(name, attributes)
|
1524
1552
|
attributes = {
|
1525
1553
|
type: :checkbox,
|
1526
|
-
name:
|
1554
|
+
name: _displayed_input_name(name),
|
1527
1555
|
id: _input_id(name),
|
1528
1556
|
value: attributes.delete(:checked_value) || DEFAULT_CHECKED_VALUE
|
1529
1557
|
}.merge(attributes)
|
@@ -1535,7 +1563,7 @@ module Hanami
|
|
1535
1563
|
|
1536
1564
|
# @api private
|
1537
1565
|
def _select_input_name(name, multiple)
|
1538
|
-
select_name =
|
1566
|
+
select_name = _displayed_input_name(name)
|
1539
1567
|
select_name = "#{select_name}[]" if multiple
|
1540
1568
|
select_name
|
1541
1569
|
end
|
@@ -1547,8 +1575,10 @@ module Hanami
|
|
1547
1575
|
# rubocop:disable Metrics/CyclomaticComplexity
|
1548
1576
|
# rubocop:disable Metrics/PerceivedComplexity
|
1549
1577
|
def _select_option_selected?(value, selected, input_value, multiple)
|
1550
|
-
value == selected ||
|
1551
|
-
|
1578
|
+
value == selected ||
|
1579
|
+
(multiple && (selected.is_a?(Array) && selected.include?(value))) ||
|
1580
|
+
(!input_value.nil? && (value.to_s == input_value.to_s)) ||
|
1581
|
+
(multiple && (input_value.is_a?(Array) && input_value.include?(value)))
|
1552
1582
|
end
|
1553
1583
|
# rubocop:enable Metrics/PerceivedComplexity
|
1554
1584
|
# rubocop:enable Metrics/CyclomaticComplexity
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hanami-helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luca Guidi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-11-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hanami-utils
|
@@ -39,47 +39,47 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.6'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: dry-struct
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '0.3'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '0.3'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '12'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '12'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '3.7'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '3.7'
|
83
83
|
description: View helpers for Ruby applications
|
84
84
|
email:
|
85
85
|
- me@lucaguidi.com
|
@@ -128,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
128
128
|
version: '0'
|
129
129
|
requirements: []
|
130
130
|
rubyforge_project:
|
131
|
-
rubygems_version: 2.
|
131
|
+
rubygems_version: 2.7.1
|
132
132
|
signing_key:
|
133
133
|
specification_version: 4
|
134
134
|
summary: Hanami helpers
|