hanami-utils 1.3.2 → 1.3.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -103,15 +103,15 @@ module Hanami
103
103
 
104
104
  # @since 0.8.0
105
105
  # @api private
106
- def _message_hash(message) # rubocop:disable Metrics/MethodLength
106
+ def _message_hash(message)
107
107
  case message
108
108
  when Hash
109
109
  @filter.call(message)
110
110
  when Exception
111
111
  Hash[
112
- message: message.message,
112
+ message: message.message,
113
113
  backtrace: message.backtrace || [],
114
- error: message.class
114
+ error: message.class
115
115
  ]
116
116
  else
117
117
  Hash[message: message]
@@ -121,7 +121,7 @@ module Hanami
121
121
  # @since 0.8.0
122
122
  # @api private
123
123
  def _format(hash)
124
- "#{_line_front_matter(hash.delete(:app), hash.delete(:severity), hash.delete(:time))}#{SEPARATOR}#{_format_message(hash)}"
124
+ "#{_line_front_matter(hash.delete(:app), hash.delete(:severity), hash.delete(:time))}#{SEPARATOR}#{_format_message(hash)}" # rubocop:disable Layout/LineLength
125
125
  end
126
126
 
127
127
  # @since 1.2.0
@@ -1,11 +1,13 @@
1
- require 'pathname'
1
+ # frozen_string_literal: true
2
+
3
+ require "pathname"
2
4
 
3
5
  # Hanami - The web, with simplicity
4
6
  #
5
7
  # @since 0.1.0
6
8
  module Hanami
7
- require 'hanami/utils/version'
8
- require 'hanami/utils/file_list'
9
+ require "hanami/utils/version"
10
+ require "hanami/utils/file_list"
9
11
 
10
12
  # Ruby core extentions and Hanami utilities
11
13
  #
@@ -13,15 +15,15 @@ module Hanami
13
15
  module Utils
14
16
  # @since 0.3.1
15
17
  # @api private
16
- HANAMI_JRUBY = 'java'.freeze
18
+ HANAMI_JRUBY = "java"
17
19
 
18
20
  # @since 0.3.1
19
21
  # @api private
20
- HANAMI_RUBINIUS = 'rbx'.freeze
22
+ HANAMI_RUBINIUS = "rbx"
21
23
 
22
24
  # Checks if the current VM is JRuby
23
25
  #
24
- # @return [TrueClass,FalseClass] return if the VM is JRuby or not
26
+ # @return [TrueClass,FalseClass] info whether the VM is JRuby or not
25
27
  #
26
28
  # @since 0.3.1
27
29
  # @api private
@@ -31,7 +33,7 @@ module Hanami
31
33
 
32
34
  # Checks if the current VM is Rubinius
33
35
  #
34
- # @return [TrueClass,FalseClass] return if the VM is Rubinius or not
36
+ # @return [TrueClass,FalseClass] info whether the VM is Rubinius or not
35
37
  #
36
38
  # @since 0.3.1
37
39
  # @api private
@@ -39,7 +41,7 @@ module Hanami
39
41
  RUBY_ENGINE == HANAMI_RUBINIUS
40
42
  end
41
43
 
42
- # Recursively require Ruby files under the given directory.
44
+ # Recursively requires Ruby files under the given directory.
43
45
  #
44
46
  # If the directory is relative, it implies it's the path from current directory.
45
47
  # If the directory is absolute, it uses as it is.
@@ -54,7 +56,7 @@ module Hanami
54
56
  for_each_file_in(directory) { |file| require_relative(file) }
55
57
  end
56
58
 
57
- # Recursively reload Ruby files under the given directory.
59
+ # Recursively reloads Ruby files under the given directory.
58
60
  #
59
61
  # If the directory is relative, it implies it's the path from current directory.
60
62
  # If the directory is absolute, it uses as it is.
@@ -87,7 +89,7 @@ module Hanami
87
89
  def self.for_each_file_in(directory, &blk)
88
90
  directory = directory.to_s.gsub(%r{(\/|\\)}, File::SEPARATOR)
89
91
  directory = Pathname.new(Dir.pwd).join(directory).to_s
90
- directory = File.join(directory, '**', '*.rb') unless directory =~ /(\*\*)/
92
+ directory = File.join(directory, "**", "*.rb") unless directory =~ /(\*\*)/
91
93
 
92
94
  FileList[directory].each(&blk)
93
95
  end
@@ -1,10 +1,29 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Hanami
2
4
  module Utils
3
5
  # BasicObject
4
6
  #
5
7
  # @since 0.3.5
6
8
  class BasicObject < ::BasicObject
7
- # Return the class for debugging purposes.
9
+ # Lookups constants at the top-level namespace, if they are missing in the
10
+ # current context.
11
+ #
12
+ # @param name [Symbol] the constant name
13
+ #
14
+ # @return [Object, Module] the constant
15
+ #
16
+ # @raise [NameError] if the constant cannot be found
17
+ #
18
+ # @since 1.3.4
19
+ # @api private
20
+ #
21
+ # @see https://ruby-doc.org/core/Module.html#method-i-const_missing
22
+ def self.const_missing(name)
23
+ ::Object.const_get(name)
24
+ end
25
+
26
+ # Returns the class for debugging purposes.
8
27
  #
9
28
  # @since 0.3.5
10
29
  #
@@ -21,17 +40,15 @@ module Hanami
21
40
  #
22
41
  # @see http://ruby-doc.org/core/Object.html#method-i-inspect
23
42
  #
24
- # rubocop:disable Style/FormatString
25
43
  # rubocop:disable Style/FormatStringToken
26
44
  def inspect
27
45
  "#<#{self.class}:#{'0x0000%x' % (__id__ << 1)}#{__inspect}>"
28
46
  end
29
47
  # rubocop:enable Style/FormatStringToken
30
- # rubocop:enable Style/FormatString
31
48
 
32
49
  # @!macro [attach] instance_of?(class)
33
50
  #
34
- # Determine if self is an instance of given class or module
51
+ # Determines if self is an instance of given class or module
35
52
  #
36
53
  # @param class [Class,Module] the class of module to verify
37
54
  #
@@ -46,7 +63,7 @@ module Hanami
46
63
 
47
64
  # @!macro [attach] is_a?(class)
48
65
  #
49
- # Determine if self is of the type of the object class or module
66
+ # Determines if self is of the type of the object class or module
50
67
  #
51
68
  # @param class [Class,Module] the class of module to verify
52
69
  #
@@ -61,7 +78,7 @@ module Hanami
61
78
 
62
79
  # @!macro [attach] kind_of?(class)
63
80
  #
64
- # Determine if self is of the kind of the object class or module
81
+ # Determines if self is of the kind of the object class or module
65
82
  #
66
83
  # @param class [Class,Module] the class of module to verify
67
84
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Hanami
2
4
  module Utils
3
5
  # Checks for blank
@@ -11,7 +13,7 @@ module Hanami
11
13
  # @api private
12
14
  STRING_MATCHER = /\A[[:space:]]*\z/.freeze
13
15
 
14
- # Checks object is blank
16
+ # Checks if object is blank
15
17
  #
16
18
  # @example Basic Usage
17
19
  # require 'hanami/utils/blank'
@@ -25,11 +27,11 @@ module Hanami
25
27
  #
26
28
  # @param object the argument
27
29
  #
28
- # @return [TrueClass,FalseClass]
30
+ # @return [TrueClass,FalseClass] info, whether object is blank
29
31
  #
30
32
  # @since 0.8.0
31
33
  # @api private
32
- def self.blank?(object) # rubocop:disable Metrics/MethodLength
34
+ def self.blank?(object)
33
35
  case object
34
36
  when String, ::String
35
37
  STRING_MATCHER === object # rubocop:disable Style/CaseEquality
@@ -44,7 +46,7 @@ module Hanami
44
46
  end
45
47
  end
46
48
 
47
- # Checks object is filled
49
+ # Checks if object is filled
48
50
  #
49
51
  # @example Basic Usage
50
52
  # require 'hanami/utils/blank'
@@ -58,7 +60,7 @@ module Hanami
58
60
  #
59
61
  # @param object the argument
60
62
  #
61
- # @return [TrueClass,FalseClass]
63
+ # @return [TrueClass,FalseClass] whether the object is filled
62
64
  #
63
65
  # @since 1.0.0
64
66
  # @api private
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Hanami
2
4
  module Utils
3
5
  # Before and After callbacks
@@ -10,7 +12,7 @@ module Hanami
10
12
  # @since 0.1.0
11
13
  # @private
12
14
  class Chain
13
- # Return a new chain
15
+ # Returns a new chain
14
16
  #
15
17
  # @return [Hanami::Utils::Callbacks::Chain]
16
18
  #
@@ -248,7 +250,9 @@ module Hanami
248
250
  end
249
251
 
250
252
  # Method callback
251
- # It wraps a symbol or a string representing a method name that is implemented by the context within it will be called.
253
+ #
254
+ # It wraps a symbol or a string representing a method name that is
255
+ # implemented by the context within it will be called.
252
256
  #
253
257
  # @since 0.1.0
254
258
  # @api private
@@ -1,4 +1,6 @@
1
- require 'hanami/utils/deprecation'
1
+ # frozen_string_literal: true
2
+
3
+ require "hanami/utils/deprecation"
2
4
 
3
5
  module Hanami
4
6
  module Utils
@@ -110,22 +112,21 @@ module Hanami
110
112
  # # with missing constant
111
113
  # Hanami::Utils::Class.load_from_pattern!('Unknown') # => raises NameError
112
114
  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')
115
+ Deprecation.new("Hanami::Utils::Class.load_from_pattern! is deprecated, please use Hanami::Utils::Class.load! instead") # rubocop:disable Layout/LineLength
114
116
 
115
117
  tokenize(pattern) do |token|
116
118
  begin
117
119
  return namespace.const_get(token, false)
118
- rescue NameError # rubocop:disable Lint/HandleExceptions
120
+ rescue NameError # rubocop:disable Lint/SuppressedException
119
121
  end
120
122
  end
121
123
 
122
- full_name = [(namespace == Object ? nil : namespace), pattern].compact.join('::')
124
+ full_name = [(namespace == Object ? nil : namespace), pattern].compact.join("::")
123
125
  raise NameError.new("uninitialized constant #{full_name}")
124
126
  end
125
127
 
126
- # rubocop:disable Metrics/MethodLength
127
128
  def self.tokenize(pattern)
128
- if match = TOKENIZE_REGEXP.match(pattern) # rubocop:disable Lint/AssignmentInCondition
129
+ if match = TOKENIZE_REGEXP.match(pattern)
129
130
  pre = match.pre_match
130
131
  post = match.post_match
131
132
  tokens = match[1].split(TOKENIZE_SEPARATOR)
@@ -138,7 +139,6 @@ module Hanami
138
139
 
139
140
  nil
140
141
  end
141
- # rubocop:enable Metrics/MethodLength
142
142
 
143
143
  # Regexp for .tokenize
144
144
  #
@@ -150,7 +150,7 @@ module Hanami
150
150
  #
151
151
  # @since 1.3.0
152
152
  # @api private
153
- TOKENIZE_SEPARATOR = '|'.freeze
153
+ TOKENIZE_SEPARATOR = "|"
154
154
  end
155
155
  end
156
156
  end
@@ -1,5 +1,7 @@
1
- require 'set'
2
- require 'hanami/utils/duplicable'
1
+ # frozen_string_literal: true
2
+
3
+ require "set"
4
+ require "hanami/utils/duplicable"
3
5
 
4
6
  module Hanami
5
7
  module Utils
@@ -1,4 +1,6 @@
1
- require 'hanami/utils'
1
+ # frozen_string_literal: true
2
+
3
+ require "hanami/utils"
2
4
 
3
5
  module Hanami
4
6
  module Utils
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Hanami
2
4
  module Utils
3
5
  # Safe dup logic
@@ -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 = 'fffd'.freeze
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) # rubocop:disable Style/ConditionalAssignment
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 => true, 0x1 => true, 0x2 => true, 0x3 => true, 0x4 => true,
57
- 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,
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
- '&' => '&amp;',
78
- '<' => '&lt;',
79
- '>' => '&gt;',
80
- '"' => '&quot;',
81
- "'" => '&apos;',
82
- '/' => '&#x2F;'
79
+ "&" => "&amp;",
80
+ "<" => "&lt;",
81
+ ">" => "&gt;",
82
+ '"' => "&quot;",
83
+ "'" => "&apos;",
84
+ "/" => "&#x2F;"
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
- ',' => true, '.' => true, '-' => true, '_' => true
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 => 'quot', # quotation mark
106
- 38 => 'amp', # ampersand
107
- 60 => 'lt', # less-than sign
108
- 62 => 'gt', # greater-than sign
109
- 160 => 'nbsp', # no-break space
110
- 161 => 'iexcl', # inverted exclamation mark
111
- 162 => 'cent', # cent sign
112
- 163 => 'pound', # pound sign
113
- 164 => 'curren', # currency sign
114
- 165 => 'yen', # yen sign
115
- 166 => 'brvbar', # broken bar
116
- 167 => 'sect', # section sign
117
- 168 => 'uml', # diaeresis
118
- 169 => 'copy', # copyright sign
119
- 170 => 'ordf', # feminine ordinal indicator
120
- 171 => 'laquo', # left-pointing double angle quotation mark
121
- 172 => 'not', # not sign
122
- 173 => 'shy', # soft hyphen
123
- 174 => 'reg', # registered sign
124
- 175 => 'macr', # macron
125
- 176 => 'deg', # degree sign
126
- 177 => 'plusmn', # plus-minus sign
127
- 178 => 'sup2', # superscript two
128
- 179 => 'sup3', # superscript three
129
- 180 => 'acute', # acute accent
130
- 181 => 'micro', # micro sign
131
- 182 => 'para', # pilcrow sign
132
- 183 => 'middot', # middle dot
133
- 184 => 'cedil', # cedilla
134
- 185 => 'sup1', # superscript one
135
- 186 => 'ordm', # masculine ordinal indicator
136
- 187 => 'raquo', # right-pointing double angle quotation mark
137
- 188 => 'frac14', # vulgar fraction one quarter
138
- 189 => 'frac12', # vulgar fraction one half
139
- 190 => 'frac34', # vulgar fraction three quarters
140
- 191 => 'iquest', # inverted question mark
141
- 192 => 'Agrave', # Latin capital letter a with grave
142
- 193 => 'Aacute', # Latin capital letter a with acute
143
- 194 => 'Acirc', # Latin capital letter a with circumflex
144
- 195 => 'Atilde', # Latin capital letter a with tilde
145
- 196 => 'Auml', # Latin capital letter a with diaeresis
146
- 197 => 'Aring', # Latin capital letter a with ring above
147
- 198 => 'AElig', # Latin capital letter ae
148
- 199 => 'Ccedil', # Latin capital letter c with cedilla
149
- 200 => 'Egrave', # Latin capital letter e with grave
150
- 201 => 'Eacute', # Latin capital letter e with acute
151
- 202 => 'Ecirc', # Latin capital letter e with circumflex
152
- 203 => 'Euml', # Latin capital letter e with diaeresis
153
- 204 => 'Igrave', # Latin capital letter i with grave
154
- 205 => 'Iacute', # Latin capital letter i with acute
155
- 206 => 'Icirc', # Latin capital letter i with circumflex
156
- 207 => 'Iuml', # Latin capital letter i with diaeresis
157
- 208 => 'ETH', # Latin capital letter eth
158
- 209 => 'Ntilde', # Latin capital letter n with tilde
159
- 210 => 'Ograve', # Latin capital letter o with grave
160
- 211 => 'Oacute', # Latin capital letter o with acute
161
- 212 => 'Ocirc', # Latin capital letter o with circumflex
162
- 213 => 'Otilde', # Latin capital letter o with tilde
163
- 214 => 'Ouml', # Latin capital letter o with diaeresis
164
- 215 => 'times', # multiplication sign
165
- 216 => 'Oslash', # Latin capital letter o with stroke
166
- 217 => 'Ugrave', # Latin capital letter u with grave
167
- 218 => 'Uacute', # Latin capital letter u with acute
168
- 219 => 'Ucirc', # Latin capital letter u with circumflex
169
- 220 => 'Uuml', # Latin capital letter u with diaeresis
170
- 221 => 'Yacute', # Latin capital letter y with acute
171
- 222 => 'THORN', # Latin capital letter thorn
172
- 223 => 'szlig', # Latin small letter sharp sXCOMMAX German Eszett
173
- 224 => 'agrave', # Latin small letter a with grave
174
- 225 => 'aacute', # Latin small letter a with acute
175
- 226 => 'acirc', # Latin small letter a with circumflex
176
- 227 => 'atilde', # Latin small letter a with tilde
177
- 228 => 'auml', # Latin small letter a with diaeresis
178
- 229 => 'aring', # Latin small letter a with ring above
179
- 230 => 'aelig', # Latin lowercase ligature ae
180
- 231 => 'ccedil', # Latin small letter c with cedilla
181
- 232 => 'egrave', # Latin small letter e with grave
182
- 233 => 'eacute', # Latin small letter e with acute
183
- 234 => 'ecirc', # Latin small letter e with circumflex
184
- 235 => 'euml', # Latin small letter e with diaeresis
185
- 236 => 'igrave', # Latin small letter i with grave
186
- 237 => 'iacute', # Latin small letter i with acute
187
- 238 => 'icirc', # Latin small letter i with circumflex
188
- 239 => 'iuml', # Latin small letter i with diaeresis
189
- 240 => 'eth', # Latin small letter eth
190
- 241 => 'ntilde', # Latin small letter n with tilde
191
- 242 => 'ograve', # Latin small letter o with grave
192
- 243 => 'oacute', # Latin small letter o with acute
193
- 244 => 'ocirc', # Latin small letter o with circumflex
194
- 245 => 'otilde', # Latin small letter o with tilde
195
- 246 => 'ouml', # Latin small letter o with diaeresis
196
- 247 => 'divide', # division sign
197
- 248 => 'oslash', # Latin small letter o with stroke
198
- 249 => 'ugrave', # Latin small letter u with grave
199
- 250 => 'uacute', # Latin small letter u with acute
200
- 251 => 'ucirc', # Latin small letter u with circumflex
201
- 252 => 'uuml', # Latin small letter u with diaeresis
202
- 253 => 'yacute', # Latin small letter y with acute
203
- 254 => 'thorn', # Latin small letter thorn
204
- 255 => 'yuml', # Latin small letter y with diaeresis
205
- 338 => 'OElig', # Latin capital ligature oe
206
- 339 => 'oelig', # Latin small ligature oe
207
- 352 => 'Scaron', # Latin capital letter s with caron
208
- 353 => 'scaron', # Latin small letter s with caron
209
- 376 => 'Yuml', # Latin capital letter y with diaeresis
210
- 402 => 'fnof', # Latin small letter f with hook
211
- 710 => 'circ', # modifier letter circumflex accent
212
- 732 => 'tilde', # small tilde
213
- 913 => 'Alpha', # Greek capital letter alpha
214
- 914 => 'Beta', # Greek capital letter beta
215
- 915 => 'Gamma', # Greek capital letter gamma
216
- 916 => 'Delta', # Greek capital letter delta
217
- 917 => 'Epsilon', # Greek capital letter epsilon
218
- 918 => 'Zeta', # Greek capital letter zeta
219
- 919 => 'Eta', # Greek capital letter eta
220
- 920 => 'Theta', # Greek capital letter theta
221
- 921 => 'Iota', # Greek capital letter iota
222
- 922 => 'Kappa', # Greek capital letter kappa
223
- 923 => 'Lambda', # Greek capital letter lambda
224
- 924 => 'Mu', # Greek capital letter mu
225
- 925 => 'Nu', # Greek capital letter nu
226
- 926 => 'Xi', # Greek capital letter xi
227
- 927 => 'Omicron', # Greek capital letter omicron
228
- 928 => 'Pi', # Greek capital letter pi
229
- 929 => 'Rho', # Greek capital letter rho
230
- 931 => 'Sigma', # Greek capital letter sigma
231
- 932 => 'Tau', # Greek capital letter tau
232
- 933 => 'Upsilon', # Greek capital letter upsilon
233
- 934 => 'Phi', # Greek capital letter phi
234
- 935 => 'Chi', # Greek capital letter chi
235
- 936 => 'Psi', # Greek capital letter psi
236
- 937 => 'Omega', # Greek capital letter omega
237
- 945 => 'alpha', # Greek small letter alpha
238
- 946 => 'beta', # Greek small letter beta
239
- 947 => 'gamma', # Greek small letter gamma
240
- 948 => 'delta', # Greek small letter delta
241
- 949 => 'epsilon', # Greek small letter epsilon
242
- 950 => 'zeta', # Greek small letter zeta
243
- 951 => 'eta', # Greek small letter eta
244
- 952 => 'theta', # Greek small letter theta
245
- 953 => 'iota', # Greek small letter iota
246
- 954 => 'kappa', # Greek small letter kappa
247
- 955 => 'lambda', # Greek small letter lambda
248
- 956 => 'mu', # Greek small letter mu
249
- 957 => 'nu', # Greek small letter nu
250
- 958 => 'xi', # Greek small letter xi
251
- 959 => 'omicron', # Greek small letter omicron
252
- 960 => 'pi', # Greek small letter pi
253
- 961 => 'rho', # Greek small letter rho
254
- 962 => 'sigmaf', # Greek small letter final sigma
255
- 963 => 'sigma', # Greek small letter sigma
256
- 964 => 'tau', # Greek small letter tau
257
- 965 => 'upsilon', # Greek small letter upsilon
258
- 966 => 'phi', # Greek small letter phi
259
- 967 => 'chi', # Greek small letter chi
260
- 968 => 'psi', # Greek small letter psi
261
- 969 => 'omega', # Greek small letter omega
262
- 977 => 'thetasym', # Greek theta symbol
263
- 978 => 'upsih', # Greek upsilon with hook symbol
264
- 982 => 'piv', # Greek pi symbol
265
- 8194 => 'ensp', # en space
266
- 8195 => 'emsp', # em space
267
- 8201 => 'thinsp', # thin space
268
- 8204 => 'zwnj', # zero width non-joiner
269
- 8205 => 'zwj', # zero width joiner
270
- 8206 => 'lrm', # left-to-right mark
271
- 8207 => 'rlm', # right-to-left mark
272
- 8211 => 'ndash', # en dash
273
- 8212 => 'mdash', # em dash
274
- 8216 => 'lsquo', # left single quotation mark
275
- 8217 => 'rsquo', # right single quotation mark
276
- 8218 => 'sbquo', # single low-9 quotation mark
277
- 8220 => 'ldquo', # left double quotation mark
278
- 8221 => 'rdquo', # right double quotation mark
279
- 8222 => 'bdquo', # double low-9 quotation mark
280
- 8224 => 'dagger', # dagger
281
- 8225 => 'Dagger', # double dagger
282
- 8226 => 'bull', # bullet
283
- 8230 => 'hellip', # horizontal ellipsis
284
- 8240 => 'permil', # per mille sign
285
- 8242 => 'prime', # prime
286
- 8243 => 'Prime', # double prime
287
- 8249 => 'lsaquo', # single left-pointing angle quotation mark
288
- 8250 => 'rsaquo', # single right-pointing angle quotation mark
289
- 8254 => 'oline', # overline
290
- 8260 => 'frasl', # fraction slash
291
- 8364 => 'euro', # euro sign
292
- 8465 => 'image', # black-letter capital i
293
- 8472 => 'weierp', # script capital pXCOMMAX Weierstrass p
294
- 8476 => 'real', # black-letter capital r
295
- 8482 => 'trade', # trademark sign
296
- 8501 => 'alefsym', # alef symbol
297
- 8592 => 'larr', # leftwards arrow
298
- 8593 => 'uarr', # upwards arrow
299
- 8594 => 'rarr', # rightwards arrow
300
- 8595 => 'darr', # downwards arrow
301
- 8596 => 'harr', # left right arrow
302
- 8629 => 'crarr', # downwards arrow with corner leftwards
303
- 8656 => 'lArr', # leftwards double arrow
304
- 8657 => 'uArr', # upwards double arrow
305
- 8658 => 'rArr', # rightwards double arrow
306
- 8659 => 'dArr', # downwards double arrow
307
- 8660 => 'hArr', # left right double arrow
308
- 8704 => 'forall', # for all
309
- 8706 => 'part', # partial differential
310
- 8707 => 'exist', # there exists
311
- 8709 => 'empty', # empty set
312
- 8711 => 'nabla', # nabla
313
- 8712 => 'isin', # element of
314
- 8713 => 'notin', # not an element of
315
- 8715 => 'ni', # contains as member
316
- 8719 => 'prod', # n-ary product
317
- 8721 => 'sum', # n-ary summation
318
- 8722 => 'minus', # minus sign
319
- 8727 => 'lowast', # asterisk operator
320
- 8730 => 'radic', # square root
321
- 8733 => 'prop', # proportional to
322
- 8734 => 'infin', # infinity
323
- 8736 => 'ang', # angle
324
- 8743 => 'and', # logical and
325
- 8744 => 'or', # logical or
326
- 8745 => 'cap', # intersection
327
- 8746 => 'cup', # union
328
- 8747 => 'int', # integral
329
- 8756 => 'there4', # therefore
330
- 8764 => 'sim', # tilde operator
331
- 8773 => 'cong', # congruent to
332
- 8776 => 'asymp', # almost equal to
333
- 8800 => 'ne', # not equal to
334
- 8801 => 'equiv', # identical toXCOMMAX equivalent to
335
- 8804 => 'le', # less-than or equal to
336
- 8805 => 'ge', # greater-than or equal to
337
- 8834 => 'sub', # subset of
338
- 8835 => 'sup', # superset of
339
- 8836 => 'nsub', # not a subset of
340
- 8838 => 'sube', # subset of or equal to
341
- 8839 => 'supe', # superset of or equal to
342
- 8853 => 'oplus', # circled plus
343
- 8855 => 'otimes', # circled times
344
- 8869 => 'perp', # up tack
345
- 8901 => 'sdot', # dot operator
346
- 8968 => 'lceil', # left ceiling
347
- 8969 => 'rceil', # right ceiling
348
- 8970 => 'lfloor', # left floor
349
- 8971 => 'rfloor', # right floor
350
- 9001 => 'lang', # left-pointing angle bracket
351
- 9002 => 'rang', # right-pointing angle bracket
352
- 9674 => 'loz', # lozenge
353
- 9824 => 'spades', # black spade suit
354
- 9827 => 'clubs', # black club suit
355
- 9829 => 'hearts', # black heart suit
356
- 9830 => 'diams' # black diamond suit
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` compatibility)
372
- # * Leave open the possibility to developers to mark a string as safe 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`
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
- # Escape HTML contents
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
- # Escape HTML attributes
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
- # Escape URL for HTML attributes (href, src, etc..).
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
- # Encode the given string into UTF-8
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 '' if input.nil?
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] # rubocop:disable Lint/AssignmentInCondition
562
+ if entity = HTML_ENTITIES[code]
559
563
  "&#{entity};"
560
564
  else
561
565
  "&#x#{hex};"