hanami-helpers 1.3.1 → 1.3.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 +8 -0
- data/hanami-helpers.gemspec +1 -1
- data/lib/hanami/helpers/form_helper.rb +22 -2
- data/lib/hanami/helpers/form_helper/form_builder.rb +24 -8
- data/lib/hanami/helpers/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 164baa1c2d4f10946f6a48b10d507fc4d98f13d08abbdd3004e6c4ffdbc0a8cb
|
4
|
+
data.tar.gz: 2fdac7777fc6dd841b22d23acb681bcafac842ea2b0cdbf76fdf972fbb6aa61d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 27641b03250b80e892697d503323613704f6b03bfd97519e871286e22434b264a71881d5a62fda5ba484da9561588588bb5c0cc57981433b61dd149fbe2955fd
|
7
|
+
data.tar.gz: e062653bf269742f7a5b77d6b0bf72457e8f73f067104845aea23bbfba371bd9b4b04b3c59536bc6d26482f2ad5a301a78856b283c2c938ffd2f4c4e442dd0b0
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
# Hanami::Helpers
|
2
2
|
View helpers for Ruby web applications
|
3
3
|
|
4
|
+
## v1.3.2 - 2019-10-31
|
5
|
+
### Added
|
6
|
+
- [Nenad] Support block syntax for `label` helper
|
7
|
+
- [Luca Guidi] Allow `form_for` to accept `params:` argument to override params coming from the view
|
8
|
+
|
9
|
+
### Fixed
|
10
|
+
- [Danny Santos] When `prompt:` option is used in `select` helper, set to `disabled="disabled"` the related `<option>` HTML tag
|
11
|
+
|
4
12
|
## v1.3.1 - 2019-01-18
|
5
13
|
### Added
|
6
14
|
- [Luca Guidi] Official support for Ruby: MRI 2.6
|
data/hanami-helpers.gemspec
CHANGED
@@ -24,6 +24,6 @@ Gem::Specification.new do |spec|
|
|
24
24
|
|
25
25
|
spec.add_development_dependency 'bundler', '>= 1.6', '< 3'
|
26
26
|
spec.add_development_dependency 'dry-struct', '~> 0.3'
|
27
|
-
spec.add_development_dependency 'rake', '~>
|
27
|
+
spec.add_development_dependency 'rake', '~> 13'
|
28
28
|
spec.add_development_dependency 'rspec', '~> 3.7'
|
29
29
|
end
|
@@ -230,6 +230,7 @@ module Hanami
|
|
230
230
|
# @param url [String] the form action URL
|
231
231
|
# @param options [Hash] HTML attributes to pass to the form tag and form values
|
232
232
|
# @option options [Hash] :values An optional payload of objects to pass
|
233
|
+
# @option options [Hash] :params An optional override of params
|
233
234
|
# @param blk [Proc] A block that describes the contents of the form
|
234
235
|
#
|
235
236
|
# @overload form_for(form, attributes = {}, &blk)
|
@@ -409,7 +410,25 @@ module Hanami
|
|
409
410
|
#
|
410
411
|
# <button type="submit">Create</button>
|
411
412
|
# </form>
|
412
|
-
|
413
|
+
#
|
414
|
+
# @example Override params
|
415
|
+
# <%=
|
416
|
+
# form_for :song, routes.songs_path, params: { song: { title: "Envision" } } do
|
417
|
+
# text_field :title
|
418
|
+
#
|
419
|
+
# submit 'Create'
|
420
|
+
# end
|
421
|
+
# %>
|
422
|
+
#
|
423
|
+
# <!-- output -->
|
424
|
+
#
|
425
|
+
# <form action="/songs" accept-charset="utf-8" id="song-form" method="POST">
|
426
|
+
# <input type="hidden" name="_csrf_token" value="920cd5bfaecc6e58368950e790f2f7b4e5561eeeab230aa1b7de1b1f40ea7d5d">
|
427
|
+
# <input type="text" name="song[title]" id="song-title" value="Envision">
|
428
|
+
#
|
429
|
+
# <button type="submit">Create</button>
|
430
|
+
# </form>
|
431
|
+
def form_for(name, url = nil, options = {}, &blk) # rubocop:disable Metrics/MethodLength
|
413
432
|
form = if name.is_a?(Form)
|
414
433
|
options = url || {}
|
415
434
|
name
|
@@ -417,11 +436,12 @@ module Hanami
|
|
417
436
|
Form.new(name, url, options.delete(:values))
|
418
437
|
end
|
419
438
|
|
439
|
+
params = options.delete(:params)
|
420
440
|
opts = options.dup
|
421
441
|
opts[:"data-remote"] = opts.delete(:remote) if opts.key?(:remote)
|
422
442
|
attributes = { action: form.url, method: form.verb, 'accept-charset': DEFAULT_CHARSET, id: "#{form.name}-form" }.merge(opts)
|
423
443
|
|
424
|
-
FormBuilder.new(form, attributes, self, &blk)
|
444
|
+
FormBuilder.new(form, attributes, self, params, &blk)
|
425
445
|
end
|
426
446
|
|
427
447
|
# Returns CSRF Protection Token stored in session.
|
@@ -81,11 +81,12 @@ module Hanami
|
|
81
81
|
|
82
82
|
# Instantiate a form builder
|
83
83
|
#
|
84
|
-
# @overload initialize(form, attributes, context, &blk)
|
84
|
+
# @overload initialize(form, attributes, context, params, &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
88
|
# @param context [Hanami::Helpers::FormHelper]
|
89
|
+
# @param params [Hash] optional set of params to override the ones that are coming from the view context
|
89
90
|
# @param blk [Proc] a block that describes the contents of the form
|
90
91
|
#
|
91
92
|
# @overload initialize(form, attributes, params, &blk)
|
@@ -99,7 +100,7 @@ module Hanami
|
|
99
100
|
#
|
100
101
|
# @since 0.2.0
|
101
102
|
# @api private
|
102
|
-
def initialize(form, attributes, context = nil, &blk) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
103
|
+
def initialize(form, attributes, context = nil, params = nil, &blk) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
103
104
|
super()
|
104
105
|
|
105
106
|
@context = context
|
@@ -115,7 +116,7 @@ module Hanami
|
|
115
116
|
else
|
116
117
|
@form = form
|
117
118
|
@name = form.name
|
118
|
-
@values = Values.new(form.values, @context.params)
|
119
|
+
@values = Values.new(form.values, params || @context.params)
|
119
120
|
@attributes = attributes
|
120
121
|
@verb_method = verb_method
|
121
122
|
@csrf_token = csrf_token
|
@@ -363,16 +364,31 @@ module Hanami
|
|
363
364
|
# <!-- output -->
|
364
365
|
# <label for="delivery-address-city">City</label>
|
365
366
|
# <input type="text" name="delivery[address][city] id="delivery-address-city" value="">
|
366
|
-
|
367
|
+
#
|
368
|
+
# @example Block syntax
|
369
|
+
# <%=
|
370
|
+
# # ...
|
371
|
+
# label for: :free_shipping do
|
372
|
+
# text "Free shipping"
|
373
|
+
# abbr "*", title: "optional", "aria-label": "optional"
|
374
|
+
# end
|
375
|
+
# %>
|
376
|
+
#
|
377
|
+
# <!-- output -->
|
378
|
+
# <label for="book-free-shipping">
|
379
|
+
# Free Shipping
|
380
|
+
# <abbr title="optional" aria-label="optional">*</abbr>
|
381
|
+
# </label>
|
382
|
+
def label(content = nil, **attributes, &blk)
|
367
383
|
attributes = { for: _for(content, attributes.delete(:for)) }.merge(attributes)
|
368
384
|
content = case content
|
369
|
-
when String, Hanami::Utils::String
|
385
|
+
when String, Hanami::Utils::String, NilClass
|
370
386
|
content
|
371
387
|
else
|
372
388
|
Utils::String.capitalize(content)
|
373
389
|
end
|
374
390
|
|
375
|
-
super(content, attributes)
|
391
|
+
super(content, attributes, &blk)
|
376
392
|
end
|
377
393
|
|
378
394
|
# Fieldset
|
@@ -1224,7 +1240,7 @@ module Hanami
|
|
1224
1240
|
#
|
1225
1241
|
# <!-- output -->
|
1226
1242
|
# <select name="book[store]" id="book-store" class="form-control">
|
1227
|
-
# <option>Select a store</option>
|
1243
|
+
# <option disabled="disabled">Select a store</option>
|
1228
1244
|
# <option value="it">Italy</option>
|
1229
1245
|
# <option value="us">United States</option>
|
1230
1246
|
# </select>
|
@@ -1287,7 +1303,7 @@ module Hanami
|
|
1287
1303
|
input_value = _value(name)
|
1288
1304
|
|
1289
1305
|
super(attributes) do
|
1290
|
-
option(prompt)
|
1306
|
+
option(prompt, disabled: true) if prompt
|
1291
1307
|
|
1292
1308
|
already_selected = nil
|
1293
1309
|
values.each do |content, 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.3.
|
4
|
+
version: 1.3.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: 2019-
|
11
|
+
date: 2019-10-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hanami-utils
|
@@ -64,14 +64,14 @@ dependencies:
|
|
64
64
|
requirements:
|
65
65
|
- - "~>"
|
66
66
|
- !ruby/object:Gem::Version
|
67
|
-
version: '
|
67
|
+
version: '13'
|
68
68
|
type: :development
|
69
69
|
prerelease: false
|
70
70
|
version_requirements: !ruby/object:Gem::Requirement
|
71
71
|
requirements:
|
72
72
|
- - "~>"
|
73
73
|
- !ruby/object:Gem::Version
|
74
|
-
version: '
|
74
|
+
version: '13'
|
75
75
|
- !ruby/object:Gem::Dependency
|
76
76
|
name: rspec
|
77
77
|
requirement: !ruby/object:Gem::Requirement
|
@@ -133,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
133
133
|
- !ruby/object:Gem::Version
|
134
134
|
version: '0'
|
135
135
|
requirements: []
|
136
|
-
rubygems_version: 3.0.
|
136
|
+
rubygems_version: 3.0.6
|
137
137
|
signing_key:
|
138
138
|
specification_version: 4
|
139
139
|
summary: Hanami helpers
|