hanami-helpers 1.2.0.beta2 → 1.2.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/hanami-helpers.gemspec +1 -1
- data/lib/hanami/helpers/form_helper/form_builder.rb +38 -18
- data/lib/hanami/helpers/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d9a38e49189c590ded98fadc810ff68f04582332eca3dda5476a4ffc15b54ced
|
4
|
+
data.tar.gz: 6913af558d44a221a2a114eef67edd07d202554fe1943cda1000cec0342aa140
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f197533772d142548b5fcf451742689389450f59fcf09578f5a360144560c686c5d41fd7bf26621a5a119f179806c24c03dfcbe104a5fb79883e7819dc5e1b7
|
7
|
+
data.tar.gz: 176d3b231eabc901adaf1747d35d957429bb1d93f606f58460e1a83871fa7dad5d51bb48258322b8c80067ff43f61ebee59aa02e274b6005f373616252a1de6d
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
# Hanami::Helpers
|
2
2
|
View helpers for Ruby web applications
|
3
3
|
|
4
|
+
## v1.2.0.rc1 - 2018-03-30
|
5
|
+
### Fixed
|
6
|
+
- [Gustavo Caso] Ensure `select` helper to set the `selected` attribute properly when an `<option>` has a `nil` value
|
7
|
+
|
4
8
|
## v1.2.0.beta2 - 2018-03-23
|
5
9
|
|
6
10
|
## v1.2.0.beta1 - 2018-02-28
|
data/hanami-helpers.gemspec
CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.require_paths = ['lib']
|
21
21
|
spec.required_ruby_version = '>= 2.3.0'
|
22
22
|
|
23
|
-
spec.add_dependency 'hanami-utils', '1.2.0.
|
23
|
+
spec.add_dependency 'hanami-utils', '1.2.0.rc1'
|
24
24
|
|
25
25
|
spec.add_development_dependency 'bundler', '~> 1.6'
|
26
26
|
spec.add_development_dependency 'dry-struct', '~> 0.3'
|
@@ -81,11 +81,11 @@ module Hanami
|
|
81
81
|
|
82
82
|
# Instantiate a form builder
|
83
83
|
#
|
84
|
-
# @overload initialize(form, attributes,
|
84
|
+
# @overload initialize(form, attributes, context, &blk)
|
85
85
|
# Top level form
|
86
86
|
# @param form [Hanami::Helpers:FormHelper::Form] the form
|
87
87
|
# @param attributes [::Hash] a set of HTML attributes
|
88
|
-
# @param
|
88
|
+
# @param context [Hanami::Helpers::FormHelper]
|
89
89
|
# @param blk [Proc] a block that describes the contents of the form
|
90
90
|
#
|
91
91
|
# @overload initialize(form, attributes, params, &blk)
|
@@ -1225,17 +1225,19 @@ module Hanami
|
|
1225
1225
|
# <option value="zw">Zimbabwe</option>
|
1226
1226
|
# </select>
|
1227
1227
|
def select(name, values, attributes = {}) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
1228
|
-
options
|
1229
|
-
|
1230
|
-
|
1231
|
-
|
1228
|
+
options = attributes.delete(:options) { {} }
|
1229
|
+
multiple = attributes[:multiple]
|
1230
|
+
attributes = { name: _select_input_name(name, multiple), id: _input_id(name) }.merge(attributes)
|
1231
|
+
prompt = options.delete(:prompt)
|
1232
|
+
selected = options.delete(:selected)
|
1233
|
+
input_value = _value(name)
|
1232
1234
|
|
1233
1235
|
super(attributes) do
|
1234
1236
|
option(prompt) unless prompt.nil?
|
1235
1237
|
|
1236
1238
|
already_selected = nil
|
1237
1239
|
values.each do |content, value|
|
1238
|
-
if (
|
1240
|
+
if (multiple || !already_selected) && (already_selected = _select_option_selected?(value, selected, input_value, multiple))
|
1239
1241
|
option(content, { value: value, selected: SELECTED }.merge(options))
|
1240
1242
|
else
|
1241
1243
|
option(content, { value: value }.merge(options))
|
@@ -1568,20 +1570,38 @@ module Hanami
|
|
1568
1570
|
select_name
|
1569
1571
|
end
|
1570
1572
|
|
1571
|
-
# TODO: this has to be refactored
|
1572
|
-
#
|
1573
1573
|
# @api private
|
1574
|
-
#
|
1575
|
-
# rubocop:disable Metrics/CyclomaticComplexity
|
1576
|
-
# rubocop:disable Metrics/PerceivedComplexity
|
1577
1574
|
def _select_option_selected?(value, selected, input_value, multiple)
|
1578
|
-
|
1579
|
-
|
1580
|
-
|
1581
|
-
(
|
1575
|
+
if input_value && selected.nil?
|
1576
|
+
value.to_s == input_value
|
1577
|
+
else
|
1578
|
+
(value == selected) ||
|
1579
|
+
_is_in_selected_values?(multiple, selected, value) ||
|
1580
|
+
_is_current_value?(input_value, value) ||
|
1581
|
+
_is_in_input_values?(multiple, input_value, value)
|
1582
|
+
end
|
1583
|
+
end
|
1584
|
+
|
1585
|
+
# @api private
|
1586
|
+
# @since 1.2.0
|
1587
|
+
def _is_current_value?(input_value, value)
|
1588
|
+
return unless input_value
|
1589
|
+
value.to_s == input_value.to_s
|
1590
|
+
end
|
1591
|
+
|
1592
|
+
# @api private
|
1593
|
+
# @since 1.2.0
|
1594
|
+
def _is_in_selected_values?(multiple, selected, value)
|
1595
|
+
return unless multiple && selected.is_a?(Array)
|
1596
|
+
selected.include?(value)
|
1597
|
+
end
|
1598
|
+
|
1599
|
+
# @api private
|
1600
|
+
# @since 1.2.0
|
1601
|
+
def _is_in_input_values?(multiple, input_value, value)
|
1602
|
+
return unless multiple && input_value.is_a?(Array)
|
1603
|
+
input_value.include?(value)
|
1582
1604
|
end
|
1583
|
-
# rubocop:enable Metrics/PerceivedComplexity
|
1584
|
-
# rubocop:enable Metrics/CyclomaticComplexity
|
1585
1605
|
|
1586
1606
|
# @api private
|
1587
1607
|
def _check_box_checked?(value, input_value)
|
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.2.0.
|
4
|
+
version: 1.2.0.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luca Guidi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-03-
|
11
|
+
date: 2018-03-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hanami-utils
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.2.0.
|
19
|
+
version: 1.2.0.rc1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.2.0.
|
26
|
+
version: 1.2.0.rc1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|