lib/nanoc3/helpers/link_to.rb in nanoc3-3.2.0a1 vs lib/nanoc3/helpers/link_to.rb in nanoc3-3.2.0a2

- old
+ new

@@ -45,11 +45,16 @@ # # link_to('Blog', '/blog/', :title => 'My super cool blog') # # => '<a title="My super cool blog" href="/blog/">Blog</a>' def link_to(text, target, attributes={}) # Find path - path = target.is_a?(String) ? target : target.path + if target.is_a?(String) + path = target + else + path = target.path + raise RuntimeError, "Cannot create a link to #{target.inspect} because this target is not outputted (its routing rule returns nil)" if path.nil? + end # Join attributes attributes = attributes.inject('') do |memo, (key, value)| memo + key.to_s + '="' + h(value) + '" ' end @@ -110,17 +115,23 @@ # # => '../qux/' def relative_path_to(target) require 'pathname' # Find path - path = target.is_a?(String) ? target : target.path + if target.is_a?(String) + path = target + else + path = target.path + raise RuntimeError, "Cannot get the relative path to #{target.inspect} because this target is not outputted (its routing rule returns nil)" if path.nil? + end # Get source and destination paths dst_path = Pathname.new(path) + raise RuntimeError, "Cannot get the relative path to #{path} because the current item representation, #{@item_rep.inspect}, is not outputted (its routing rule returns nil)" if @item_rep.path.nil? src_path = Pathname.new(@item_rep.path) - # Calculate elative path (method depends on whether destination is a - # directory or not). + # Calculate the relative 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