Class: Hx::Listing::RecursiveIndex

Inherits:
Object
  • Object
show all
Includes:
Filter
Defined in:
lib/hx/listing/recursiveindex.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Filter

#each_entry_path, #get_entry

Methods included from View

#edit_entry

Constructor Details

#initialize(input, options) ⇒ RecursiveIndex

Returns a new instance of RecursiveIndex.



39
40
41
42
# File 'lib/hx/listing/recursiveindex.rb', line 39

def initialize(input, options)
  @input = input
  @index_name = options[:index_name] || "index"
end

Class Method Details

.new(input, options) ⇒ Object



34
35
36
37
# File 'lib/hx/listing/recursiveindex.rb', line 34

def self.new(input, options)
  listing = super(input, options)
  Listing.apply_options(listing, options)
end

Instance Method Details

#each_entry(selector) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/hx/listing/recursiveindex.rb', line 44

def each_entry(selector)
  indices = {}
  @input.each_entry(Path::ALL) do |path, entry|
    components = path.split("/")
    until components.empty?
      components.pop
      index_path = (components + [@index_name]).join("/")
      next unless selector.accept_path? index_path
      index_entry = indices[index_path]
      unless index_entry
        index_entry = {'items' => []}
        indices[index_path] = index_entry
      end
      if path == index_path
        index_entry = entry.merge(index_entry)
        indices[index_path] = index_entry
      end
      index_entry['items'] << {'path' => path, 'entry' => entry}
      index_entry['updated'] = Hx.last_update_time(index_entry, entry)
    end
  end
  indices.each do |path, entry|
    yield path, entry
  end
  self
end