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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 53cb4229bd148d979834de168de38a63c4ddc2cd7fc258de09ab6d53f5495344
4
- data.tar.gz: 2005f05d5c8111c2bc185b243a7510953fd026f058dc24fa07cc2fba07c36c3c
3
+ metadata.gz: d9a38e49189c590ded98fadc810ff68f04582332eca3dda5476a4ffc15b54ced
4
+ data.tar.gz: 6913af558d44a221a2a114eef67edd07d202554fe1943cda1000cec0342aa140
5
5
  SHA512:
6
- metadata.gz: 25797f84379affb3aa16c9c12a74c512adbb83a92d060f46b9449f1a6ead13dd82585c172cd17adc828d00bf7315d74ed716232cb0825abdde5bba5101605b22
7
- data.tar.gz: aad028c977b6849651277ad180ed8dd1396616fe2f8820e60e739d617f4110bfa232a5c80b63902caa53a7796d88e75461d6d54b45d04645af1b55e768f666f5
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
@@ -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.beta2'
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, params, &blk)
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 params [Hanami::Action::Params] request params
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 = attributes.delete(:options) { {} }
1229
- attributes = { name: _select_input_name(name, attributes[:multiple]), id: _input_id(name) }.merge(attributes)
1230
- prompt = options.delete(:prompt)
1231
- selected = options.delete(:selected)
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 (attributes[:multiple] || !already_selected) && (already_selected = _select_option_selected?(value, selected, _value(name), attributes[:multiple]))
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
- 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)))
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)
@@ -3,6 +3,6 @@ module Hanami
3
3
  # Define version
4
4
  #
5
5
  # @since 0.1.0
6
- VERSION = '1.2.0.beta2'.freeze
6
+ VERSION = '1.2.0.rc1'.freeze
7
7
  end
8
8
  end
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.beta2
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-23 00:00:00.000000000 Z
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.beta2
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.beta2
26
+ version: 1.2.0.rc1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement