Class: Marsdawn::Site::Indexer

Inherits:
Hash
  • Object
show all
Defined in:
lib/marsdawn/site/indexer.rb

Instance Method Summary collapse

Constructor Details

#initialize(site, index = {}) ⇒ Indexer

Returns a new instance of Indexer.



6
7
8
9
10
11
12
# 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

Instance Method Details

#current_page(path) ⇒ Object



14
15
16
17
# File 'lib/marsdawn/site/indexer.rb', line 14

def current_page path
  @current_page = path
  self
end

#neighbor(path) ⇒ Object



33
34
35
36
37
38
39
40
# 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 = {}) ⇒ Object



46
47
48
49
50
51
52
53
54
# 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_sObject



42
43
44
# File 'lib/marsdawn/site/indexer.rb', line 42

def to_s
  to_html
end

#under(path) ⇒ Object

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



26
27
28
29
30
31
# 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