hanami-helpers 1.3.1 → 1.3.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5b8b6087b11385128dca97a30a4b3178c5d087fb533096adf20cc0cb666c6b25
4
- data.tar.gz: f1bf68d6b197a0f0a89cc85002355d3f13eecbc65d137a959e67c31adb24134a
3
+ metadata.gz: 164baa1c2d4f10946f6a48b10d507fc4d98f13d08abbdd3004e6c4ffdbc0a8cb
4
+ data.tar.gz: 2fdac7777fc6dd841b22d23acb681bcafac842ea2b0cdbf76fdf972fbb6aa61d
5
5
  SHA512:
6
- metadata.gz: e3faa5e7b7ed1c3dd37452d835938dd7e1a744c90d6587e4642474cd62b97caa3fa4a36ed30194295f65b8ba37e09c09a2a90c1099f0a42310f7604e38626e5d
7
- data.tar.gz: d9a471c73b03b00d6d8df9a255c1d0cc7177dc31e6640eb2e6162b2eeaecacc8bd71d51569f28e5cefab4b652f9384217829c0481af4974f3f394f8688c8975e
6
+ metadata.gz: 27641b03250b80e892697d503323613704f6b03bfd97519e871286e22434b264a71881d5a62fda5ba484da9561588588bb5c0cc57981433b61dd149fbe2955fd
7
+ data.tar.gz: e062653bf269742f7a5b77d6b0bf72457e8f73f067104845aea23bbfba371bd9b4b04b3c59536bc6d26482f2ad5a301a78856b283c2c938ffd2f4c4e442dd0b0
@@ -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
@@ -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', '~> 12'
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
- def form_for(name, url = nil, options = {}, &blk)
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
- def label(content, attributes = {})
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) unless prompt.nil?
1306
+ option(prompt, disabled: true) if prompt
1291
1307
 
1292
1308
  already_selected = nil
1293
1309
  values.each do |content, value|
@@ -3,6 +3,6 @@ module Hanami
3
3
  # Define version
4
4
  #
5
5
  # @since 0.1.0
6
- VERSION = '1.3.1'.freeze
6
+ VERSION = '1.3.2'.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.3.1
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-01-18 00:00:00.000000000 Z
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: '12'
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: '12'
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.2
136
+ rubygems_version: 3.0.6
137
137
  signing_key:
138
138
  specification_version: 4
139
139
  summary: Hanami helpers