lib/rabbit/parser/ext/image.rb in rabbit-2.2.1 vs lib/rabbit/parser/ext/image.rb in rabbit-3.0.0
- old
+ new
@@ -1,12 +1,29 @@
-require 'uri'
-require 'cgi'
-require 'open-uri'
-require 'fileutils'
+# Copyright (C) 2007-2018 Kouhei Sutou <kou@cozmixng.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-require 'rabbit/element'
+require "uri"
+require "cgi"
+require "open-uri"
+require "fileutils"
+require "rabbit/element"
+require "rabbit/filename"
+
module Rabbit
module Parser
module Ext
module Image
module_function
@@ -37,11 +54,11 @@
image["_src"] = image_file # for protecting from GC
image
end
module Private
- ALLOWED_IMG_URL_SCHEME = ['http', 'https', 'file']
+ ALLOWED_IMG_URL_SCHEME = ["http", "https", "file"]
module_function
def uri_string_to_image_filename(canvas, uri_string)
if start_with_scheme?(uri_string)
uri = URI.parse(uri_string)
@@ -56,19 +73,19 @@
end
def uri_to_image_filename(canvas, uri)
case uri.scheme.to_s.downcase
when "file"
- GLib.filename_from_utf8(uri.path)
+ Filename.new(uri.path).encode
when "http", "https", "ftp"
other_uri_filename(canvas, uri)
else
nil
end
end
def local_path_to_image_filename(canvas, path)
- path = Pathname.new(GLib.filename_from_utf8(path))
+ path = Pathname.new(Filename.new(path).encode)
return path.to_s if path.absolute?
expanded_path = canvas.full_path(path.to_s)
if start_with_scheme?(expanded_path)
uri_string_to_image_filename(canvas, expanded_path)