hanami-utils 1.3.7 → 2.0.0.alpha1
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 +14 -29
- data/README.md +5 -13
- data/hanami-utils.gemspec +3 -4
- data/lib/hanami/interactor.rb +29 -53
- data/lib/hanami/logger.rb +12 -12
- data/lib/hanami/logger/colorizer.rb +10 -10
- data/lib/hanami/logger/filter.rb +10 -89
- data/lib/hanami/logger/formatter.rb +7 -7
- data/lib/hanami/middleware.rb +11 -0
- data/lib/hanami/utils.rb +3 -19
- data/lib/hanami/utils/basic_object.rb +3 -63
- data/lib/hanami/utils/blank.rb +6 -8
- data/lib/hanami/utils/callbacks.rb +20 -5
- data/lib/hanami/utils/class.rb +3 -52
- data/lib/hanami/utils/class_attribute.rb +22 -13
- data/lib/hanami/utils/class_attribute/attributes.rb +45 -0
- data/lib/hanami/utils/escape.rb +170 -172
- data/lib/hanami/utils/file_list.rb +1 -1
- data/lib/hanami/utils/files.rb +2 -31
- data/lib/hanami/utils/hash.rb +12 -341
- data/lib/hanami/utils/json.rb +1 -1
- data/lib/hanami/utils/kernel.rb +12 -11
- data/lib/hanami/utils/load_paths.rb +3 -3
- data/lib/hanami/utils/query_string.rb +1 -1
- data/lib/hanami/utils/shell_color.rb +9 -9
- data/lib/hanami/utils/string.rb +38 -102
- data/lib/hanami/utils/version.rb +1 -1
- metadata +15 -29
- data/lib/hanami/utils/duplicable.rb +0 -82
- data/lib/hanami/utils/inflector.rb +0 -493
data/lib/hanami/utils/escape.rb
CHANGED
@@ -39,7 +39,7 @@ module Hanami
|
|
39
39
|
# @since 0.4.0
|
40
40
|
# @api private
|
41
41
|
HEX_CODES = (0..255).each_with_object({}) do |c, codes|
|
42
|
-
if (c >= 0x30 && c <= 0x39) || (c >= 0x41 && c <= 0x5A) || (c >= 0x61 && c <= 0x7A)
|
42
|
+
if (c >= 0x30 && c <= 0x39) || (c >= 0x41 && c <= 0x5A) || (c >= 0x61 && c <= 0x7A) # rubocop:disable Style/ConditionalAssignment
|
43
43
|
codes[c] = nil
|
44
44
|
else
|
45
45
|
codes[c] = c.to_s(HEX_BASE)
|
@@ -55,8 +55,8 @@ module Hanami
|
|
55
55
|
#
|
56
56
|
# @see https://gist.github.com/jodosha/ac5dd54416de744b9600
|
57
57
|
NON_PRINTABLE_CHARS = {
|
58
|
-
0x0
|
59
|
-
0x5
|
58
|
+
0x0 => true, 0x1 => true, 0x2 => true, 0x3 => true, 0x4 => true,
|
59
|
+
0x5 => true, 0x6 => true, 0x7 => true, 0x8 => true, 0x11 => true,
|
60
60
|
0x12 => true, 0x14 => true, 0x15 => true, 0x16 => true, 0x17 => true,
|
61
61
|
0x18 => true, 0x19 => true, 0x1a => true, 0x1b => true, 0x1c => true,
|
62
62
|
0x1d => true, 0x1e => true, 0x1f => true, 0x7f => true, 0x80 => true,
|
@@ -104,166 +104,166 @@ module Hanami
|
|
104
104
|
#
|
105
105
|
# @see Hanami::Utils::Escape.html_attribute
|
106
106
|
HTML_ENTITIES = {
|
107
|
-
34
|
108
|
-
38
|
109
|
-
60
|
110
|
-
62
|
111
|
-
160
|
112
|
-
161
|
113
|
-
162
|
114
|
-
163
|
115
|
-
164
|
116
|
-
165
|
117
|
-
166
|
118
|
-
167
|
119
|
-
168
|
120
|
-
169
|
121
|
-
170
|
122
|
-
171
|
123
|
-
172
|
124
|
-
173
|
125
|
-
174
|
126
|
-
175
|
127
|
-
176
|
128
|
-
177
|
129
|
-
178
|
130
|
-
179
|
131
|
-
180
|
132
|
-
181
|
133
|
-
182
|
134
|
-
183
|
135
|
-
184
|
136
|
-
185
|
137
|
-
186
|
138
|
-
187
|
139
|
-
188
|
140
|
-
189
|
141
|
-
190
|
142
|
-
191
|
143
|
-
192
|
144
|
-
193
|
145
|
-
194
|
146
|
-
195
|
147
|
-
196
|
148
|
-
197
|
149
|
-
198
|
150
|
-
199
|
151
|
-
200
|
152
|
-
201
|
153
|
-
202
|
154
|
-
203
|
155
|
-
204
|
156
|
-
205
|
157
|
-
206
|
158
|
-
207
|
159
|
-
208
|
160
|
-
209
|
161
|
-
210
|
162
|
-
211
|
163
|
-
212
|
164
|
-
213
|
165
|
-
214
|
166
|
-
215
|
167
|
-
216
|
168
|
-
217
|
169
|
-
218
|
170
|
-
219
|
171
|
-
220
|
172
|
-
221
|
173
|
-
222
|
174
|
-
223
|
175
|
-
224
|
176
|
-
225
|
177
|
-
226
|
178
|
-
227
|
179
|
-
228
|
180
|
-
229
|
181
|
-
230
|
182
|
-
231
|
183
|
-
232
|
184
|
-
233
|
185
|
-
234
|
186
|
-
235
|
187
|
-
236
|
188
|
-
237
|
189
|
-
238
|
190
|
-
239
|
191
|
-
240
|
192
|
-
241
|
193
|
-
242
|
194
|
-
243
|
195
|
-
244
|
196
|
-
245
|
197
|
-
246
|
198
|
-
247
|
199
|
-
248
|
200
|
-
249
|
201
|
-
250
|
202
|
-
251
|
203
|
-
252
|
204
|
-
253
|
205
|
-
254
|
206
|
-
255
|
207
|
-
338
|
208
|
-
339
|
209
|
-
352
|
210
|
-
353
|
211
|
-
376
|
212
|
-
402
|
213
|
-
710
|
214
|
-
732
|
215
|
-
913
|
216
|
-
914
|
217
|
-
915
|
218
|
-
916
|
219
|
-
917
|
220
|
-
918
|
221
|
-
919
|
222
|
-
920
|
223
|
-
921
|
224
|
-
922
|
225
|
-
923
|
226
|
-
924
|
227
|
-
925
|
228
|
-
926
|
229
|
-
927
|
230
|
-
928
|
231
|
-
929
|
232
|
-
931
|
233
|
-
932
|
234
|
-
933
|
235
|
-
934
|
236
|
-
935
|
237
|
-
936
|
238
|
-
937
|
239
|
-
945
|
240
|
-
946
|
241
|
-
947
|
242
|
-
948
|
243
|
-
949
|
244
|
-
950
|
245
|
-
951
|
246
|
-
952
|
247
|
-
953
|
248
|
-
954
|
249
|
-
955
|
250
|
-
956
|
251
|
-
957
|
252
|
-
958
|
253
|
-
959
|
254
|
-
960
|
255
|
-
961
|
256
|
-
962
|
257
|
-
963
|
258
|
-
964
|
259
|
-
965
|
260
|
-
966
|
261
|
-
967
|
262
|
-
968
|
263
|
-
969
|
264
|
-
977
|
265
|
-
978
|
266
|
-
982
|
107
|
+
34 => "quot", # quotation mark
|
108
|
+
38 => "amp", # ampersand
|
109
|
+
60 => "lt", # less-than sign
|
110
|
+
62 => "gt", # greater-than sign
|
111
|
+
160 => "nbsp", # no-break space
|
112
|
+
161 => "iexcl", # inverted exclamation mark
|
113
|
+
162 => "cent", # cent sign
|
114
|
+
163 => "pound", # pound sign
|
115
|
+
164 => "curren", # currency sign
|
116
|
+
165 => "yen", # yen sign
|
117
|
+
166 => "brvbar", # broken bar
|
118
|
+
167 => "sect", # section sign
|
119
|
+
168 => "uml", # diaeresis
|
120
|
+
169 => "copy", # copyright sign
|
121
|
+
170 => "ordf", # feminine ordinal indicator
|
122
|
+
171 => "laquo", # left-pointing double angle quotation mark
|
123
|
+
172 => "not", # not sign
|
124
|
+
173 => "shy", # soft hyphen
|
125
|
+
174 => "reg", # registered sign
|
126
|
+
175 => "macr", # macron
|
127
|
+
176 => "deg", # degree sign
|
128
|
+
177 => "plusmn", # plus-minus sign
|
129
|
+
178 => "sup2", # superscript two
|
130
|
+
179 => "sup3", # superscript three
|
131
|
+
180 => "acute", # acute accent
|
132
|
+
181 => "micro", # micro sign
|
133
|
+
182 => "para", # pilcrow sign
|
134
|
+
183 => "middot", # middle dot
|
135
|
+
184 => "cedil", # cedilla
|
136
|
+
185 => "sup1", # superscript one
|
137
|
+
186 => "ordm", # masculine ordinal indicator
|
138
|
+
187 => "raquo", # right-pointing double angle quotation mark
|
139
|
+
188 => "frac14", # vulgar fraction one quarter
|
140
|
+
189 => "frac12", # vulgar fraction one half
|
141
|
+
190 => "frac34", # vulgar fraction three quarters
|
142
|
+
191 => "iquest", # inverted question mark
|
143
|
+
192 => "Agrave", # Latin capital letter a with grave
|
144
|
+
193 => "Aacute", # Latin capital letter a with acute
|
145
|
+
194 => "Acirc", # Latin capital letter a with circumflex
|
146
|
+
195 => "Atilde", # Latin capital letter a with tilde
|
147
|
+
196 => "Auml", # Latin capital letter a with diaeresis
|
148
|
+
197 => "Aring", # Latin capital letter a with ring above
|
149
|
+
198 => "AElig", # Latin capital letter ae
|
150
|
+
199 => "Ccedil", # Latin capital letter c with cedilla
|
151
|
+
200 => "Egrave", # Latin capital letter e with grave
|
152
|
+
201 => "Eacute", # Latin capital letter e with acute
|
153
|
+
202 => "Ecirc", # Latin capital letter e with circumflex
|
154
|
+
203 => "Euml", # Latin capital letter e with diaeresis
|
155
|
+
204 => "Igrave", # Latin capital letter i with grave
|
156
|
+
205 => "Iacute", # Latin capital letter i with acute
|
157
|
+
206 => "Icirc", # Latin capital letter i with circumflex
|
158
|
+
207 => "Iuml", # Latin capital letter i with diaeresis
|
159
|
+
208 => "ETH", # Latin capital letter eth
|
160
|
+
209 => "Ntilde", # Latin capital letter n with tilde
|
161
|
+
210 => "Ograve", # Latin capital letter o with grave
|
162
|
+
211 => "Oacute", # Latin capital letter o with acute
|
163
|
+
212 => "Ocirc", # Latin capital letter o with circumflex
|
164
|
+
213 => "Otilde", # Latin capital letter o with tilde
|
165
|
+
214 => "Ouml", # Latin capital letter o with diaeresis
|
166
|
+
215 => "times", # multiplication sign
|
167
|
+
216 => "Oslash", # Latin capital letter o with stroke
|
168
|
+
217 => "Ugrave", # Latin capital letter u with grave
|
169
|
+
218 => "Uacute", # Latin capital letter u with acute
|
170
|
+
219 => "Ucirc", # Latin capital letter u with circumflex
|
171
|
+
220 => "Uuml", # Latin capital letter u with diaeresis
|
172
|
+
221 => "Yacute", # Latin capital letter y with acute
|
173
|
+
222 => "THORN", # Latin capital letter thorn
|
174
|
+
223 => "szlig", # Latin small letter sharp sXCOMMAX German Eszett
|
175
|
+
224 => "agrave", # Latin small letter a with grave
|
176
|
+
225 => "aacute", # Latin small letter a with acute
|
177
|
+
226 => "acirc", # Latin small letter a with circumflex
|
178
|
+
227 => "atilde", # Latin small letter a with tilde
|
179
|
+
228 => "auml", # Latin small letter a with diaeresis
|
180
|
+
229 => "aring", # Latin small letter a with ring above
|
181
|
+
230 => "aelig", # Latin lowercase ligature ae
|
182
|
+
231 => "ccedil", # Latin small letter c with cedilla
|
183
|
+
232 => "egrave", # Latin small letter e with grave
|
184
|
+
233 => "eacute", # Latin small letter e with acute
|
185
|
+
234 => "ecirc", # Latin small letter e with circumflex
|
186
|
+
235 => "euml", # Latin small letter e with diaeresis
|
187
|
+
236 => "igrave", # Latin small letter i with grave
|
188
|
+
237 => "iacute", # Latin small letter i with acute
|
189
|
+
238 => "icirc", # Latin small letter i with circumflex
|
190
|
+
239 => "iuml", # Latin small letter i with diaeresis
|
191
|
+
240 => "eth", # Latin small letter eth
|
192
|
+
241 => "ntilde", # Latin small letter n with tilde
|
193
|
+
242 => "ograve", # Latin small letter o with grave
|
194
|
+
243 => "oacute", # Latin small letter o with acute
|
195
|
+
244 => "ocirc", # Latin small letter o with circumflex
|
196
|
+
245 => "otilde", # Latin small letter o with tilde
|
197
|
+
246 => "ouml", # Latin small letter o with diaeresis
|
198
|
+
247 => "divide", # division sign
|
199
|
+
248 => "oslash", # Latin small letter o with stroke
|
200
|
+
249 => "ugrave", # Latin small letter u with grave
|
201
|
+
250 => "uacute", # Latin small letter u with acute
|
202
|
+
251 => "ucirc", # Latin small letter u with circumflex
|
203
|
+
252 => "uuml", # Latin small letter u with diaeresis
|
204
|
+
253 => "yacute", # Latin small letter y with acute
|
205
|
+
254 => "thorn", # Latin small letter thorn
|
206
|
+
255 => "yuml", # Latin small letter y with diaeresis
|
207
|
+
338 => "OElig", # Latin capital ligature oe
|
208
|
+
339 => "oelig", # Latin small ligature oe
|
209
|
+
352 => "Scaron", # Latin capital letter s with caron
|
210
|
+
353 => "scaron", # Latin small letter s with caron
|
211
|
+
376 => "Yuml", # Latin capital letter y with diaeresis
|
212
|
+
402 => "fnof", # Latin small letter f with hook
|
213
|
+
710 => "circ", # modifier letter circumflex accent
|
214
|
+
732 => "tilde", # small tilde
|
215
|
+
913 => "Alpha", # Greek capital letter alpha
|
216
|
+
914 => "Beta", # Greek capital letter beta
|
217
|
+
915 => "Gamma", # Greek capital letter gamma
|
218
|
+
916 => "Delta", # Greek capital letter delta
|
219
|
+
917 => "Epsilon", # Greek capital letter epsilon
|
220
|
+
918 => "Zeta", # Greek capital letter zeta
|
221
|
+
919 => "Eta", # Greek capital letter eta
|
222
|
+
920 => "Theta", # Greek capital letter theta
|
223
|
+
921 => "Iota", # Greek capital letter iota
|
224
|
+
922 => "Kappa", # Greek capital letter kappa
|
225
|
+
923 => "Lambda", # Greek capital letter lambda
|
226
|
+
924 => "Mu", # Greek capital letter mu
|
227
|
+
925 => "Nu", # Greek capital letter nu
|
228
|
+
926 => "Xi", # Greek capital letter xi
|
229
|
+
927 => "Omicron", # Greek capital letter omicron
|
230
|
+
928 => "Pi", # Greek capital letter pi
|
231
|
+
929 => "Rho", # Greek capital letter rho
|
232
|
+
931 => "Sigma", # Greek capital letter sigma
|
233
|
+
932 => "Tau", # Greek capital letter tau
|
234
|
+
933 => "Upsilon", # Greek capital letter upsilon
|
235
|
+
934 => "Phi", # Greek capital letter phi
|
236
|
+
935 => "Chi", # Greek capital letter chi
|
237
|
+
936 => "Psi", # Greek capital letter psi
|
238
|
+
937 => "Omega", # Greek capital letter omega
|
239
|
+
945 => "alpha", # Greek small letter alpha
|
240
|
+
946 => "beta", # Greek small letter beta
|
241
|
+
947 => "gamma", # Greek small letter gamma
|
242
|
+
948 => "delta", # Greek small letter delta
|
243
|
+
949 => "epsilon", # Greek small letter epsilon
|
244
|
+
950 => "zeta", # Greek small letter zeta
|
245
|
+
951 => "eta", # Greek small letter eta
|
246
|
+
952 => "theta", # Greek small letter theta
|
247
|
+
953 => "iota", # Greek small letter iota
|
248
|
+
954 => "kappa", # Greek small letter kappa
|
249
|
+
955 => "lambda", # Greek small letter lambda
|
250
|
+
956 => "mu", # Greek small letter mu
|
251
|
+
957 => "nu", # Greek small letter nu
|
252
|
+
958 => "xi", # Greek small letter xi
|
253
|
+
959 => "omicron", # Greek small letter omicron
|
254
|
+
960 => "pi", # Greek small letter pi
|
255
|
+
961 => "rho", # Greek small letter rho
|
256
|
+
962 => "sigmaf", # Greek small letter final sigma
|
257
|
+
963 => "sigma", # Greek small letter sigma
|
258
|
+
964 => "tau", # Greek small letter tau
|
259
|
+
965 => "upsilon", # Greek small letter upsilon
|
260
|
+
966 => "phi", # Greek small letter phi
|
261
|
+
967 => "chi", # Greek small letter chi
|
262
|
+
968 => "psi", # Greek small letter psi
|
263
|
+
969 => "omega", # Greek small letter omega
|
264
|
+
977 => "thetasym", # Greek theta symbol
|
265
|
+
978 => "upsih", # Greek upsilon with hook symbol
|
266
|
+
982 => "piv", # Greek pi symbol
|
267
267
|
8194 => "ensp", # en space
|
268
268
|
8195 => "emsp", # em space
|
269
269
|
8201 => "thinsp", # thin space
|
@@ -370,10 +370,8 @@ module Hanami
|
|
370
370
|
#
|
371
371
|
# It's marked with this special class for two reasons:
|
372
372
|
#
|
373
|
-
# * Don't double escape the same string (this is for `Hanami::Helpers`
|
374
|
-
#
|
375
|
-
# * Leave open the possibility to developers to mark a string as safe
|
376
|
-
# with an higher API (eg. `#raw` in `Hanami::View` or `Hanami::Helpers`)
|
373
|
+
# * Don't double escape the same string (this is for `Hanami::Helpers` compatibility)
|
374
|
+
# * Leave open the possibility to developers to mark a string as safe with an higher API (eg. `#raw` in `Hanami::View` or `Hanami::Helpers`)
|
377
375
|
#
|
378
376
|
# @since 0.4.0
|
379
377
|
# @api private
|
@@ -401,7 +399,7 @@ module Hanami
|
|
401
399
|
end
|
402
400
|
end
|
403
401
|
|
404
|
-
#
|
402
|
+
# Escape HTML contents
|
405
403
|
#
|
406
404
|
# This MUST be used only for tag contents.
|
407
405
|
# Please use `html_attribute` for escaping HTML attributes.
|
@@ -434,7 +432,7 @@ module Hanami
|
|
434
432
|
result
|
435
433
|
end
|
436
434
|
|
437
|
-
#
|
435
|
+
# Escape HTML attributes
|
438
436
|
#
|
439
437
|
# This can be used both for HTML attributes and contents.
|
440
438
|
# Please note that this is more computational expensive.
|
@@ -467,7 +465,7 @@ module Hanami
|
|
467
465
|
result
|
468
466
|
end
|
469
467
|
|
470
|
-
#
|
468
|
+
# Escape URL for HTML attributes (href, src, etc..).
|
471
469
|
#
|
472
470
|
# It extracts from the given input the first valid URL that matches the
|
473
471
|
# whitelisted schemes (default: http, https and mailto).
|
@@ -525,7 +523,7 @@ module Hanami
|
|
525
523
|
class << self
|
526
524
|
private
|
527
525
|
|
528
|
-
#
|
526
|
+
# Encode the given string into UTF-8
|
529
527
|
#
|
530
528
|
# @param input [String] the input
|
531
529
|
#
|
@@ -559,7 +557,7 @@ module Hanami
|
|
559
557
|
|
560
558
|
hex = REPLACEMENT_HEX if NON_PRINTABLE_CHARS[code]
|
561
559
|
|
562
|
-
if entity = HTML_ENTITIES[code]
|
560
|
+
if entity = HTML_ENTITIES[code] # rubocop:disable Lint/AssignmentInCondition
|
563
561
|
"&#{entity};"
|
564
562
|
else
|
565
563
|
"&#x#{hex};"
|
@@ -6,7 +6,7 @@ module Hanami
|
|
6
6
|
#
|
7
7
|
# @since 0.9.0
|
8
8
|
module FileList
|
9
|
-
#
|
9
|
+
# Return an ordered list of files, consistent across operating systems
|
10
10
|
#
|
11
11
|
# It has the same signature of <tt>Dir.glob</tt>, it just guarantees to
|
12
12
|
# order the results before to return them.
|
data/lib/hanami/utils/files.rb
CHANGED
@@ -34,24 +34,6 @@ module Hanami
|
|
34
34
|
open(path, ::File::CREAT | ::File::WRONLY | ::File::TRUNC, *content) # rubocop:disable Security/Open - this isn't a call to `::Kernel.open`, but to `self.open`
|
35
35
|
end
|
36
36
|
|
37
|
-
# Rewrites the contents of an existing file.
|
38
|
-
# If the path already exists, it replaces the contents.
|
39
|
-
#
|
40
|
-
# @param path [String,Pathname] the path to file
|
41
|
-
# @param content [String, Array<String>] the content to write
|
42
|
-
#
|
43
|
-
# @raise [Errno::ENOENT] if the path doesn't exist
|
44
|
-
#
|
45
|
-
# @since 1.1.0
|
46
|
-
def self.rewrite(path, *content)
|
47
|
-
Hanami::Utils::Deprecation.new(
|
48
|
-
"`.rewrite' is deprecated, please use `.write'"
|
49
|
-
)
|
50
|
-
raise Errno::ENOENT unless File.exist?(path)
|
51
|
-
|
52
|
-
write(path, *content)
|
53
|
-
end
|
54
|
-
|
55
37
|
# Copies source into destination.
|
56
38
|
# All the intermediate directories are created.
|
57
39
|
# If the destination already exists, it overrides the contents.
|
@@ -165,7 +147,6 @@ module Hanami
|
|
165
147
|
mkdir_p(path)
|
166
148
|
|
167
149
|
content = ::File.readlines(path)
|
168
|
-
content << "\n" if _append_newline?(content)
|
169
150
|
content << "#{contents}\n"
|
170
151
|
|
171
152
|
write(path, content)
|
@@ -326,12 +307,12 @@ module Hanami
|
|
326
307
|
#
|
327
308
|
# # class App
|
328
309
|
# # end
|
329
|
-
def self.remove_block(path, target)
|
310
|
+
def self.remove_block(path, target) # rubocop:disable Metrics/AbcSize
|
330
311
|
content = ::File.readlines(path)
|
331
312
|
starting = index(content, path, target)
|
332
313
|
line = content[starting]
|
333
314
|
size = line[/\A[[:space:]]*/].bytesize
|
334
|
-
closing = (" " * size) + (
|
315
|
+
closing = (" " * size) + (/{/.match?(target) ? "}" : "end")
|
335
316
|
ending = starting + index(content[starting..-1], path, closing)
|
336
317
|
|
337
318
|
content.slice!(starting..ending)
|
@@ -454,16 +435,6 @@ module Hanami
|
|
454
435
|
end
|
455
436
|
|
456
437
|
private_class_method :line_number
|
457
|
-
|
458
|
-
# @since 1.3.6
|
459
|
-
# @api private
|
460
|
-
def self._append_newline?(content)
|
461
|
-
return false if content.empty?
|
462
|
-
|
463
|
-
!content.last.end_with?("\n")
|
464
|
-
end
|
465
|
-
|
466
|
-
private_class_method :_append_newline?
|
467
438
|
end
|
468
439
|
end
|
469
440
|
end
|