hanami-utils 1.3.5 → 2.0.0.alpha2
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 +41 -0
- data/README.md +5 -15
- data/hanami-utils.gemspec +19 -16
- data/lib/hanami-utils.rb +3 -1
- data/lib/hanami/interactor.rb +70 -36
- data/lib/hanami/logger.rb +13 -13
- data/lib/hanami/logger/colorizer.rb +10 -10
- data/lib/hanami/logger/filter.rb +74 -9
- data/lib/hanami/logger/formatter.rb +7 -7
- data/lib/hanami/middleware.rb +11 -0
- data/lib/hanami/utils.rb +12 -26
- data/lib/hanami/utils/basic_object.rb +7 -7
- data/lib/hanami/utils/blank.rb +9 -9
- data/lib/hanami/utils/callbacks.rb +24 -3
- data/lib/hanami/utils/class.rb +3 -56
- data/lib/hanami/utils/class_attribute.rb +23 -12
- data/lib/hanami/utils/class_attribute/attributes.rb +45 -0
- data/lib/hanami/utils/deprecation.rb +3 -1
- data/lib/hanami/utils/escape.rb +275 -271
- data/lib/hanami/utils/file_list.rb +24 -2
- data/lib/hanami/utils/files.rb +16 -22
- data/lib/hanami/utils/hash.rb +24 -363
- data/lib/hanami/utils/io.rb +2 -0
- data/lib/hanami/utils/json.rb +5 -3
- data/lib/hanami/utils/kernel.rb +22 -21
- data/lib/hanami/utils/load_paths.rb +6 -4
- data/lib/hanami/utils/path_prefix.rb +38 -6
- data/lib/hanami/utils/query_string.rb +1 -1
- data/lib/hanami/utils/shell_color.rb +9 -9
- data/lib/hanami/utils/string.rb +44 -470
- data/lib/hanami/utils/version.rb +3 -1
- metadata +30 -16
- data/lib/hanami/utils/duplicable.rb +0 -80
- data/lib/hanami/utils/inflector.rb +0 -494
data/lib/hanami/utils/class.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Hanami
|
4
4
|
module Utils
|
@@ -72,60 +72,8 @@ module Hanami
|
|
72
72
|
load!(name, namespace) if namespace.const_defined?(name.to_s, false)
|
73
73
|
end
|
74
74
|
|
75
|
-
# Loads a class from the given pattern name and namespace
|
76
|
-
#
|
77
|
-
# @param pattern [String] the class name pattern
|
78
|
-
# @param namespace [Class, Module] the Ruby namespace where we want to perform the lookup.
|
79
|
-
# @return [Class, Module] the found Ruby constant.
|
80
|
-
#
|
81
|
-
# @raise [NameError] if no constant can be found.
|
82
|
-
#
|
83
|
-
# @since 0.3.1
|
84
|
-
#
|
85
|
-
# @see Hanami::Utils::String#tokenize
|
86
|
-
#
|
87
|
-
# @example
|
88
|
-
# require 'hanami/utils/class'
|
89
|
-
#
|
90
|
-
# module App
|
91
|
-
# module Service
|
92
|
-
# class Endpoint
|
93
|
-
# end
|
94
|
-
# end
|
95
|
-
#
|
96
|
-
# class ServiceEndpoint
|
97
|
-
# end
|
98
|
-
# end
|
99
|
-
#
|
100
|
-
# # basic usage
|
101
|
-
# Hanami::Utils::Class.load_from_pattern!('App::Service') # => App::Service
|
102
|
-
#
|
103
|
-
# # with explicit namespace
|
104
|
-
# Hanami::Utils::Class.load_from_pattern!('Service', App) # => App::Service
|
105
|
-
#
|
106
|
-
# # with pattern
|
107
|
-
# Hanami::Utils::Class.load_from_pattern!('App::Service(::Endpoint|Endpoint)') # => App::Service::Endpoint
|
108
|
-
# Hanami::Utils::Class.load_from_pattern!('App::Service(Endpoint|::Endpoint)') # => App::ServiceEndpoint
|
109
|
-
#
|
110
|
-
# # with missing constant
|
111
|
-
# Hanami::Utils::Class.load_from_pattern!('Unknown') # => raises NameError
|
112
|
-
def self.load_from_pattern!(pattern, namespace = Object)
|
113
|
-
Deprecation.new('Hanami::Utils::Class.load_from_pattern! is deprecated, please use Hanami::Utils::Class.load! instead')
|
114
|
-
|
115
|
-
tokenize(pattern) do |token|
|
116
|
-
begin
|
117
|
-
return namespace.const_get(token, false)
|
118
|
-
rescue NameError # rubocop:disable Lint/HandleExceptions
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
full_name = [(namespace == Object ? nil : namespace), pattern].compact.join('::')
|
123
|
-
raise NameError.new("uninitialized constant #{full_name}")
|
124
|
-
end
|
125
|
-
|
126
|
-
# rubocop:disable Metrics/MethodLength
|
127
75
|
def self.tokenize(pattern)
|
128
|
-
if match = TOKENIZE_REGEXP.match(pattern)
|
76
|
+
if match = TOKENIZE_REGEXP.match(pattern)
|
129
77
|
pre = match.pre_match
|
130
78
|
post = match.post_match
|
131
79
|
tokens = match[1].split(TOKENIZE_SEPARATOR)
|
@@ -138,7 +86,6 @@ module Hanami
|
|
138
86
|
|
139
87
|
nil
|
140
88
|
end
|
141
|
-
# rubocop:enable Metrics/MethodLength
|
142
89
|
|
143
90
|
# Regexp for .tokenize
|
144
91
|
#
|
@@ -150,7 +97,7 @@ module Hanami
|
|
150
97
|
#
|
151
98
|
# @since 1.3.0
|
152
99
|
# @api private
|
153
|
-
TOKENIZE_SEPARATOR =
|
100
|
+
TOKENIZE_SEPARATOR = "|"
|
154
101
|
end
|
155
102
|
end
|
156
103
|
end
|
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
require 'hanami/utils/duplicable'
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
3
|
module Hanami
|
5
4
|
module Utils
|
@@ -8,6 +7,8 @@ module Hanami
|
|
8
7
|
#
|
9
8
|
# @see Hanami::Utils::ClassAttribute::ClassMethods
|
10
9
|
module ClassAttribute
|
10
|
+
require "hanami/utils/class_attribute/attributes"
|
11
|
+
|
11
12
|
# @api private
|
12
13
|
def self.included(base)
|
13
14
|
base.extend ClassMethods
|
@@ -16,6 +17,12 @@ module Hanami
|
|
16
17
|
# @since 0.1.0
|
17
18
|
# @api private
|
18
19
|
module ClassMethods
|
20
|
+
def self.extended(base)
|
21
|
+
base.class_eval do
|
22
|
+
@__class_attributes = Attributes.new unless defined?(@__class_attributes)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
19
26
|
# Defines a class level accessor for the given attribute(s).
|
20
27
|
#
|
21
28
|
# A value set for a superclass is automatically available by their
|
@@ -66,11 +73,17 @@ module Hanami
|
|
66
73
|
# SmallAirplane.engines # => 2
|
67
74
|
# SmallAirplane.wheels # => 8
|
68
75
|
def class_attribute(*attributes)
|
69
|
-
|
70
|
-
|
71
|
-
|
76
|
+
attributes.each do |attr|
|
77
|
+
singleton_class.class_eval %(
|
78
|
+
def #{attr}
|
79
|
+
class_attributes[:#{attr}]
|
80
|
+
end
|
72
81
|
|
73
|
-
|
82
|
+
def #{attr}=(value)
|
83
|
+
class_attributes[:#{attr}] = value
|
84
|
+
end
|
85
|
+
), __FILE__, __LINE__ - 8
|
86
|
+
end
|
74
87
|
end
|
75
88
|
|
76
89
|
protected
|
@@ -78,11 +91,9 @@ module Hanami
|
|
78
91
|
# @see Class#inherited
|
79
92
|
# @api private
|
80
93
|
def inherited(subclass)
|
81
|
-
class_attributes.
|
82
|
-
|
83
|
-
|
84
|
-
subclass.class_attribute attr
|
85
|
-
subclass.send("#{attr}=", value)
|
94
|
+
ca = class_attributes.dup
|
95
|
+
subclass.class_eval do
|
96
|
+
@__class_attributes = ca
|
86
97
|
end
|
87
98
|
|
88
99
|
super
|
@@ -93,7 +104,7 @@ module Hanami
|
|
93
104
|
# Class accessor for class attributes.
|
94
105
|
# @api private
|
95
106
|
def class_attributes
|
96
|
-
@
|
107
|
+
@__class_attributes
|
97
108
|
end
|
98
109
|
end
|
99
110
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "concurrent/map"
|
4
|
+
|
5
|
+
module Hanami
|
6
|
+
module Utils
|
7
|
+
module ClassAttribute
|
8
|
+
# Class attributes set
|
9
|
+
#
|
10
|
+
# @since 2.0.0
|
11
|
+
# @api private
|
12
|
+
class Attributes
|
13
|
+
# @since 2.0.0
|
14
|
+
# @api private
|
15
|
+
def initialize(attributes: Concurrent::Map.new)
|
16
|
+
@attributes = attributes
|
17
|
+
end
|
18
|
+
|
19
|
+
# @since 2.0.0
|
20
|
+
# @api private
|
21
|
+
def []=(key, value)
|
22
|
+
@attributes[key.to_sym] = value
|
23
|
+
end
|
24
|
+
|
25
|
+
# @since 2.0.0
|
26
|
+
# @api private
|
27
|
+
def [](key)
|
28
|
+
@attributes.fetch(key, nil)
|
29
|
+
end
|
30
|
+
|
31
|
+
# @since 2.0.0
|
32
|
+
# @api private
|
33
|
+
def dup
|
34
|
+
attributes = Concurrent::Map.new.tap do |attrs|
|
35
|
+
@attributes.each do |key, value|
|
36
|
+
attrs[key.to_sym] = value.dup
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
self.class.new(attributes: attributes)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/lib/hanami/utils/escape.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Hanami
|
2
4
|
module Utils
|
3
5
|
# HTML escape utilities
|
@@ -30,14 +32,14 @@ module Hanami
|
|
30
32
|
#
|
31
33
|
# @since 0.4.0
|
32
34
|
# @api private
|
33
|
-
REPLACEMENT_HEX =
|
35
|
+
REPLACEMENT_HEX = "fffd"
|
34
36
|
|
35
37
|
# Low hex codes lookup table
|
36
38
|
#
|
37
39
|
# @since 0.4.0
|
38
40
|
# @api private
|
39
41
|
HEX_CODES = (0..255).each_with_object({}) do |c, codes|
|
40
|
-
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)
|
41
43
|
codes[c] = nil
|
42
44
|
else
|
43
45
|
codes[c] = c.to_s(HEX_BASE)
|
@@ -53,8 +55,8 @@ module Hanami
|
|
53
55
|
#
|
54
56
|
# @see https://gist.github.com/jodosha/ac5dd54416de744b9600
|
55
57
|
NON_PRINTABLE_CHARS = {
|
56
|
-
0x0
|
57
|
-
0x5
|
58
|
+
0x0 => true, 0x1 => true, 0x2 => true, 0x3 => true, 0x4 => true,
|
59
|
+
0x5 => true, 0x6 => true, 0x7 => true, 0x8 => true, 0x11 => true,
|
58
60
|
0x12 => true, 0x14 => true, 0x15 => true, 0x16 => true, 0x17 => true,
|
59
61
|
0x18 => true, 0x19 => true, 0x1a => true, 0x1b => true, 0x1c => true,
|
60
62
|
0x1d => true, 0x1e => true, 0x1f => true, 0x7f => true, 0x80 => true,
|
@@ -74,12 +76,12 @@ module Hanami
|
|
74
76
|
#
|
75
77
|
# @see Hanami::Utils::Escape.html
|
76
78
|
HTML_CHARS = {
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
'"' =>
|
81
|
-
"'" =>
|
82
|
-
|
79
|
+
"&" => "&",
|
80
|
+
"<" => "<",
|
81
|
+
">" => ">",
|
82
|
+
'"' => """,
|
83
|
+
"'" => "'",
|
84
|
+
"/" => "/"
|
83
85
|
}.freeze
|
84
86
|
|
85
87
|
# Lookup table for safe chars for HTML attributes.
|
@@ -92,7 +94,7 @@ module Hanami
|
|
92
94
|
# @see Lookup::Utils::Escape.html_attribute
|
93
95
|
# @see https://gist.github.com/jodosha/ac5dd54416de744b9600
|
94
96
|
HTML_ATTRIBUTE_SAFE_CHARS = {
|
95
|
-
|
97
|
+
"," => true, "." => true, "-" => true, "_" => true
|
96
98
|
}.freeze
|
97
99
|
|
98
100
|
# Lookup table for HTML attribute escape
|
@@ -102,258 +104,258 @@ module Hanami
|
|
102
104
|
#
|
103
105
|
# @see Hanami::Utils::Escape.html_attribute
|
104
106
|
HTML_ENTITIES = {
|
105
|
-
34
|
106
|
-
38
|
107
|
-
60
|
108
|
-
62
|
109
|
-
160
|
110
|
-
161
|
111
|
-
162
|
112
|
-
163
|
113
|
-
164
|
114
|
-
165
|
115
|
-
166
|
116
|
-
167
|
117
|
-
168
|
118
|
-
169
|
119
|
-
170
|
120
|
-
171
|
121
|
-
172
|
122
|
-
173
|
123
|
-
174
|
124
|
-
175
|
125
|
-
176
|
126
|
-
177
|
127
|
-
178
|
128
|
-
179
|
129
|
-
180
|
130
|
-
181
|
131
|
-
182
|
132
|
-
183
|
133
|
-
184
|
134
|
-
185
|
135
|
-
186
|
136
|
-
187
|
137
|
-
188
|
138
|
-
189
|
139
|
-
190
|
140
|
-
191
|
141
|
-
192
|
142
|
-
193
|
143
|
-
194
|
144
|
-
195
|
145
|
-
196
|
146
|
-
197
|
147
|
-
198
|
148
|
-
199
|
149
|
-
200
|
150
|
-
201
|
151
|
-
202
|
152
|
-
203
|
153
|
-
204
|
154
|
-
205
|
155
|
-
206
|
156
|
-
207
|
157
|
-
208
|
158
|
-
209
|
159
|
-
210
|
160
|
-
211
|
161
|
-
212
|
162
|
-
213
|
163
|
-
214
|
164
|
-
215
|
165
|
-
216
|
166
|
-
217
|
167
|
-
218
|
168
|
-
219
|
169
|
-
220
|
170
|
-
221
|
171
|
-
222
|
172
|
-
223
|
173
|
-
224
|
174
|
-
225
|
175
|
-
226
|
176
|
-
227
|
177
|
-
228
|
178
|
-
229
|
179
|
-
230
|
180
|
-
231
|
181
|
-
232
|
182
|
-
233
|
183
|
-
234
|
184
|
-
235
|
185
|
-
236
|
186
|
-
237
|
187
|
-
238
|
188
|
-
239
|
189
|
-
240
|
190
|
-
241
|
191
|
-
242
|
192
|
-
243
|
193
|
-
244
|
194
|
-
245
|
195
|
-
246
|
196
|
-
247
|
197
|
-
248
|
198
|
-
249
|
199
|
-
250
|
200
|
-
251
|
201
|
-
252
|
202
|
-
253
|
203
|
-
254
|
204
|
-
255
|
205
|
-
338
|
206
|
-
339
|
207
|
-
352
|
208
|
-
353
|
209
|
-
376
|
210
|
-
402
|
211
|
-
710
|
212
|
-
732
|
213
|
-
913
|
214
|
-
914
|
215
|
-
915
|
216
|
-
916
|
217
|
-
917
|
218
|
-
918
|
219
|
-
919
|
220
|
-
920
|
221
|
-
921
|
222
|
-
922
|
223
|
-
923
|
224
|
-
924
|
225
|
-
925
|
226
|
-
926
|
227
|
-
927
|
228
|
-
928
|
229
|
-
929
|
230
|
-
931
|
231
|
-
932
|
232
|
-
933
|
233
|
-
934
|
234
|
-
935
|
235
|
-
936
|
236
|
-
937
|
237
|
-
945
|
238
|
-
946
|
239
|
-
947
|
240
|
-
948
|
241
|
-
949
|
242
|
-
950
|
243
|
-
951
|
244
|
-
952
|
245
|
-
953
|
246
|
-
954
|
247
|
-
955
|
248
|
-
956
|
249
|
-
957
|
250
|
-
958
|
251
|
-
959
|
252
|
-
960
|
253
|
-
961
|
254
|
-
962
|
255
|
-
963
|
256
|
-
964
|
257
|
-
965
|
258
|
-
966
|
259
|
-
967
|
260
|
-
968
|
261
|
-
969
|
262
|
-
977
|
263
|
-
978
|
264
|
-
982
|
265
|
-
8194 =>
|
266
|
-
8195 =>
|
267
|
-
8201 =>
|
268
|
-
8204 =>
|
269
|
-
8205 =>
|
270
|
-
8206 =>
|
271
|
-
8207 =>
|
272
|
-
8211 =>
|
273
|
-
8212 =>
|
274
|
-
8216 =>
|
275
|
-
8217 =>
|
276
|
-
8218 =>
|
277
|
-
8220 =>
|
278
|
-
8221 =>
|
279
|
-
8222 =>
|
280
|
-
8224 =>
|
281
|
-
8225 =>
|
282
|
-
8226 =>
|
283
|
-
8230 =>
|
284
|
-
8240 =>
|
285
|
-
8242 =>
|
286
|
-
8243 =>
|
287
|
-
8249 =>
|
288
|
-
8250 =>
|
289
|
-
8254 =>
|
290
|
-
8260 =>
|
291
|
-
8364 =>
|
292
|
-
8465 =>
|
293
|
-
8472 =>
|
294
|
-
8476 =>
|
295
|
-
8482 =>
|
296
|
-
8501 =>
|
297
|
-
8592 =>
|
298
|
-
8593 =>
|
299
|
-
8594 =>
|
300
|
-
8595 =>
|
301
|
-
8596 =>
|
302
|
-
8629 =>
|
303
|
-
8656 =>
|
304
|
-
8657 =>
|
305
|
-
8658 =>
|
306
|
-
8659 =>
|
307
|
-
8660 =>
|
308
|
-
8704 =>
|
309
|
-
8706 =>
|
310
|
-
8707 =>
|
311
|
-
8709 =>
|
312
|
-
8711 =>
|
313
|
-
8712 =>
|
314
|
-
8713 =>
|
315
|
-
8715 =>
|
316
|
-
8719 =>
|
317
|
-
8721 =>
|
318
|
-
8722 =>
|
319
|
-
8727 =>
|
320
|
-
8730 =>
|
321
|
-
8733 =>
|
322
|
-
8734 =>
|
323
|
-
8736 =>
|
324
|
-
8743 =>
|
325
|
-
8744 =>
|
326
|
-
8745 =>
|
327
|
-
8746 =>
|
328
|
-
8747 =>
|
329
|
-
8756 =>
|
330
|
-
8764 =>
|
331
|
-
8773 =>
|
332
|
-
8776 =>
|
333
|
-
8800 =>
|
334
|
-
8801 =>
|
335
|
-
8804 =>
|
336
|
-
8805 =>
|
337
|
-
8834 =>
|
338
|
-
8835 =>
|
339
|
-
8836 =>
|
340
|
-
8838 =>
|
341
|
-
8839 =>
|
342
|
-
8853 =>
|
343
|
-
8855 =>
|
344
|
-
8869 =>
|
345
|
-
8901 =>
|
346
|
-
8968 =>
|
347
|
-
8969 =>
|
348
|
-
8970 =>
|
349
|
-
8971 =>
|
350
|
-
9001 =>
|
351
|
-
9002 =>
|
352
|
-
9674 =>
|
353
|
-
9824 =>
|
354
|
-
9827 =>
|
355
|
-
9829 =>
|
356
|
-
9830 =>
|
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
|
+
8194 => "ensp", # en space
|
268
|
+
8195 => "emsp", # em space
|
269
|
+
8201 => "thinsp", # thin space
|
270
|
+
8204 => "zwnj", # zero width non-joiner
|
271
|
+
8205 => "zwj", # zero width joiner
|
272
|
+
8206 => "lrm", # left-to-right mark
|
273
|
+
8207 => "rlm", # right-to-left mark
|
274
|
+
8211 => "ndash", # en dash
|
275
|
+
8212 => "mdash", # em dash
|
276
|
+
8216 => "lsquo", # left single quotation mark
|
277
|
+
8217 => "rsquo", # right single quotation mark
|
278
|
+
8218 => "sbquo", # single low-9 quotation mark
|
279
|
+
8220 => "ldquo", # left double quotation mark
|
280
|
+
8221 => "rdquo", # right double quotation mark
|
281
|
+
8222 => "bdquo", # double low-9 quotation mark
|
282
|
+
8224 => "dagger", # dagger
|
283
|
+
8225 => "Dagger", # double dagger
|
284
|
+
8226 => "bull", # bullet
|
285
|
+
8230 => "hellip", # horizontal ellipsis
|
286
|
+
8240 => "permil", # per mille sign
|
287
|
+
8242 => "prime", # prime
|
288
|
+
8243 => "Prime", # double prime
|
289
|
+
8249 => "lsaquo", # single left-pointing angle quotation mark
|
290
|
+
8250 => "rsaquo", # single right-pointing angle quotation mark
|
291
|
+
8254 => "oline", # overline
|
292
|
+
8260 => "frasl", # fraction slash
|
293
|
+
8364 => "euro", # euro sign
|
294
|
+
8465 => "image", # black-letter capital i
|
295
|
+
8472 => "weierp", # script capital pXCOMMAX Weierstrass p
|
296
|
+
8476 => "real", # black-letter capital r
|
297
|
+
8482 => "trade", # trademark sign
|
298
|
+
8501 => "alefsym", # alef symbol
|
299
|
+
8592 => "larr", # leftwards arrow
|
300
|
+
8593 => "uarr", # upwards arrow
|
301
|
+
8594 => "rarr", # rightwards arrow
|
302
|
+
8595 => "darr", # downwards arrow
|
303
|
+
8596 => "harr", # left right arrow
|
304
|
+
8629 => "crarr", # downwards arrow with corner leftwards
|
305
|
+
8656 => "lArr", # leftwards double arrow
|
306
|
+
8657 => "uArr", # upwards double arrow
|
307
|
+
8658 => "rArr", # rightwards double arrow
|
308
|
+
8659 => "dArr", # downwards double arrow
|
309
|
+
8660 => "hArr", # left right double arrow
|
310
|
+
8704 => "forall", # for all
|
311
|
+
8706 => "part", # partial differential
|
312
|
+
8707 => "exist", # there exists
|
313
|
+
8709 => "empty", # empty set
|
314
|
+
8711 => "nabla", # nabla
|
315
|
+
8712 => "isin", # element of
|
316
|
+
8713 => "notin", # not an element of
|
317
|
+
8715 => "ni", # contains as member
|
318
|
+
8719 => "prod", # n-ary product
|
319
|
+
8721 => "sum", # n-ary summation
|
320
|
+
8722 => "minus", # minus sign
|
321
|
+
8727 => "lowast", # asterisk operator
|
322
|
+
8730 => "radic", # square root
|
323
|
+
8733 => "prop", # proportional to
|
324
|
+
8734 => "infin", # infinity
|
325
|
+
8736 => "ang", # angle
|
326
|
+
8743 => "and", # logical and
|
327
|
+
8744 => "or", # logical or
|
328
|
+
8745 => "cap", # intersection
|
329
|
+
8746 => "cup", # union
|
330
|
+
8747 => "int", # integral
|
331
|
+
8756 => "there4", # therefore
|
332
|
+
8764 => "sim", # tilde operator
|
333
|
+
8773 => "cong", # congruent to
|
334
|
+
8776 => "asymp", # almost equal to
|
335
|
+
8800 => "ne", # not equal to
|
336
|
+
8801 => "equiv", # identical toXCOMMAX equivalent to
|
337
|
+
8804 => "le", # less-than or equal to
|
338
|
+
8805 => "ge", # greater-than or equal to
|
339
|
+
8834 => "sub", # subset of
|
340
|
+
8835 => "sup", # superset of
|
341
|
+
8836 => "nsub", # not a subset of
|
342
|
+
8838 => "sube", # subset of or equal to
|
343
|
+
8839 => "supe", # superset of or equal to
|
344
|
+
8853 => "oplus", # circled plus
|
345
|
+
8855 => "otimes", # circled times
|
346
|
+
8869 => "perp", # up tack
|
347
|
+
8901 => "sdot", # dot operator
|
348
|
+
8968 => "lceil", # left ceiling
|
349
|
+
8969 => "rceil", # right ceiling
|
350
|
+
8970 => "lfloor", # left floor
|
351
|
+
8971 => "rfloor", # right floor
|
352
|
+
9001 => "lang", # left-pointing angle bracket
|
353
|
+
9002 => "rang", # right-pointing angle bracket
|
354
|
+
9674 => "loz", # lozenge
|
355
|
+
9824 => "spades", # black spade suit
|
356
|
+
9827 => "clubs", # black club suit
|
357
|
+
9829 => "hearts", # black heart suit
|
358
|
+
9830 => "diams" # black diamond suit
|
357
359
|
}.freeze
|
358
360
|
|
359
361
|
# Allowed URL schemes
|
@@ -368,8 +370,10 @@ module Hanami
|
|
368
370
|
#
|
369
371
|
# It's marked with this special class for two reasons:
|
370
372
|
#
|
371
|
-
# * Don't double escape the same string (this is for `Hanami::Helpers`
|
372
|
-
#
|
373
|
+
# * Don't double escape the same string (this is for `Hanami::Helpers`
|
374
|
+
# compatibility)
|
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
377
|
#
|
374
378
|
# @since 0.4.0
|
375
379
|
# @api private
|
@@ -397,7 +401,7 @@ module Hanami
|
|
397
401
|
end
|
398
402
|
end
|
399
403
|
|
400
|
-
#
|
404
|
+
# Escapes HTML contents
|
401
405
|
#
|
402
406
|
# This MUST be used only for tag contents.
|
403
407
|
# Please use `html_attribute` for escaping HTML attributes.
|
@@ -430,7 +434,7 @@ module Hanami
|
|
430
434
|
result
|
431
435
|
end
|
432
436
|
|
433
|
-
#
|
437
|
+
# Escapes HTML attributes
|
434
438
|
#
|
435
439
|
# This can be used both for HTML attributes and contents.
|
436
440
|
# Please note that this is more computational expensive.
|
@@ -463,7 +467,7 @@ module Hanami
|
|
463
467
|
result
|
464
468
|
end
|
465
469
|
|
466
|
-
#
|
470
|
+
# Escapes URL for HTML attributes (href, src, etc..).
|
467
471
|
#
|
468
472
|
# It extracts from the given input the first valid URL that matches the
|
469
473
|
# whitelisted schemes (default: http, https and mailto).
|
@@ -521,7 +525,7 @@ module Hanami
|
|
521
525
|
class << self
|
522
526
|
private
|
523
527
|
|
524
|
-
#
|
528
|
+
# Encodes the given string into UTF-8
|
525
529
|
#
|
526
530
|
# @param input [String] the input
|
527
531
|
#
|
@@ -530,7 +534,7 @@ module Hanami
|
|
530
534
|
# @since 0.4.0
|
531
535
|
# @api private
|
532
536
|
def encode(input)
|
533
|
-
return
|
537
|
+
return "" if input.nil?
|
534
538
|
|
535
539
|
input.to_s.encode(Encoding::UTF_8)
|
536
540
|
rescue Encoding::UndefinedConversionError
|
@@ -555,7 +559,7 @@ module Hanami
|
|
555
559
|
|
556
560
|
hex = REPLACEMENT_HEX if NON_PRINTABLE_CHARS[code]
|
557
561
|
|
558
|
-
if entity = HTML_ENTITIES[code]
|
562
|
+
if entity = HTML_ENTITIES[code]
|
559
563
|
"&#{entity};"
|
560
564
|
else
|
561
565
|
"&#x#{hex};"
|