hanami 2.1.0.rc2 → 2.1.0
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 +22 -1
- data/hanami.gemspec +2 -2
- data/lib/hanami/app.rb +0 -5
- data/lib/hanami/config.rb +1 -5
- data/lib/hanami/extensions/view/context.rb +12 -3
- data/lib/hanami/helpers/assets_helper.rb +31 -30
- data/lib/hanami/helpers/form_helper/form_builder.rb +54 -54
- data/lib/hanami/helpers/form_helper/values.rb +8 -8
- data/lib/hanami/helpers/form_helper.rb +9 -9
- data/lib/hanami/providers/assets.rb +3 -1
- data/lib/hanami/rake_tasks.rb +1 -9
- data/lib/hanami/slice/routing/middleware/stack.rb +3 -3
- data/lib/hanami/slice.rb +10 -0
- data/lib/hanami/version.rb +1 -1
- data/lib/hanami/web/welcome.html.erb +2 -6
- data/spec/integration/assets/assets_spec.rb +67 -24
- data/spec/integration/assets/cross_slice_assets_helpers_spec.rb +130 -0
- data/spec/integration/rack_app/middleware_spec.rb +66 -0
- data/spec/integration/view/context/assets_spec.rb +57 -31
- data/spec/support/app_integration.rb +12 -6
- data/spec/unit/hanami/helpers/assets_helper/asset_url_spec.rb +11 -0
- data/spec/unit/hanami/version_spec.rb +1 -1
- metadata +11 -9
@@ -12,25 +12,25 @@ module Hanami
|
|
12
12
|
# @see FormHelper#form_for
|
13
13
|
#
|
14
14
|
# @api public
|
15
|
-
# @since 2.
|
15
|
+
# @since 2.1.0
|
16
16
|
class FormBuilder
|
17
17
|
# Set of HTTP methods that are understood by web browsers
|
18
18
|
#
|
19
|
-
# @since 2.
|
19
|
+
# @since 2.1.0
|
20
20
|
# @api private
|
21
21
|
BROWSER_METHODS = %w[GET POST].freeze
|
22
22
|
private_constant :BROWSER_METHODS
|
23
23
|
|
24
24
|
# Set of HTTP methods that should NOT generate CSRF token
|
25
25
|
#
|
26
|
-
# @since 2.
|
26
|
+
# @since 2.1.0
|
27
27
|
# @api private
|
28
28
|
EXCLUDED_CSRF_METHODS = %w[GET].freeze
|
29
29
|
private_constant :EXCLUDED_CSRF_METHODS
|
30
30
|
|
31
31
|
# Separator for accept attribute of file input
|
32
32
|
#
|
33
|
-
# @since 2.
|
33
|
+
# @since 2.1.0
|
34
34
|
# @api private
|
35
35
|
#
|
36
36
|
# @see #file_input
|
@@ -39,7 +39,7 @@ module Hanami
|
|
39
39
|
|
40
40
|
# Default value for unchecked check box
|
41
41
|
#
|
42
|
-
# @since 2.
|
42
|
+
# @since 2.1.0
|
43
43
|
# @api private
|
44
44
|
#
|
45
45
|
# @see #check_box
|
@@ -48,7 +48,7 @@ module Hanami
|
|
48
48
|
|
49
49
|
# Default value for checked check box
|
50
50
|
#
|
51
|
-
# @since 2.
|
51
|
+
# @since 2.1.0
|
52
52
|
# @api private
|
53
53
|
#
|
54
54
|
# @see #check_box
|
@@ -57,14 +57,14 @@ module Hanami
|
|
57
57
|
|
58
58
|
# Input name separator
|
59
59
|
#
|
60
|
-
# @since 2.
|
60
|
+
# @since 2.1.0
|
61
61
|
# @api private
|
62
62
|
INPUT_NAME_SEPARATOR = "."
|
63
63
|
private_constant :INPUT_NAME_SEPARATOR
|
64
64
|
|
65
65
|
# Empty string
|
66
66
|
#
|
67
|
-
# @since 2.
|
67
|
+
# @since 2.1.0
|
68
68
|
# @api private
|
69
69
|
#
|
70
70
|
# @see #password_field
|
@@ -75,22 +75,22 @@ module Hanami
|
|
75
75
|
include Hanami::View::Helpers::TagHelper
|
76
76
|
|
77
77
|
# @api private
|
78
|
-
# @since 2.
|
78
|
+
# @since 2.1.0
|
79
79
|
attr_reader :base_name
|
80
80
|
private :base_name
|
81
81
|
|
82
82
|
# @api private
|
83
|
-
# @since 2.
|
83
|
+
# @since 2.1.0
|
84
84
|
attr_reader :values
|
85
85
|
private :values
|
86
86
|
|
87
87
|
# @api private
|
88
|
-
# @since 2.
|
88
|
+
# @since 2.1.0
|
89
89
|
attr_reader :inflector
|
90
90
|
private :inflector
|
91
91
|
|
92
92
|
# @api private
|
93
|
-
# @since 2.
|
93
|
+
# @since 2.1.0
|
94
94
|
attr_reader :form_attributes
|
95
95
|
private :form_attributes
|
96
96
|
|
@@ -105,7 +105,7 @@ module Hanami
|
|
105
105
|
# @see Hanami::Helpers::FormHelper#form_for
|
106
106
|
#
|
107
107
|
# @api private
|
108
|
-
# @since 2.
|
108
|
+
# @since 2.1.0
|
109
109
|
def initialize(inflector:, form_attributes:, base_name: nil, values: Values.new)
|
110
110
|
@base_name = base_name
|
111
111
|
@values = values
|
@@ -114,7 +114,7 @@ module Hanami
|
|
114
114
|
end
|
115
115
|
|
116
116
|
# @api private
|
117
|
-
# @since 2.
|
117
|
+
# @since 2.1.0
|
118
118
|
def call(content, **attributes)
|
119
119
|
attributes["accept-charset"] ||= DEFAULT_CHARSET
|
120
120
|
|
@@ -168,7 +168,7 @@ module Hanami
|
|
168
168
|
# <input type="text" name="delivery[address][location][city]" id="delivery-address-location-city" value="">
|
169
169
|
#
|
170
170
|
# @api public
|
171
|
-
# @since 2.
|
171
|
+
# @since 2.1.0
|
172
172
|
def fields_for(name, *yield_args)
|
173
173
|
new_base_name = [base_name, name.to_s].compact.join(INPUT_NAME_SEPARATOR)
|
174
174
|
|
@@ -224,7 +224,7 @@ module Hanami
|
|
224
224
|
# </div>
|
225
225
|
#
|
226
226
|
# @api public
|
227
|
-
# @since 2.
|
227
|
+
# @since 2.1.0
|
228
228
|
def fields_for_collection(name, &block)
|
229
229
|
collection_base_name = [base_name, name.to_s].compact.join(INPUT_NAME_SEPARATOR)
|
230
230
|
|
@@ -288,7 +288,7 @@ module Hanami
|
|
288
288
|
# </label>
|
289
289
|
#
|
290
290
|
# @api public
|
291
|
-
# @since 2.
|
291
|
+
# @since 2.1.0
|
292
292
|
def label(content = nil, **attributes, &block)
|
293
293
|
for_attribute_given = attributes.key?(:for)
|
294
294
|
|
@@ -323,7 +323,7 @@ module Hanami
|
|
323
323
|
# <input type="text" name="book[author][name]" id="book-author-name" value="">
|
324
324
|
# </fieldset>
|
325
325
|
#
|
326
|
-
# @since 2.
|
326
|
+
# @since 2.1.0
|
327
327
|
# @api public
|
328
328
|
def fieldset(...)
|
329
329
|
# This is here only for documentation purposes
|
@@ -403,7 +403,7 @@ module Hanami
|
|
403
403
|
# <input type="checkbox" name="book[languages][]" value="english">
|
404
404
|
#
|
405
405
|
# @api public
|
406
|
-
# @since 2.
|
406
|
+
# @since 2.1.0
|
407
407
|
def check_box(name, **attributes)
|
408
408
|
(+"").tap { |output|
|
409
409
|
output << _hidden_field_for_check_box(name, attributes).to_s
|
@@ -427,7 +427,7 @@ module Hanami
|
|
427
427
|
# => <input type="color" name="user[background]" id="user-background" value="" class="form-control">
|
428
428
|
#
|
429
429
|
# @api public
|
430
|
-
# @since 2.
|
430
|
+
# @since 2.1.0
|
431
431
|
def color_field(name, **attributes)
|
432
432
|
input(**_attributes(:color, name, attributes))
|
433
433
|
end
|
@@ -448,7 +448,7 @@ module Hanami
|
|
448
448
|
# => <input type="date" name="user[birth_date]" id="user-birth-date" value="" class="form-control">
|
449
449
|
#
|
450
450
|
# @api public
|
451
|
-
# @since 2.
|
451
|
+
# @since 2.1.0
|
452
452
|
def date_field(name, **attributes)
|
453
453
|
input(**_attributes(:date, name, attributes))
|
454
454
|
end
|
@@ -469,7 +469,7 @@ module Hanami
|
|
469
469
|
# => <input type="datetime" name="delivery[delivered_at]" id="delivery-delivered-at" value="" class="form-control">
|
470
470
|
#
|
471
471
|
# @api public
|
472
|
-
# @since 2.
|
472
|
+
# @since 2.1.0
|
473
473
|
def datetime_field(name, **attributes)
|
474
474
|
input(**_attributes(:datetime, name, attributes))
|
475
475
|
end
|
@@ -490,7 +490,7 @@ module Hanami
|
|
490
490
|
# => <input type="datetime-local" name="delivery[delivered_at]" id="delivery-delivered-at" value="" class="form-control">
|
491
491
|
#
|
492
492
|
# @api public
|
493
|
-
# @since 2.
|
493
|
+
# @since 2.1.0
|
494
494
|
def datetime_local_field(name, **attributes)
|
495
495
|
input(**_attributes(:"datetime-local", name, attributes))
|
496
496
|
end
|
@@ -511,7 +511,7 @@ module Hanami
|
|
511
511
|
# => <input type="time" name="book[release_hour]" id="book-release-hour" value="" class="form-control">
|
512
512
|
#
|
513
513
|
# @api public
|
514
|
-
# @since 2.
|
514
|
+
# @since 2.1.0
|
515
515
|
def time_field(name, **attributes)
|
516
516
|
input(**_attributes(:time, name, attributes))
|
517
517
|
end
|
@@ -532,7 +532,7 @@ module Hanami
|
|
532
532
|
# => <input type="month" name="book[release_month]" id="book-release-month" value="" class="form-control">
|
533
533
|
#
|
534
534
|
# @api public
|
535
|
-
# @since 2.
|
535
|
+
# @since 2.1.0
|
536
536
|
def month_field(name, **attributes)
|
537
537
|
input(**_attributes(:month, name, attributes))
|
538
538
|
end
|
@@ -553,7 +553,7 @@ module Hanami
|
|
553
553
|
# => <input type="week" name="book[release_week]" id="book-release-week" value="" class="form-control">
|
554
554
|
#
|
555
555
|
# @api public
|
556
|
-
# @since 2.
|
556
|
+
# @since 2.1.0
|
557
557
|
def week_field(name, **attributes)
|
558
558
|
input(**_attributes(:week, name, attributes))
|
559
559
|
end
|
@@ -574,7 +574,7 @@ module Hanami
|
|
574
574
|
# => <input type="email" name="user[email]" id="user-email" value="" class="form-control">
|
575
575
|
#
|
576
576
|
# @api public
|
577
|
-
# @since 2.
|
577
|
+
# @since 2.1.0
|
578
578
|
def email_field(name, **attributes)
|
579
579
|
input(**_attributes(:email, name, attributes))
|
580
580
|
end
|
@@ -595,7 +595,7 @@ module Hanami
|
|
595
595
|
# => <input type="url" name="user[website]" id="user-website" value="" class="form-control">
|
596
596
|
#
|
597
597
|
# @api public
|
598
|
-
# @since 2.
|
598
|
+
# @since 2.1.0
|
599
599
|
def url_field(name, **attributes)
|
600
600
|
attributes[:value] = sanitize_url(attributes.fetch(:value) { _value(name) })
|
601
601
|
|
@@ -618,7 +618,7 @@ module Hanami
|
|
618
618
|
# => <input type="tel" name="user[telephone]" id="user-telephone" value="" class="form-control">
|
619
619
|
#
|
620
620
|
# @api public
|
621
|
-
# @since 2.
|
621
|
+
# @since 2.1.0
|
622
622
|
def tel_field(name, **attributes)
|
623
623
|
input(**_attributes(:tel, name, attributes))
|
624
624
|
end
|
@@ -635,7 +635,7 @@ module Hanami
|
|
635
635
|
# => <input type="hidden" name="delivery[customer_id]" id="delivery-customer-id" value="">
|
636
636
|
#
|
637
637
|
# @api public
|
638
|
-
# @since 2.
|
638
|
+
# @since 2.1.0
|
639
639
|
def hidden_field(name, **attributes)
|
640
640
|
input(**_attributes(:hidden, name, attributes))
|
641
641
|
end
|
@@ -669,7 +669,7 @@ module Hanami
|
|
669
669
|
# => <input type="file" name="user[resume]" id="user-resume" multiple="multiple">
|
670
670
|
#
|
671
671
|
# @api public
|
672
|
-
# @since 2.
|
672
|
+
# @since 2.1.0
|
673
673
|
def file_field(name, **attributes)
|
674
674
|
form_attributes[:enctype] = "multipart/form-data"
|
675
675
|
|
@@ -697,7 +697,7 @@ module Hanami
|
|
697
697
|
# => <input type="number" name="book[percent_read]" id="book-precent-read" value="" min="1" max="100" step="1">
|
698
698
|
#
|
699
699
|
# @api public
|
700
|
-
# @since 2.
|
700
|
+
# @since 2.1.0
|
701
701
|
def number_field(name, **attributes)
|
702
702
|
input(**_attributes(:number, name, attributes))
|
703
703
|
end
|
@@ -720,7 +720,7 @@ module Hanami
|
|
720
720
|
# => <input type="number" name="book[discount_percentage]" id="book-discount-percentage" value="" min="1" max="100" step="1">
|
721
721
|
#
|
722
722
|
# @api public
|
723
|
-
# @since 2.
|
723
|
+
# @since 2.1.0
|
724
724
|
def range_field(name, **attributes)
|
725
725
|
input(**_attributes(:range, name, attributes))
|
726
726
|
end
|
@@ -747,7 +747,7 @@ module Hanami
|
|
747
747
|
# => <textarea name="user[hobby]" id="user-hobby" class="form-control"></textarea>
|
748
748
|
#
|
749
749
|
# @api public
|
750
|
-
# @since 2.
|
750
|
+
# @since 2.1.0
|
751
751
|
def text_area(name, content = nil, **attributes)
|
752
752
|
if content.respond_to?(:to_hash)
|
753
753
|
attributes = content
|
@@ -774,7 +774,7 @@ module Hanami
|
|
774
774
|
# => <input type="text" name="user[first_name]" id="user-first-name" value="" class="form-control">
|
775
775
|
#
|
776
776
|
# @api public
|
777
|
-
# @since 2.
|
777
|
+
# @since 2.1.0
|
778
778
|
def text_field(name, **attributes)
|
779
779
|
input(**_attributes(:text, name, attributes))
|
780
780
|
end
|
@@ -796,7 +796,7 @@ module Hanami
|
|
796
796
|
# => <input type="search" name="search[q]" id="search-q" value="" class="form-control">
|
797
797
|
#
|
798
798
|
# @api public
|
799
|
-
# @since 2.
|
799
|
+
# @since 2.1.0
|
800
800
|
def search_field(name, **attributes)
|
801
801
|
input(**_attributes(:search, name, attributes))
|
802
802
|
end
|
@@ -839,7 +839,7 @@ module Hanami
|
|
839
839
|
# <input type="radio" name="book[category]" value="Non-Fiction" checked="checked">
|
840
840
|
#
|
841
841
|
# @api public
|
842
|
-
# @since 2.
|
842
|
+
# @since 2.1.0
|
843
843
|
def radio_button(name, value, **attributes)
|
844
844
|
attributes = {type: :radio, name: _input_name(name), value: value, **attributes}
|
845
845
|
attributes[:checked] = true if _value(name).to_s == value.to_s
|
@@ -859,7 +859,7 @@ module Hanami
|
|
859
859
|
# => <input type="password" name="signup[password]" id="signup-password" value="">
|
860
860
|
#
|
861
861
|
# @api public
|
862
|
-
# @since 2.
|
862
|
+
# @since 2.1.0
|
863
863
|
def password_field(name, **attributes)
|
864
864
|
attrs = {type: :password, name: _input_name(name), id: _input_id(name), value: nil, **attributes}
|
865
865
|
attrs[:value] = EMPTY_STRING if attrs[:value].nil?
|
@@ -987,7 +987,7 @@ module Hanami
|
|
987
987
|
# </select>
|
988
988
|
#
|
989
989
|
# @api public
|
990
|
-
# @since 2.
|
990
|
+
# @since 2.1.0
|
991
991
|
def select(name, values, **attributes) # rubocop:disable Metrics/AbcSize
|
992
992
|
options = attributes.delete(:options) { {} }
|
993
993
|
multiple = attributes[:multiple]
|
@@ -1066,7 +1066,7 @@ module Hanami
|
|
1066
1066
|
# </datalist>
|
1067
1067
|
#
|
1068
1068
|
# @api public
|
1069
|
-
# @since 2.
|
1069
|
+
# @since 2.1.0
|
1070
1070
|
def datalist(name, values, list, **attributes)
|
1071
1071
|
options = attributes.delete(:options) || {}
|
1072
1072
|
datalist = attributes.delete(:datalist) || {}
|
@@ -1121,7 +1121,7 @@ module Hanami
|
|
1121
1121
|
# </button>
|
1122
1122
|
#
|
1123
1123
|
# @api public
|
1124
|
-
# @since 2.
|
1124
|
+
# @since 2.1.0
|
1125
1125
|
def button(...)
|
1126
1126
|
tag.button(...)
|
1127
1127
|
end
|
@@ -1144,7 +1144,7 @@ module Hanami
|
|
1144
1144
|
# => <input name="image" width="50" type="image" src="https://hanamirb.org/assets/button.png">
|
1145
1145
|
#
|
1146
1146
|
# @api public
|
1147
|
-
# @since 2.
|
1147
|
+
# @since 2.1.0
|
1148
1148
|
def image_button(source, **attributes)
|
1149
1149
|
attributes[:type] = :image
|
1150
1150
|
attributes[:src] = sanitize_url(source)
|
@@ -1188,7 +1188,7 @@ module Hanami
|
|
1188
1188
|
# </button>
|
1189
1189
|
#
|
1190
1190
|
# @api public
|
1191
|
-
# @since 2.
|
1191
|
+
# @since 2.1.0
|
1192
1192
|
def submit(content = nil, **attributes, &blk)
|
1193
1193
|
if content.is_a?(::Hash)
|
1194
1194
|
attributes = content
|
@@ -1209,7 +1209,7 @@ module Hanami
|
|
1209
1209
|
#
|
1210
1210
|
# @return [String] the tag
|
1211
1211
|
#
|
1212
|
-
# @since 2.
|
1212
|
+
# @since 2.1.0
|
1213
1213
|
# @api public
|
1214
1214
|
#
|
1215
1215
|
# @example Basic usage
|
@@ -1217,7 +1217,7 @@ module Hanami
|
|
1217
1217
|
# => <input type="text" name="book[title]" id="book-title" value="Hanami book">
|
1218
1218
|
#
|
1219
1219
|
# @api public
|
1220
|
-
# @since 2.
|
1220
|
+
# @since 2.1.0
|
1221
1221
|
def input(...)
|
1222
1222
|
tag.input(...)
|
1223
1223
|
end
|
@@ -1225,7 +1225,7 @@ module Hanami
|
|
1225
1225
|
private
|
1226
1226
|
|
1227
1227
|
# @api private
|
1228
|
-
# @since 2.
|
1228
|
+
# @since 2.1.0
|
1229
1229
|
def _form_method(attributes)
|
1230
1230
|
attributes[:method] ||= DEFAULT_METHOD
|
1231
1231
|
attributes[:method] = attributes[:method].to_s.upcase
|
@@ -1240,7 +1240,7 @@ module Hanami
|
|
1240
1240
|
end
|
1241
1241
|
|
1242
1242
|
# @api private
|
1243
|
-
# @since 2.
|
1243
|
+
# @since 2.1.0
|
1244
1244
|
def _csrf_token(values, attributes)
|
1245
1245
|
return [] if values.csrf_token.nil?
|
1246
1246
|
|
@@ -1250,7 +1250,7 @@ module Hanami
|
|
1250
1250
|
end
|
1251
1251
|
|
1252
1252
|
# @api private
|
1253
|
-
# @since 2.
|
1253
|
+
# @since 2.1.0
|
1254
1254
|
def _attributes(type, name, attributes)
|
1255
1255
|
attrs = {
|
1256
1256
|
type: type,
|
@@ -1264,7 +1264,7 @@ module Hanami
|
|
1264
1264
|
end
|
1265
1265
|
|
1266
1266
|
# @api private
|
1267
|
-
# @since 2.
|
1267
|
+
# @since 2.1.0
|
1268
1268
|
def _input_name(name)
|
1269
1269
|
tokens = _split_input_name(name)
|
1270
1270
|
result = tokens.shift
|
@@ -1281,19 +1281,19 @@ module Hanami
|
|
1281
1281
|
end
|
1282
1282
|
|
1283
1283
|
# @api private
|
1284
|
-
# @since 2.
|
1284
|
+
# @since 2.1.0
|
1285
1285
|
def _input_id(name)
|
1286
1286
|
[base_name, name].compact.join(INPUT_NAME_SEPARATOR).to_s.tr("._", "-")
|
1287
1287
|
end
|
1288
1288
|
|
1289
1289
|
# @api private
|
1290
|
-
# @since 2.
|
1290
|
+
# @since 2.1.0
|
1291
1291
|
def _value(name)
|
1292
1292
|
values.get(*_split_input_name(name).map(&:to_sym))
|
1293
1293
|
end
|
1294
1294
|
|
1295
1295
|
# @api private
|
1296
|
-
# @since 2.
|
1296
|
+
# @since 2.1.0
|
1297
1297
|
def _split_input_name(name)
|
1298
1298
|
[
|
1299
1299
|
*base_name.to_s.split(INPUT_NAME_SEPARATOR),
|
@@ -1302,7 +1302,7 @@ module Hanami
|
|
1302
1302
|
end
|
1303
1303
|
|
1304
1304
|
# @api private
|
1305
|
-
# @since 2.
|
1305
|
+
# @since 2.1.0
|
1306
1306
|
#
|
1307
1307
|
# @see #check_box
|
1308
1308
|
def _hidden_field_for_check_box(name, attributes)
|
@@ -1316,7 +1316,7 @@ module Hanami
|
|
1316
1316
|
end
|
1317
1317
|
|
1318
1318
|
# @api private
|
1319
|
-
# @since 2.
|
1319
|
+
# @since 2.1.0
|
1320
1320
|
#
|
1321
1321
|
# @see #check_box
|
1322
1322
|
def _attributes_for_check_box(name, attributes)
|
@@ -8,18 +8,18 @@ module Hanami
|
|
8
8
|
# It's responsible to populate input values with data coming from params
|
9
9
|
# and inline values specified via form helpers like `text_field`.
|
10
10
|
#
|
11
|
-
# @since 2.
|
11
|
+
# @since 2.1.0
|
12
12
|
# @api private
|
13
13
|
class Values
|
14
|
-
# @since 2.
|
14
|
+
# @since 2.1.0
|
15
15
|
# @api private
|
16
16
|
GET_SEPARATOR = "."
|
17
17
|
|
18
18
|
# @api private
|
19
|
-
# @since 2.
|
19
|
+
# @since 2.1.0
|
20
20
|
attr_reader :csrf_token
|
21
21
|
|
22
|
-
# @since 2.
|
22
|
+
# @since 2.1.0
|
23
23
|
# @api private
|
24
24
|
def initialize(values: {}, params: {}, csrf_token: nil)
|
25
25
|
@values = values.to_h
|
@@ -30,7 +30,7 @@ module Hanami
|
|
30
30
|
# Returns the value (if present) for the given key.
|
31
31
|
# Nested values are expressed with an array if symbols.
|
32
32
|
#
|
33
|
-
# @since 2.
|
33
|
+
# @since 2.1.0
|
34
34
|
# @api private
|
35
35
|
def get(*keys)
|
36
36
|
get_from_params(*keys) || get_from_values(*keys)
|
@@ -38,14 +38,14 @@ module Hanami
|
|
38
38
|
|
39
39
|
private
|
40
40
|
|
41
|
-
# @since 2.
|
41
|
+
# @since 2.1.0
|
42
42
|
# @api private
|
43
43
|
def get_from_params(*keys)
|
44
44
|
keys.map! { |key| /\A\d+\z/.match?(key.to_s) ? key.to_s.to_i : key }
|
45
45
|
@params.dig(*keys)
|
46
46
|
end
|
47
47
|
|
48
|
-
# @since 2.
|
48
|
+
# @since 2.1.0
|
49
49
|
# @api private
|
50
50
|
def get_from_values(*keys)
|
51
51
|
head, *tail = *keys
|
@@ -60,7 +60,7 @@ module Hanami
|
|
60
60
|
result
|
61
61
|
end
|
62
62
|
|
63
|
-
# @since 2.
|
63
|
+
# @since 2.1.0
|
64
64
|
# @api private
|
65
65
|
def dig(base, key)
|
66
66
|
case base
|
@@ -14,19 +14,19 @@ module Hanami
|
|
14
14
|
# values.
|
15
15
|
#
|
16
16
|
# @api public
|
17
|
-
# @since 2.
|
17
|
+
# @since 2.1.0
|
18
18
|
module FormHelper
|
19
19
|
require_relative "form_helper/form_builder"
|
20
20
|
|
21
21
|
# Default HTTP method for form
|
22
22
|
#
|
23
|
-
# @since 2.
|
23
|
+
# @since 2.1.0
|
24
24
|
# @api private
|
25
25
|
DEFAULT_METHOD = "POST"
|
26
26
|
|
27
27
|
# Default charset
|
28
28
|
#
|
29
|
-
# @since 2.
|
29
|
+
# @since 2.1.0
|
30
30
|
# @api private
|
31
31
|
DEFAULT_CHARSET = "utf-8"
|
32
32
|
|
@@ -34,7 +34,7 @@ module Hanami
|
|
34
34
|
#
|
35
35
|
# This name of this key is shared with the hanami and hanami-controller gems.
|
36
36
|
#
|
37
|
-
# @since 2.
|
37
|
+
# @since 2.1.0
|
38
38
|
# @api private
|
39
39
|
CSRF_TOKEN = :_csrf_token
|
40
40
|
|
@@ -145,7 +145,7 @@ module Hanami
|
|
145
145
|
# </form>
|
146
146
|
#
|
147
147
|
# @api public
|
148
|
-
# @since 2.
|
148
|
+
# @since 2.1.0
|
149
149
|
def form_for(base_name, url = nil, values: _form_for_values, params: _form_for_params, **attributes)
|
150
150
|
url, base_name = base_name, nil if url.nil?
|
151
151
|
|
@@ -175,7 +175,7 @@ module Hanami
|
|
175
175
|
# <meta name="csrf-token" content="4a038be85b7603c406dcbfad4b9cdf91ec6ca138ed6441163a07bb0fdfbe25b5">
|
176
176
|
#
|
177
177
|
# @api public
|
178
|
-
# @since 2.
|
178
|
+
# @since 2.1.0
|
179
179
|
def csrf_meta_tags
|
180
180
|
return unless (token = _form_csrf_token)
|
181
181
|
|
@@ -184,7 +184,7 @@ module Hanami
|
|
184
184
|
end
|
185
185
|
|
186
186
|
# @api private
|
187
|
-
# @since 2.
|
187
|
+
# @since 2.1.0
|
188
188
|
def _form_for_values
|
189
189
|
if respond_to?(:_locals) # Scope
|
190
190
|
_locals
|
@@ -196,12 +196,12 @@ module Hanami
|
|
196
196
|
end
|
197
197
|
|
198
198
|
# @api private
|
199
|
-
# @since 2.
|
199
|
+
# @since 2.1.0
|
200
200
|
def _form_for_params
|
201
201
|
_context.request.params
|
202
202
|
end
|
203
203
|
|
204
|
-
# @since 2.
|
204
|
+
# @since 2.1.0
|
205
205
|
# @api private
|
206
206
|
def _form_csrf_token
|
207
207
|
return unless _context.request.session_enabled?
|
@@ -29,7 +29,9 @@ module Hanami
|
|
29
29
|
|
30
30
|
# @api private
|
31
31
|
def start
|
32
|
-
|
32
|
+
root = slice.app.root.join("public", "assets", Hanami::Assets.public_assets_dir(slice).to_s)
|
33
|
+
|
34
|
+
assets = Hanami::Assets.new(config: slice.config.assets, root: root)
|
33
35
|
|
34
36
|
register(:assets, assets)
|
35
37
|
end
|
data/lib/hanami/rake_tasks.rb
CHANGED
@@ -44,18 +44,10 @@ Hanami::CLI::RakeTasks.register_tasks do
|
|
44
44
|
if Hanami.bundled?("hanami-assets")
|
45
45
|
namespace :assets do
|
46
46
|
task :precompile do
|
47
|
-
|
47
|
+
Hanami::CLI::Commands::App::Assets::Compile.new.call
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
51
|
-
|
52
|
-
private
|
53
|
-
|
54
|
-
@_hanami_cli_bundler = Hanami::CLI::Bundler.new
|
55
|
-
|
56
|
-
def run_hanami_command(command)
|
57
|
-
@_hanami_cli_bundler.hanami_exec(command)
|
58
|
-
end
|
59
51
|
end
|
60
52
|
|
61
53
|
Hanami::CLI::RakeTasks.install_tasks
|
@@ -91,16 +91,16 @@ module Hanami
|
|
91
91
|
#
|
92
92
|
# @api public
|
93
93
|
# @since 2.0.0
|
94
|
-
def use(spec, *args, path_prefix: ::Hanami::Router::DEFAULT_PREFIX, before: nil, after: nil, &blk)
|
94
|
+
def use(spec, *args, path_prefix: ::Hanami::Router::DEFAULT_PREFIX, before: nil, after: nil, **kwargs, &blk)
|
95
95
|
middleware = resolve_middleware_class(spec)
|
96
|
-
item = [middleware, args, blk]
|
96
|
+
item = [middleware, args, kwargs, blk]
|
97
97
|
|
98
98
|
if before
|
99
99
|
@stack[path_prefix].insert((idx = index_of(before, path_prefix)).zero? ? 0 : idx - 1, item)
|
100
100
|
elsif after
|
101
101
|
@stack[path_prefix].insert(index_of(after, path_prefix) + 1, item)
|
102
102
|
else
|
103
|
-
@stack[path_prefix].push(
|
103
|
+
@stack[path_prefix].push(item)
|
104
104
|
end
|
105
105
|
|
106
106
|
self
|
data/lib/hanami/slice.rb
CHANGED
@@ -895,6 +895,11 @@ module Hanami
|
|
895
895
|
require_relative "providers/routes"
|
896
896
|
register_provider(:routes, source: Providers::Routes.for_slice(self))
|
897
897
|
end
|
898
|
+
|
899
|
+
if assets_dir? && Hanami.bundled?("hanami-assets")
|
900
|
+
require_relative "providers/assets"
|
901
|
+
register_provider(:assets, source: Providers::Assets.for_slice(self))
|
902
|
+
end
|
898
903
|
end
|
899
904
|
|
900
905
|
def prepare_autoloader
|
@@ -1022,6 +1027,11 @@ module Hanami
|
|
1022
1027
|
}.freeze
|
1023
1028
|
private_constant :ROUTER_NOT_FOUND_HANDLER
|
1024
1029
|
|
1030
|
+
def assets_dir?
|
1031
|
+
assets_path = app.eql?(self) ? root.join("app", "assets") : root.join("assets")
|
1032
|
+
assets_path.directory?
|
1033
|
+
end
|
1034
|
+
|
1025
1035
|
# rubocop:enable Metrics/AbcSize
|
1026
1036
|
end
|
1027
1037
|
# rubocop:enable Metrics/ModuleLength
|