lib/nanoc/helpers/link_to.rb in nanoc-3.6.7 vs lib/nanoc/helpers/link_to.rb in nanoc-3.6.8

- old
+ new

@@ -43,21 +43,21 @@ # # @example Linking with custom attributes # # 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={}) + def link_to(text, target, attributes = {}) # Find 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? + raise "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)| + attributes = attributes.reduce('') do |memo, (key, value)| memo + key.to_s + '="' + h(value) + '" ' end # Create link "<a #{attributes}href=\"#{h path}\">#{text}</a>" @@ -85,11 +85,11 @@ # # @example Linking to the same page # # link_to_unless_current('This Item', @item) # # => '<span class="active" title="You\'re here.">This Item</span>' - def link_to_unless_current(text, target, attributes={}) + def link_to_unless_current(text, target, attributes = {}) # Find path path = target.is_a?(String) ? target : target.path if @item_rep && @item_rep.path == path # Create message @@ -138,17 +138,17 @@ end src_path = Pathname.new(@item_rep.path) # Calculate the relative path (method depends on whether destination is # a directory or not). - if src_path.to_s[-1,1] != '/' + 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] == '/' + if dst_path.to_s[-1, 1] == '/' relative_path << '/' end # Done relative_path