hanami-helpers 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/hanami-helpers.gemspec +2 -0
- data/lib/hanami/helpers/form_helper/form_builder.rb +11 -7
- data/lib/hanami/helpers/form_helper/values.rb +3 -2
- data/lib/hanami/helpers/number_formatting_helper.rb +28 -3
- data/lib/hanami/helpers/version.rb +1 -1
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81f2f927f612c01d961de1653cccea4c11e2ceeb
|
4
|
+
data.tar.gz: e41a6a6995d4d04e7e11ac893843be76967c2555
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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)
|
data/hanami-helpers.gemspec
CHANGED
@@ -718,7 +718,7 @@ module Hanami
|
|
718
718
|
# <%=
|
719
719
|
# # ...
|
720
720
|
# values = Hash['Italy' => 'it', 'United States' => 'us']
|
721
|
-
# select :
|
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 :
|
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 :
|
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 :
|
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
|
-
|
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 =
|
52
|
-
|
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,
|
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
|
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(
|
240
|
+
@number.round(precision)
|
216
241
|
else
|
217
242
|
@number
|
218
243
|
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.
|
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-
|
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.
|
135
|
+
rubygems_version: 2.6.8
|
122
136
|
signing_key:
|
123
137
|
specification_version: 4
|
124
138
|
summary: Hanami helpers
|