Skip to content

Instantly share code, notes, and snippets.

@lcw
Created December 31, 2009 03:08
Show Gist options
  • Save lcw/266585 to your computer and use it in GitHub Desktop.
Save lcw/266585 to your computer and use it in GitHub Desktop.
# All files in the 'lib' directory will be loaded
# before nanoc starts compiling.
include Nanoc3::Helpers::LinkTo
# Creates a HTML link using link_to, except when the linked item is the
# current one. In this case, a span element with class "active" and with
# the given text will be returned.
#
# Examples:
#
# link_to_unless_current('Blog', '/blog/')
# # => '<a href="/blog/">Blog</a>'
#
# link_to_unless_current('This Item', @item_rep)
# # => '<span class="active">This Item</span>'
def link_to_project_unless_current(text, path_or_rep_unless, path_or_rep,
attributes={})
# Find path
path = path_or_rep.is_a?(String) ? path_or_rep : path_or_rep.path
path_unless = path_or_rep_unless.is_a?(String) ? path_or_rep_unless : path_or_rep_unless.path
if @item_rep and @item_rep.path.match(path_unless)
# Create message
"<span class=\"active\" title=\"You're here.\">#{text}</span>"
else
link_to(text, path_or_rep, attributes)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment