def relative_path_to(target)
require 'pathname'
if target.is_a?(String)
path = target
else
path = target.path
if path.nil?
raise "Cannot get the relative path to #{target.inspect} because this target is not outputted (its routing rule returns nil)"
end
end
if path.start_with?('//') || path.start_with?('\\\\')
return path
end
dst_path = Pathname.new(path)
if @item_rep.path.nil?
raise "Cannot get the relative path to #{path} because the current item representation, #{@item_rep.inspect}, is not outputted (its routing rule returns nil)"
end
src_path = Pathname.new(@item_rep.path)
if src_path.to_s[-1,1] != '/'
relative_path = dst_path.relative_path_from(src_path.dirname).to_s
else
relative_path = dst_path.relative_path_from(src_path).to_s
end
if dst_path.to_s[-1,1] == '/'
relative_path << '/'
end
relative_path
end