Sha256: f69253f96128a18d9eed28b6793289d91a7eb66ac76e83b380722407c1907573

Contents?: true

Size: 943 Bytes

Versions: 5

Compression:

Stored size: 943 Bytes

Contents

class Menu < Record
  def render(page)
    if include_all_children
      items = root.children.collect do |child|
        exception = exceptions.find {|except| except.page == child}
        next if exception && !exception.show
        render_item(child, page, 0, exception ? exception.depth : depth)
      end
    else
      items = exceptions.all.collect do |exception|
        render_item(exception.page, page, 0, exception.depth)
      end
    end
    
    if include_root
      items.unshift(render_item(root, page, 0, 0))
    end
    
    "<nav>#{items.join}</nav>"
  end
  
  private
    def render_item(item, page, current_depth, max_depth)
      items = ["<a href='#{item.path}' class='#{'selected' if item == page}'>#{item.title}</a>"]
      if current_depth < max_depth
        item.children.each do |child|
          items << render_item(child, page, current_depth + 1, max_depth)
        end
      end
      items.join
    end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
yodel-0.0.7 lib/yodel/models/pages/menu.rb
yodel-0.0.4 lib/yodel/models/pages/menu.rb
yodel-0.0.3 lib/yodel/models/pages/menu.rb
yodel-0.0.2 lib/yodel/models/pages/menu.rb
yodel-0.0.1 lib/yodel/models/pages/menu.rb