hanami-helpers 0.5.0 → 0.5.1

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: 8e1a90723c16139a6a3c5fdd84e0d85f732ed886
4
- data.tar.gz: 1edccf5044d1185147cf0d0e51fe863d78467e03
3
+ metadata.gz: 81f2f927f612c01d961de1653cccea4c11e2ceeb
4
+ data.tar.gz: e41a6a6995d4d04e7e11ac893843be76967c2555
5
5
  SHA512:
6
- metadata.gz: 98e536f514a1e3d152ab3f16b059592f0d8c1b7b2f83688cedf3641a397c8db506fbefd6855fc5acb9b0feeadf991501d9dc9f62e9c3e2f555837b9085f5aa6c
7
- data.tar.gz: fac6a702eb642517b6e5c31d3a1bdbf784ebccf5ed7938665ed0dfb7234205074fae945f42ce2f343ebfc2b254ddb4e90fe5032f8472308378d688e303b8aefa
6
+ metadata.gz: 3eef23b1f56601b1977a15a754a6b1d54c120cbb4591f9e47b29b75dd7678e325f7fe953e978b8cfc9d926d98a87ce2548b4bdc8633d511cafe08d1dc75a9511
7
+ data.tar.gz: 1c101a9b9f88da297a32b5ed9dd957c173bfca10746c0ab80b948dbee16e177d01bb3fb8fae8afcd5f115584b0a20afc200b3ad3ef88c6012fafc51c0cc45839
data/CHANGELOG.md CHANGED
@@ -1,6 +1,12 @@
1
1
  # Hanami::Helpers
2
2
  View helpers for Ruby web applications
3
3
 
4
+ ## v0.5.1 - 2016-12-19
5
+ ### Fixed
6
+ - [Alex Coles] Ensure `#form_for`'s `values:` to accept `Hanami::Entity` instances
7
+ - [Ksenia Zalesnaya & Marion Duprey] Ensure checkboxes to check/uncheck when a boolean is passed as value
8
+ - [Paweł Świątkowski] Ensure `#format_number` to respect given precision
9
+
4
10
  ## v0.5.0 - 2016-11-15
5
11
  ### Added
6
12
  - [Marion Duprey] Allow `select` form helper to generate a multiple select (via `multiple: true` option)
@@ -25,4 +25,6 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency 'bundler', '~> 1.6'
26
26
  spec.add_development_dependency 'rake', '~> 11'
27
27
  spec.add_development_dependency 'minitest', '~> 5.5'
28
+
29
+ spec.add_development_dependency 'dry-struct', '~> 0.1'
28
30
  end
@@ -718,7 +718,7 @@ module Hanami
718
718
  # <%=
719
719
  # # ...
720
720
  # values = Hash['Italy' => 'it', 'United States' => 'us']
721
- # select :stores, values
721
+ # select :store, values
722
722
  # %>
723
723
  #
724
724
  # # Output:
@@ -737,7 +737,7 @@ module Hanami
737
737
  # <%=
738
738
  # # ...
739
739
  # values = Hash['it' => 'Italy', 'us' => 'United States']
740
- # select :stores, values
740
+ # select :store, values
741
741
  # %>
742
742
  #
743
743
  # # Output:
@@ -750,7 +750,7 @@ module Hanami
750
750
  # <%=
751
751
  # # ...
752
752
  # values = Hash['it' => 'Italy', 'us' => 'United States']
753
- # select :stores, values, options: {prompt: 'Select a store'}
753
+ # select :store, values, options: {prompt: 'Select a store'}
754
754
  # %>
755
755
  #
756
756
  # # Output:
@@ -764,7 +764,7 @@ module Hanami
764
764
  # <%=
765
765
  # # ...
766
766
  # values = Hash['it' => 'Italy', 'us' => 'United States']
767
- # select :stores, values, options: {selected: book.store}
767
+ # select :store, values, options: {selected: book.store}
768
768
  # %>
769
769
  #
770
770
  # # Output:
@@ -1030,9 +1030,7 @@ module Hanami
1030
1030
  value: attributes.delete(:checked_value) || DEFAULT_CHECKED_VALUE
1031
1031
  }.merge(attributes)
1032
1032
 
1033
- value = _value(name)
1034
- attributes[:checked] = CHECKED if !value.nil? &&
1035
- (value == attributes[:value] || value.include?(attributes[:value]))
1033
+ attributes[:checked] = CHECKED if _check_box_checked?(attributes[:value], _value(name))
1036
1034
 
1037
1035
  attributes
1038
1036
  end
@@ -1053,6 +1051,12 @@ module Hanami
1053
1051
  end
1054
1052
  # rubocop:enable Metrics/PerceivedComplexity
1055
1053
  # rubocop:enable Metrics/CyclomaticComplexity
1054
+
1055
+ def _check_box_checked?(value, input_value)
1056
+ !input_value.nil? &&
1057
+ (input_value.to_s == value.to_s || input_value.is_a?(TrueClass) ||
1058
+ input_value.is_a?(Array) && input_value.include?(value))
1059
+ end
1056
1060
  end
1057
1061
  end
1058
1062
  end
@@ -48,8 +48,9 @@ module Hanami
48
48
  tail.each do |k|
49
49
  break if result.nil?
50
50
 
51
- result = if result.respond_to?(k) # rubocop:disable Style/IfUnlessModifier
52
- result.public_send(k)
51
+ result = case result
52
+ when Utils::Hash, ::Hash then result[k]
53
+ when ->(r) { r.respond_to?(k) } then result.public_send(k)
53
54
  end
54
55
  end
55
56
 
@@ -134,7 +134,7 @@ module Hanami
134
134
  @number = number
135
135
  @delimiter = options.fetch(:delimiter, DEFAULT_DELIMITER)
136
136
  @separator = options.fetch(:separator, DEFAULT_SEPARATOR)
137
- @precision = options.fetch(:precision, DEFAULT_PRECISION)
137
+ @precision = options.fetch(:precision, nil)
138
138
  end
139
139
 
140
140
  # Format number according to the specified options
@@ -181,7 +181,12 @@ module Hanami
181
181
  # @since 0.2.0
182
182
  # @api private
183
183
  def to_str
184
- to_number.to_s
184
+ number = to_number
185
+ if precision_requested_explicitly?
186
+ Kernel.format("%.#{precision}f", number)
187
+ else
188
+ number.to_s
189
+ end
185
190
  end
186
191
 
187
192
  # Numeric coercion
@@ -203,6 +208,26 @@ module Hanami
203
208
  end
204
209
  end
205
210
 
211
+ # Returns precision with a fallback to default value
212
+ #
213
+ # @return [Numeric] precision
214
+ #
215
+ # @since 1.0.0
216
+ # @api private
217
+ def precision
218
+ @precision || DEFAULT_PRECISION
219
+ end
220
+
221
+ # Checks if precision was requested in options
222
+ #
223
+ # @return [TrueClass,FalseClass] the result of the check
224
+ #
225
+ # @since 1.0.0
226
+ # @api private
227
+ def precision_requested_explicitly?
228
+ !@precision.nil?
229
+ end
230
+
206
231
  # Round number in case we need to return a <tt>Float</tt> representation.
207
232
  # If <tt>@number</tt> doesn't respond to <tt>#round</tt> return the number as it is.
208
233
  #
@@ -212,7 +237,7 @@ module Hanami
212
237
  # @api private
213
238
  def rounded_number
214
239
  if @number.respond_to?(:round)
215
- @number.round(@precision)
240
+ @number.round(precision)
216
241
  else
217
242
  @number
218
243
  end
@@ -3,6 +3,6 @@ module Hanami
3
3
  # Define version
4
4
  #
5
5
  # @since 0.1.0
6
- VERSION = '0.5.0'.freeze
6
+ VERSION = '0.5.1'.freeze
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hanami-helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luca Guidi
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-11-15 00:00:00.000000000 Z
13
+ date: 2016-12-19 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: hanami-utils
@@ -68,6 +68,20 @@ dependencies:
68
68
  - - "~>"
69
69
  - !ruby/object:Gem::Version
70
70
  version: '5.5'
71
+ - !ruby/object:Gem::Dependency
72
+ name: dry-struct
73
+ requirement: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - "~>"
76
+ - !ruby/object:Gem::Version
77
+ version: '0.1'
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - "~>"
83
+ - !ruby/object:Gem::Version
84
+ version: '0.1'
71
85
  description: View helpers for Ruby applications
72
86
  email:
73
87
  - me@lucaguidi.com
@@ -118,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
132
  version: '0'
119
133
  requirements: []
120
134
  rubyforge_project:
121
- rubygems_version: 2.6.4
135
+ rubygems_version: 2.6.8
122
136
  signing_key:
123
137
  specification_version: 4
124
138
  summary: Hanami helpers