Skip to content

Commit 89f0678

Browse files
committed
Refactor ascii? method
1 parent 0de33cd commit 89f0678

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

lib/iruby/display.rb

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require "set"
2+
13
module IRuby
24
module Display
35
class << self
@@ -50,14 +52,15 @@ def protect(mime, data)
5052
ascii?(mime) ? data.to_s : [data.to_s].pack('m0')
5153
end
5254

55+
# Each of the following mime types must be a text type,
56+
# but mime-types library tells us it is a non-text type.
57+
FORCE_TEXT_TYPES = Set[
58+
"application/javascript",
59+
"image/svg+xml"
60+
].freeze
61+
5362
def ascii?(mime)
54-
case mime
55-
when "application/javascript"
56-
# Special case for application/javascript.
57-
# This needs because mime-types tells us application/javascript a non-text type.
58-
true
59-
when "image/svg+xml"
60-
# mime-types tells us image/svg+xml a non-text type.
63+
if FORCE_TEXT_TYPES.include?(mime)
6164
true
6265
else
6366
MIME::Type.new(mime).ascii?

0 commit comments

Comments
 (0)