Module: Middleman::ListPages::HelperMethods

Defined in:
lib/middleman-listpages/extension.rb

Instance Method Summary collapse

Instance Method Details

#li_for(page, sub_list = nil, opts = {}) ⇒ Object



37
38
39
40
41
# File 'lib/middleman-listpages/extension.rb', line 37

def li_for(page, sub_list=nil, opts={})
  active = (page.path == current_page.path)

  render('_list_item', binding)
end

#list_pages(page = nil, opts = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/middleman-listpages/extension.rb', line 13

def list_pages(page=nil, opts={})
  opts[:depth] ||= -1
  opts[:current_depth] ||= 1
  if opts[:depth] > -1
    return "" if (opts[:current_depth] > opts[:depth])
  end

  page ||= sitemap.find_resource_by_destination_path('index.html')
  children = filter_children(page.children, opts.slice(:extensions))

  if children.empty?
    ""
  else
    child_html = children.map do |child|
      my_opts = opts.dup
      my_opts[:current_depth] +=  1
      sub_list = list_pages(child, my_opts)
      li_for(child, sub_list, my_opts)
    end

    render('_list', binding)
  end
end