lib/rabbit/parser/ext/image.rb in rabbit-1.0.9 vs lib/rabbit/parser/ext/image.rb in rabbit-2.0.0
- old
+ new
@@ -7,11 +7,11 @@
module Rabbit
module Parser
module Ext
module Image
- ALLOWED_IMG_URL_SCHEME = ['http', 'file', '']
+ ALLOWED_IMG_URL_SCHEME = ['http', 'https', 'file', '']
module_function
def make_image(canvas, uri_str, prop={})
uri = URI.parse(uri_str)
scheme = uri.scheme
@@ -45,38 +45,32 @@
end
module Private
module_function
def image_filename(canvas, uri)
- case uri.scheme
- when /file/i
+ case uri.scheme.to_s.downcase
+ when "file"
GLib.filename_from_utf8(uri.path)
- when /http|ftp/i
+ when "http", "https", "ftp"
other_uri_filename(canvas, uri)
else
- related_path_filename(canvas, uri)
+ path = Pathname.new(GLib.filename_from_utf8(uri.path))
+ return path.to_s if path.absolute?
+
+ expanded_path = canvas.full_path(path.to_s)
+ expanded_uri = URI(expanded_path)
+ if expanded_uri.scheme.nil?
+ expanded_path
+ else
+ image_filename(canvas, expanded_uri)
+ end
end
end
def tmp_filename(canvas, key)
dir = canvas.tmp_dir_name
FileUtils.mkdir_p(dir)
File.join(dir, CGI.escape(key))
- end
-
- def related_path_filename(canvas, uri)
- image_uri = canvas.full_path(GLib.filename_from_utf8(uri.to_s))
- filename = nil
-
- begin
- raise URI::InvalidURIError if URI.parse(image_uri).scheme.nil?
- filename = tmp_filename(canvas, image_uri)
- setup_image_file(canvas, image_uri, filename)
- rescue URI::InvalidURIError
- filename = image_uri
- end
-
- filename
end
def other_uri_filename(canvas, uri)
filename = tmp_filename(canvas, uri.to_s)
setup_image_file(canvas, uri, filename)