trulia / hologram

A markdown based documentation system for style guides.
http://trulia.github.io/hologram
Other
2.16k stars 199 forks source link

Nested blocks menu #225

Closed lifeiscontent closed 4 years ago

lifeiscontent commented 9 years ago

If anyone else wants a nested structure like I did.

this is how you do it.

at the top of the _header.html file put this

<% parent_blocks = @blocks.select { |b| b[:children] = nil; b[:parent].nil? } %>
<% @blocks.reject { |b| b[:parent].nil? }.each { |b| parent_blocks.find { |pb| pb[:name] == b[:parent].get_hash[:name] }[:children] = b[:parent].children.keys } %>

in your section nav you can write something like this

<ul>
  <li><%= title %> nav</li>
  <% parent_blocks.each do |block| %>
  <li>
    <a href="#<%= block[:name] %>"><%= block[:title] %></a>
    <% unless block[:children].nil? %>
    <ul>
      <% block[:children].each do |child| %>
      <% child = @blocks.find { |b| b[:name] == child } %>
      <li>
        <a href="#<%= child[:name] %>"><%= child[:title] %></a>
      </li>
      <% end %>
    </ul>
    <% end %>
  </li>
  <% end %>
</ul>
chris-canipe commented 9 years ago

This is great: thanks!