Report abuse

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
  def sidebar(collection, options = {}, &block)
    label = options.include?(:label) ? options[:label] : collection.first.class.to_s.pluralize

    s = sidebar_wrapper(label) do
      collection.inject("") do |buffer, item|
        buffer <<  content_tag(:li, capture(item, &block), :class => 'sidebar-links')
      end
    end
    
    concat(s, block.binding)
  end
  
  protected
  
  def sidebar_wrapper(label)
    content_tag(
      :ul, 
        content_tag(:li, label, :class => 'header') +
        tag(:li, :style => 'list-style: none') + 
        yield,
      :class => 'sidebar-links')
  end