hanami-helpers 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -1
- data/lib/hanami/helpers/form_helper.rb +3 -3
- data/lib/hanami/helpers/form_helper/form_builder.rb +35 -18
- data/lib/hanami/helpers/html_helper/html_builder.rb +3 -3
- data/lib/hanami/helpers/routing_helper.rb +1 -1
- data/lib/hanami/helpers/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2240795ff1bddb8305850e8473c60580701e7175528edcc25f83bad073a49fc9
|
4
|
+
data.tar.gz: 704af3c5d22e74509806c87c17bb368b0935dafe6ff276d2532bbc010c59eba2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94778d91a095e8e7e41d58c0fa9477de162960fab463f2c8eb593b03f27ba2ac3dc7041d6fdab42b7f46783838510f0532191d678c4d5cd2225b454251b0c499
|
7
|
+
data.tar.gz: 6a5c35fd9efdc2c5db4d763398e10bc51de1cf2b429e28bfcfc5b2694e2dc3a68d24d6b22658965e85e5b85202a3c1f206d920badc5bf6e70ae75335dd4d8410
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,11 @@
|
|
1
1
|
# Hanami::Helpers
|
2
2
|
View helpers for Ruby web applications
|
3
3
|
|
4
|
-
## v1.1.
|
4
|
+
## v1.1.2 - 2018-04-05
|
5
|
+
### Fixed
|
6
|
+
- [Luca Guidi] Ensure correct arity of `#form_for`, to be used in conjuction with `Hanami::Helpers::FormHelper::Form` (eg. `<%= form_for(form) { ... } %>`)
|
7
|
+
|
8
|
+
## v1.1.1 - 2018-02-27
|
5
9
|
### Fixed
|
6
10
|
- [Alfonso Uceda] Ensure `#select` form helper to not select options with `nil` value
|
7
11
|
- [Alfonso Uceda] Ensure `#fields_for_collection` form helper to produce input fields with correct `name` attribute
|
@@ -229,7 +229,7 @@ module Hanami
|
|
229
229
|
# @option options [Hash] :values An optional payload of objects to pass
|
230
230
|
# @param blk [Proc] A block that describes the contents of the form
|
231
231
|
#
|
232
|
-
# @overload form_for(form, attributes, &blk)
|
232
|
+
# @overload form_for(form, attributes = {}, &blk)
|
233
233
|
# Use Form
|
234
234
|
# @param form [Hanami::Helpers::FormHelper::Form] a form object
|
235
235
|
# @param attributes [Hash] HTML attributes to pass to the form tag and form values
|
@@ -406,9 +406,9 @@ module Hanami
|
|
406
406
|
#
|
407
407
|
# <button type="submit">Create</button>
|
408
408
|
# </form>
|
409
|
-
def form_for(name, url, options = {}, &blk)
|
409
|
+
def form_for(name, url = nil, options = {}, &blk)
|
410
410
|
form = if name.is_a?(Form)
|
411
|
-
options = url
|
411
|
+
options = url || {}
|
412
412
|
name
|
413
413
|
else
|
414
414
|
Form.new(name, url, options.delete(:values))
|
@@ -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,35 @@ 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
|
+
def _is_current_value?(input_value, value)
|
1587
|
+
return unless input_value
|
1588
|
+
value.to_s == input_value.to_s
|
1589
|
+
end
|
1590
|
+
|
1591
|
+
# @api private
|
1592
|
+
def _is_in_selected_values?(multiple, selected, value)
|
1593
|
+
return unless multiple && selected.is_a?(Array)
|
1594
|
+
selected.include?(value)
|
1595
|
+
end
|
1596
|
+
|
1597
|
+
# @api private
|
1598
|
+
def _is_in_input_values?(multiple, input_value, value)
|
1599
|
+
return unless multiple && input_value.is_a?(Array)
|
1600
|
+
input_value.include?(value)
|
1582
1601
|
end
|
1583
|
-
# rubocop:enable Metrics/PerceivedComplexity
|
1584
|
-
# rubocop:enable Metrics/CyclomaticComplexity
|
1585
1602
|
|
1586
1603
|
# @api private
|
1587
1604
|
def _check_box_checked?(value, input_value)
|
@@ -160,7 +160,7 @@ module Hanami
|
|
160
160
|
@nodes << self.class.html_node.new(:#{tag}, blk || content, attributes || content, options)
|
161
161
|
self
|
162
162
|
end
|
163
|
-
}
|
163
|
+
}, __FILE__, __LINE__ - 5
|
164
164
|
end
|
165
165
|
|
166
166
|
EMPTY_TAGS.each do |tag|
|
@@ -169,7 +169,7 @@ module Hanami
|
|
169
169
|
@nodes << EmptyHtmlNode.new(:#{tag}, attributes)
|
170
170
|
self
|
171
171
|
end
|
172
|
-
}
|
172
|
+
}, __FILE__, __LINE__ - 5
|
173
173
|
end
|
174
174
|
|
175
175
|
include Utils::ClassAttribute
|
@@ -369,7 +369,7 @@ module Hanami
|
|
369
369
|
# @since 0.1.0
|
370
370
|
# @api private
|
371
371
|
def resolve(&blk)
|
372
|
-
@context = eval
|
372
|
+
@context = eval('self', blk.binding, __FILE__, __LINE__)
|
373
373
|
instance_exec(&blk)
|
374
374
|
end
|
375
375
|
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.1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luca Guidi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-04-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hanami-utils
|
@@ -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.7.
|
131
|
+
rubygems_version: 2.7.5
|
132
132
|
signing_key:
|
133
133
|
specification_version: 4
|
134
134
|
summary: Hanami helpers
|