hanami-utils 1.3.8 → 2.0.0.alpha1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,8 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "set"
4
- require "hanami/utils/duplicable"
5
-
6
3
  module Hanami
7
4
  module Utils
8
5
  # Inheritable class level variable accessors.
@@ -10,6 +7,8 @@ module Hanami
10
7
  #
11
8
  # @see Hanami::Utils::ClassAttribute::ClassMethods
12
9
  module ClassAttribute
10
+ require "hanami/utils/class_attribute/attributes"
11
+
13
12
  # @api private
14
13
  def self.included(base)
15
14
  base.extend ClassMethods
@@ -18,6 +17,12 @@ module Hanami
18
17
  # @since 0.1.0
19
18
  # @api private
20
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
+
21
26
  # Defines a class level accessor for the given attribute(s).
22
27
  #
23
28
  # A value set for a superclass is automatically available by their
@@ -68,11 +73,17 @@ module Hanami
68
73
  # SmallAirplane.engines # => 2
69
74
  # SmallAirplane.wheels # => 8
70
75
  def class_attribute(*attributes)
71
- singleton_class.class_eval do
72
- attr_accessor(*attributes)
73
- end
76
+ attributes.each do |attr|
77
+ singleton_class.class_eval %(
78
+ def #{attr}
79
+ class_attributes[:#{attr}]
80
+ end
74
81
 
75
- class_attributes.merge(attributes)
82
+ def #{attr}=(value)
83
+ class_attributes[:#{attr}] = value
84
+ end
85
+ ), __FILE__, __LINE__ - 8
86
+ end
76
87
  end
77
88
 
78
89
  protected
@@ -80,11 +91,9 @@ module Hanami
80
91
  # @see Class#inherited
81
92
  # @api private
82
93
  def inherited(subclass)
83
- class_attributes.each do |attr|
84
- value = send(attr)
85
- value = Duplicable.dup(value)
86
- subclass.class_attribute attr
87
- subclass.send("#{attr}=", value)
94
+ ca = class_attributes.dup
95
+ subclass.class_eval do
96
+ @__class_attributes = ca
88
97
  end
89
98
 
90
99
  super
@@ -95,7 +104,7 @@ module Hanami
95
104
  # Class accessor for class attributes.
96
105
  # @api private
97
106
  def class_attributes
98
- @class_attributes ||= Set.new
107
+ @__class_attributes
99
108
  end
100
109
  end
101
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
@@ -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 => true, 0x1 => true, 0x2 => true, 0x3 => true, 0x4 => true,
59
- 0x5 => true, 0x6 => true, 0x7 => true, 0x8 => true, 0x11 => true,
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 => "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
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
- # 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
+ # * 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
- # Escapes HTML contents
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
- # Escapes HTML attributes
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
- # Escapes URL for HTML attributes (href, src, etc..).
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
- # Encodes the given string into UTF-8
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};"