Class: Marsdawn::Site::Indexer
- Inherits:
-
Hash
- Object
- Hash
- Marsdawn::Site::Indexer
- Defined in:
- lib/marsdawn/site/indexer.rb
Instance Method Summary collapse
- #current_page(path) ⇒ Object
-
#initialize(site, index = {}) ⇒ Indexer
constructor
A new instance of Indexer.
- #neighbor(path) ⇒ Object
- #to_html(options = {}) ⇒ Object
- #to_s ⇒ Object
-
#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 = link if uri == parent_path end end.
Constructor Details
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 ={} if self.size > 0 opts = { }.merge() create_link_html File.dirname(self.keys.first), opts else "" end end |
#to_s ⇒ Object
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 |