Skip to content

Instantly share code, notes, and snippets.

@fracai
Created August 8, 2011 22:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fracai/1132866 to your computer and use it in GitHub Desktop.
Save fracai/1132866 to your computer and use it in GitHub Desktop.
nanoc helper for building path based relationshiips
module Nanoc3::Helpers
module Relationships
extend Nanoc3::Memoization
def output_parent(page)
nil == page and return nil
(page.identifier == '/' or page.binary? or page[:is_hidden]) and return nil
path = page.path.gsub(/[^\/]*$/,'')
@items.sort_by{ |i| i.path.count('/') }.reverse.each do |i|
(i == page or i.binary? or i[:is_hidden]) and next
if path =~ /^#{i.path.gsub(/[^\/]+$/,'')}/
return i
end
end
raise "error finding parent" # should never reach this point
end
memoize :output_parent
def output_children(page)
nil == page and return []
page.binary? and return nil
return @items.select { |i| output_parent(i) == page }
end
memoize :output_children
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment