<%= toctree :from => '/' %>
<%= toctree %>
<%= toctree '/dir_a/', '/dir_b/' %>
<%= toctree '/dir_a/', '/dir_b/', :except => ['dir_a/dir_x', 'dir_a/dir_y'] %>
<%= toctree :maxdepth => 2 %>
<%= toctree :from => '/' %>
<%= toctree %>
<%= toctree '/dir_a/', '/dir_b/' %>
<%= toctree '/dir_a/', '/dir_b/', :except => ['dir_a/dir_x', 'dir_a/dir_y'] %>
<%= toctree :maxdepth => 2 %>
| module Nanoc3 | |
| module Helpers | |
| module TocTree | |
| def toctree(*args) | |
| ids = args.select{|arg| arg.is_a?(String) } | |
| ids = ['*'] if ids.empty? | |
| opts = args.reject{|arg| arg.is_a?(String) }.first || {} | |
| opts[:from] ||= @item.identifier | |
| items = titled_items | |
| .select{|item| item.identifier =~ /^#{ids.join('|')}/ } | |
| .select{|item| !item.parent.nil? && item.parent.identifier == opts[:from] } | |
| .sort{|i1, i2| i1.identifier <=> i2.identifier } | |
| to_list(items, opts) | |
| end | |
| private | |
| def titled_items | |
| @items.reject{|item| item[:title].nil? } | |
| end | |
| def to_list(items, opts, depth = 0) | |
| return "" if !opts[:maxdepth].nil? && opts[:maxdepth] <= depth | |
| html = '<ul>' | |
| items.each do |item| | |
| next if opts[:except] && opts[:except].include?(item.identifier) | |
| html += "<li>#{link_to(item[:title], item)}</li>" | |
| # html += "<li>#{link_to(item.identifier, item)}</li>" | |
| if not item.children.empty? | |
| html += to_list(item.children, opts, depth + 1) | |
| end | |
| end | |
| html += '</ul>' | |
| end | |
| end | |
| end | |
| end |