Class: Gollum::Macro::Navigation

Inherits:
Gollum::Macro show all
Defined in:
lib/gollum-lib/macro/navigation.rb

Instance Method Summary collapse

Methods inherited from Gollum::Macro

#initialize, instance

Constructor Details

This class inherits a constructor from Gollum::Macro

Instance Method Details

#render(title = "Navigate this directory", toc_root_path = ::File.dirname(@page.url_path), full_path = false) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/gollum-lib/macro/navigation.rb', line 5

def render(title = "Navigate this directory", toc_root_path = ::File.dirname(@page.url_path), full_path = false)
  pages = @wiki.pages
  if pages.size > 0
    prepath=@wiki.base_path.sub(/\/$/, '')
    list_items = pages.map do |page|
      if toc_root_path == '.' || page.url_path =~ /^#{toc_root_path}\//
        path_display = (full_path || toc_root_path == '.') ? page.url_path  : page.url_path.sub(/^#{toc_root_path}\//,"").sub(/^\//,'')
        "<li><a href=\"#{CGI::escapeHTML(prepath + "/" + page.escaped_url_path)}\">#{CGI::escapeHTML(path_display)}</a></li>"
      end
    end
    result = "<ul>#{list_items.join}</ul>"
  end
  "<div class=\"toc\"><div class=\"toc-title\">#{title}</div>#{result}</div>"
end