# File lib/nanoc3/helpers/link_to.rb, line 111 def relative_path_to(target) require 'pathname' # Find path path = target.is_a?(String) ? target : target.path # Get source and destination paths dst_path = Pathname.new(path) src_path = Pathname.new(@item_rep.path) # Calculate elative path (method depends on whether destination is a # directory or not). 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 # Add trailing slash if necessary if dst_path.to_s[-1,1] == '/' relative_path << '/' end # Done relative_path end