hanami-helpers 1.2.0.rc1 → 1.2.0.rc2
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
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 403c3f57961c9fd5bd281e742f370e631e047caac752d206d5a7a1037a81edde
|
4
|
+
data.tar.gz: 997fb95bcba56d0fe55c19760ea3eceb5e0b3d3a791403bb39ba6a6987f74660
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c79301dfc9c74430890b2ffe1ebea44d4051fd290ea2fb05b8d6c1d1ee6263a2a3b139452832f0244a3e0138e43a71315ab756dedc3c4389f701ed7955289bb6
|
7
|
+
data.tar.gz: cd4bedad0aa5b9b39dd0a955aa2723ad9570c4797c23e4a7a88d6d360c1033cd11fcd4ab1a78992552e95cc7359474f1915f5ad7fe516899550a684b38528d57
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
# Hanami::Helpers
|
2
2
|
View helpers for Ruby web applications
|
3
3
|
|
4
|
+
## v1.2.0.rc2 - 2018-04-06
|
5
|
+
### Added
|
6
|
+
- [Ponomarev Ilya] Allow `submit` and `button` form helpers to accept blocks
|
7
|
+
- [Ferdinand Niedermann] let `fields_for_collection` to iterate thru the given collection and yield current index and value
|
8
|
+
|
4
9
|
## v1.2.0.rc1 - 2018-03-30
|
5
10
|
### Fixed
|
6
11
|
- [Gustavo Caso] Ensure `select` helper to set the `selected` attribute properly when an `<option>` has a `nil` value
|
@@ -8,11 +13,15 @@ View helpers for Ruby web applications
|
|
8
13
|
## v1.2.0.beta2 - 2018-03-23
|
9
14
|
|
10
15
|
## v1.2.0.beta1 - 2018-02-28
|
11
|
-
|
16
|
+
### Added
|
12
17
|
- [Luca Guidi] Introduced `csrf_meta_tags` helper to print meta tags for CSRF protection
|
13
18
|
- [Luca Guidi] Added support for `form_for(..., remote: true)` which translates to `<form ... data-remote="true">`
|
14
19
|
- [Sean Collins] Allow HTML attributes to be specified as an array of strings or symbols (eg `<%= html.span("foo", class: %w(ui form)) %>`)
|
15
20
|
|
21
|
+
## v1.1.2 - 2018-04-05
|
22
|
+
### Fixed
|
23
|
+
- [Luca Guidi] Ensure correct arity of `#form_for`, to be used in conjuction with `Hanami::Helpers::FormHelper::Form` (eg. `<%= form_for(form) { ... } %>`)
|
24
|
+
|
16
25
|
## v1.1.1 - 2018-02-27
|
17
26
|
### Fixed
|
18
27
|
- [Alfonso Uceda] Ensure `#select` form helper to not select options with `nil` value
|
data/hanami-helpers.gemspec
CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.require_paths = ['lib']
|
21
21
|
spec.required_ruby_version = '>= 2.3.0'
|
22
22
|
|
23
|
-
spec.add_dependency 'hanami-utils', '1.2.0.
|
23
|
+
spec.add_dependency 'hanami-utils', '1.2.0.rc2'
|
24
24
|
|
25
25
|
spec.add_development_dependency 'bundler', '~> 1.6'
|
26
26
|
spec.add_development_dependency 'dry-struct', '~> 0.3'
|
@@ -232,7 +232,7 @@ module Hanami
|
|
232
232
|
# @option options [Hash] :values An optional payload of objects to pass
|
233
233
|
# @param blk [Proc] A block that describes the contents of the form
|
234
234
|
#
|
235
|
-
# @overload form_for(form, attributes, &blk)
|
235
|
+
# @overload form_for(form, attributes = {}, &blk)
|
236
236
|
# Use Form
|
237
237
|
# @param form [Hanami::Helpers::FormHelper::Form] a form object
|
238
238
|
# @param attributes [Hash] HTML attributes to pass to the form tag and form values
|
@@ -409,9 +409,9 @@ module Hanami
|
|
409
409
|
#
|
410
410
|
# <button type="submit">Create</button>
|
411
411
|
# </form>
|
412
|
-
def form_for(name, url, options = {}, &blk)
|
412
|
+
def form_for(name, url = nil, options = {}, &blk)
|
413
413
|
form = if name.is_a?(Form)
|
414
|
-
options = url
|
414
|
+
options = url || {}
|
415
415
|
name
|
416
416
|
else
|
417
417
|
Form.new(name, url, options.delete(:values))
|
@@ -148,6 +148,9 @@ module Hanami
|
|
148
148
|
# @param name [Symbol] the nested name, it's used to generate input
|
149
149
|
# names, ids, and to lookup params to fill values.
|
150
150
|
#
|
151
|
+
# @yield [index]
|
152
|
+
# @yieldparam [Integer] index iterative index (it starts from zero)
|
153
|
+
#
|
151
154
|
# @since 0.2.0
|
152
155
|
#
|
153
156
|
# @example Basic usage
|
@@ -200,10 +203,10 @@ module Hanami
|
|
200
203
|
#
|
201
204
|
# <button type="submit">Create</button>
|
202
205
|
# </form>
|
203
|
-
def fields_for(name)
|
206
|
+
def fields_for(name, value = nil)
|
204
207
|
current_name = @name
|
205
208
|
@name = _input_name(name)
|
206
|
-
yield(name)
|
209
|
+
yield(name, value)
|
207
210
|
ensure
|
208
211
|
@name = current_name
|
209
212
|
end
|
@@ -216,6 +219,10 @@ module Hanami
|
|
216
219
|
# @param name [Symbol] the nested name, it's used to generate input
|
217
220
|
# names, ids, and to lookup params to fill values.
|
218
221
|
#
|
222
|
+
# @yield [index, value]
|
223
|
+
# @yieldparam [Integer] index iterative index (it starts from zero)
|
224
|
+
# @yieldparam [Object] value an item of the collection
|
225
|
+
#
|
219
226
|
# @example Basic usage
|
220
227
|
# <%=
|
221
228
|
# form_for :delivery, routes.deliveries_path do
|
@@ -238,13 +245,60 @@ module Hanami
|
|
238
245
|
#
|
239
246
|
# <button type="submit">Create</button>
|
240
247
|
# </form>
|
248
|
+
#
|
249
|
+
# @example Yield index and value
|
250
|
+
# <%=
|
251
|
+
# form_for(:bill, routes.bill_path(id: bill.id), { bill: bill }, method: :patch, class: 'form-horizontal') do
|
252
|
+
# fieldset do
|
253
|
+
# legend "Addresses"
|
254
|
+
#
|
255
|
+
# fields_for_collection :addresses do |i, address|
|
256
|
+
# div class: "form-group" do
|
257
|
+
# text "Address id: #{address.id}"
|
258
|
+
#
|
259
|
+
# label :street
|
260
|
+
# input_text :street, class: "form-control", placeholder: "Street", "data-funky": "index-#{i}"
|
261
|
+
# end
|
262
|
+
# end
|
263
|
+
#
|
264
|
+
# label :ensure_names
|
265
|
+
# end
|
266
|
+
#
|
267
|
+
# submit submit_label, class: "btn btn-default"
|
268
|
+
# end
|
269
|
+
# %>
|
270
|
+
#
|
271
|
+
# <!-- output -->
|
272
|
+
# <form action="/bills/1" method="POST" accept-charset="utf-8" id="bill-form" class="form-horizontal">
|
273
|
+
# <input type="hidden" name="_method" value="PATCH">
|
274
|
+
# <input type="hidden" name="_csrf_token" value="920cd5bfaecc6e58368950e790f2f7b4e5561eeeab230aa1b7de1b1f40ea7d5d">
|
275
|
+
# <fieldset>
|
276
|
+
# <legend>Addresses</legend>
|
277
|
+
#
|
278
|
+
# <div class="form-group">
|
279
|
+
# Address id: 23
|
280
|
+
# <label for="bill-addresses-0-street">Street</label>
|
281
|
+
# <input type="text" name="bill[addresses][][street]" id="bill-addresses-0-street" value="5th Ave" class="form-control" placeholder="Street" data-funky="index-0">
|
282
|
+
# </div>
|
283
|
+
#
|
284
|
+
# <div class="form-group">
|
285
|
+
# Address id: 42
|
286
|
+
# <label for="bill-addresses-1-street">Street</label>
|
287
|
+
# <input type="text" name="bill[addresses][][street]" id="bill-addresses-1-street" value="4th Ave" class="form-control" placeholder="Street" data-funky="index-1">
|
288
|
+
# </div>
|
289
|
+
#
|
290
|
+
# <label for="bill-ensure-names">Ensure names</label>
|
291
|
+
# </fieldset>
|
292
|
+
#
|
293
|
+
# <button type="submit" class="btn btn-default">Update</button>
|
294
|
+
# </form>
|
241
295
|
def fields_for_collection(name, &block)
|
242
296
|
current_name = @name
|
243
297
|
base_value = _value(name)
|
244
298
|
@name = _input_name(name)
|
245
299
|
|
246
|
-
base_value.
|
247
|
-
fields_for(index, &block)
|
300
|
+
base_value.each_with_index do |value, index|
|
301
|
+
fields_for(index, value, &block)
|
248
302
|
end
|
249
303
|
ensure
|
250
304
|
@name = current_name
|
@@ -1328,8 +1382,15 @@ module Hanami
|
|
1328
1382
|
|
1329
1383
|
# Button
|
1330
1384
|
#
|
1331
|
-
# @
|
1332
|
-
#
|
1385
|
+
# @overload button(content, attributes = {})
|
1386
|
+
# Use string content
|
1387
|
+
# @param content [String] The content
|
1388
|
+
# @param attributes [Hash] HTML attributes to pass to the button tag
|
1389
|
+
#
|
1390
|
+
# @overload button(attributes = {}, &blk)
|
1391
|
+
# Use block content
|
1392
|
+
# @param attributes [Hash] HTML attributes to pass to the button tag
|
1393
|
+
# @param blk [Proc] the block content
|
1333
1394
|
#
|
1334
1395
|
# @since 1.0.0
|
1335
1396
|
#
|
@@ -1350,8 +1411,25 @@ module Hanami
|
|
1350
1411
|
#
|
1351
1412
|
# <!-- output -->
|
1352
1413
|
# <button class="btn btn-secondary">Click me</button>
|
1353
|
-
|
1354
|
-
|
1414
|
+
#
|
1415
|
+
# @example Block
|
1416
|
+
# <%=
|
1417
|
+
# # ...
|
1418
|
+
# button class: "btn btn-secondary" do
|
1419
|
+
# span class: 'oi oi-check'
|
1420
|
+
# end
|
1421
|
+
# %>
|
1422
|
+
#
|
1423
|
+
# <!-- output -->
|
1424
|
+
# <button class="btn btn-secondary">
|
1425
|
+
# <span class="oi oi-check"></span>
|
1426
|
+
# </button>
|
1427
|
+
def button(content, attributes = {}, &blk)
|
1428
|
+
if content.is_a?(::Hash)
|
1429
|
+
attributes = content
|
1430
|
+
content = nil
|
1431
|
+
end
|
1432
|
+
|
1355
1433
|
super
|
1356
1434
|
end
|
1357
1435
|
|
@@ -1393,8 +1471,15 @@ module Hanami
|
|
1393
1471
|
|
1394
1472
|
# Submit button
|
1395
1473
|
#
|
1396
|
-
# @
|
1397
|
-
#
|
1474
|
+
# @overload submit(content, attributes = {})
|
1475
|
+
# Use string content
|
1476
|
+
# @param content [String] The content
|
1477
|
+
# @param attributes [Hash] HTML attributes to pass to the button tag
|
1478
|
+
#
|
1479
|
+
# @overload submit(attributes = {}, &blk)
|
1480
|
+
# Use block content
|
1481
|
+
# @param attributes [Hash] HTML attributes to pass to the button tag
|
1482
|
+
# @param blk [Proc] the block content
|
1398
1483
|
#
|
1399
1484
|
# @since 0.2.0
|
1400
1485
|
#
|
@@ -1415,9 +1500,27 @@ module Hanami
|
|
1415
1500
|
#
|
1416
1501
|
# <!-- output -->
|
1417
1502
|
# <button type="submit" class="btn btn-primary">Create</button>
|
1418
|
-
|
1503
|
+
#
|
1504
|
+
# @example Block
|
1505
|
+
# <%=
|
1506
|
+
# # ...
|
1507
|
+
# button class: "btn btn-primary" do
|
1508
|
+
# span class: 'oi oi-check'
|
1509
|
+
# end
|
1510
|
+
# %>
|
1511
|
+
#
|
1512
|
+
# <!-- output -->
|
1513
|
+
# <button type="submit" class="btn btn-primary">
|
1514
|
+
# <span class="oi oi-check"></span>
|
1515
|
+
# </button>
|
1516
|
+
def submit(content, attributes = {}, &blk)
|
1517
|
+
if content.is_a?(::Hash)
|
1518
|
+
attributes = content
|
1519
|
+
content = nil
|
1520
|
+
end
|
1521
|
+
|
1419
1522
|
attributes = { type: :submit }.merge(attributes)
|
1420
|
-
button(content, attributes)
|
1523
|
+
button(content, attributes, &blk)
|
1421
1524
|
end
|
1422
1525
|
|
1423
1526
|
protected
|
@@ -379,8 +379,8 @@ module Hanami
|
|
379
379
|
#
|
380
380
|
# @since 0.1.0
|
381
381
|
# @api private
|
382
|
-
def method_missing(
|
383
|
-
@context.__send__(
|
382
|
+
def method_missing(method_name, *args, &blk)
|
383
|
+
@context.__send__(method_name, *args, &blk)
|
384
384
|
end
|
385
385
|
end
|
386
386
|
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.2.0.
|
4
|
+
version: 1.2.0.rc2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luca Guidi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-04-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hanami-utils
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.2.0.
|
19
|
+
version: 1.2.0.rc2
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.2.0.
|
26
|
+
version: 1.2.0.rc2
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -128,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
128
128
|
version: 1.3.1
|
129
129
|
requirements: []
|
130
130
|
rubyforge_project:
|
131
|
-
rubygems_version: 2.7.
|
131
|
+
rubygems_version: 2.7.6
|
132
132
|
signing_key:
|
133
133
|
specification_version: 4
|
134
134
|
summary: Hanami helpers
|