From 9df75e3bcae32d373ab895b01fa27d0baee5e909 Mon Sep 17 00:00:00 2001 From: Date: Wed, 11 Oct 2017 23:03:20 +0900 Subject: [PATCH] =?UTF-8?q?Windows=E9=A2=A8=E3=81=AE=E3=83=91=E3=82=B9?= =?UTF-8?q?=E3=82=92=E3=82=B5=E3=83=9D=E3=83=BC=E3=83=88=E3=81=99=E3=82=8B?= =?UTF-8?q?=E6=A9=9F=E6=A7=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/plugin/photo/model/photo.rb | 16 +++++++++----- .../windows_path_support/windows_path_support.rb | 25 ++++++++++++++++++++++ 2 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 core/plugin/windows_path_support/windows_path_support.rb diff --git a/core/plugin/photo/model/photo.rb b/core/plugin/photo/model/photo.rb index b954ead..2ecb2ae 100644 --- a/core/plugin/photo/model/photo.rb +++ b/core/plugin/photo/model/photo.rb @@ -19,11 +19,17 @@ module Plugin::Photo when URI, Addressable::URI, Retriever::URI photos[uri.to_s.hash] ||= new(perma_link: uri) when String - if uri.start_with?('http') - photos[uri.hash] ||= new(perma_link: uri) - elsif uri.start_with?('/') - uri = Retriever::URI.new(scheme: 'file', path: uri) - photos[uri.hash] ||= new(perma_link: uri) + uri_obj = Plugin.filtering(:uri_from_string, nil, uri).first + + if uri_obj + photos[uri.hash] ||= new(perma_link: uri_obj) + else + if uri.start_with?('http') + photos[uri.hash] ||= new(perma_link: uri) + elsif uri.start_with?('/') + uri = Retriever::URI.new(scheme: 'file', path: uri) + photos[uri.hash] ||= new(perma_link: uri) + end end end end diff --git a/core/plugin/windows_path_support/windows_path_support.rb b/core/plugin/windows_path_support/windows_path_support.rb new file mode 100644 index 0000000..40a27a9 --- /dev/null +++ b/core/plugin/windows_path_support/windows_path_support.rb @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# windows_path_support.rb +# +# + +require "rbconfig" + +Plugin.create :windows_path_support do + filter_uri_from_string { |uri, str| + # Windows? + result = if RbConfig::CONFIG["host_os"] =~ /mswin|mingw|bccwin|wince/ + # has drive letter? + if str =~ /^[a-zA-Z]\:/ + Retriever::URI.new(scheme: 'file', path: uri) + else + nil + end + else + nil + end + + [result, str] + } + +end -- 2.7.4