class Marsdawn::Site::Indexer
Public Class Methods
new(site, index={})
click to toggle source
# File lib/marsdawn/site/indexer.rb, line 6 def initialize site, index={} @site = site @current_page = nil index.each do |uri, title| self[uri] = Marsdawn::Site::Link.new(@site, uri, title) end end
Public Instance Methods
current_page(path)
click to toggle source
# File lib/marsdawn/site/indexer.rb, line 14 def current_page path @current_page = path self end
neighbor(path)
click to toggle source
# File lib/marsdawn/site/indexer.rb, line 33 def neighbor path level = path.count('/') base = File.dirname(path) base = "#{base}/" if base != '/' self.each_with_object(Marsdawn::Site::Indexer.new(@site).current_page(path)) do |(uri, link), ret| ret[uri] = link if uri.start_with?(base) && uri.count('/') == level && uri != base end end
to_html(options={})
click to toggle source
# File lib/marsdawn/site/indexer.rb, line 46 def to_html options={} if self.size > 0 opts = { }.merge(options) create_link_html File.dirname(self.keys.first), opts else "" end end
to_s()
click to toggle source
# File lib/marsdawn/site/indexer.rb, line 42 def to_s to_html end
under(path)
click to toggle source
def parent path
parent_path = "#{File.dirname(path)}/" self.each_with_object(Marsdawn::Site::Indexer.new(@site).current_page(path)) do |(uri, link), ret| ret[uri] = link if uri == parent_path end
end
# File lib/marsdawn/site/indexer.rb, line 26 def under path base = path + (path == '/' ? '' : '/') self.each_with_object(Marsdawn::Site::Indexer.new(@site).current_page(path)) do |(uri, link), ret| ret[uri] = link if uri.start_with?(base) && uri != base end end
Private Instance Methods
create_link_html(path, opts={})
click to toggle source
# File lib/marsdawn/site/indexer.rb, line 57 def create_link_html path, opts={} base_level = path.count('/') words = [] words << '<ul>' self.each do |uri, link| next unless uri.start_with?(path) level = uri.count('/') if base_level < level words.insert -2, create_link_html(uri) elsif base_level == level attr = (uri == @current_page ? ' class="current-page"' : '') words << "<li#{attr}>" words << link.to_html words << '</li>' end end words << '</ul>' words.size > 2 ? words.join('') : "" end