Class: Hx::Listing::DateArchive
- Inherits:
-
Object
- Object
- Hx::Listing::DateArchive
- Includes:
- Filter
- Defined in:
- lib/hx/listing/datearchive.rb
Class Method Summary collapse
Instance Method Summary collapse
- #each_entry(selector) ⇒ Object
-
#initialize(input, options) ⇒ DateArchive
constructor
A new instance of DateArchive.
Methods included from Filter
#each_entry_path, #edit_entry, #get_entry
Constructor Details
#initialize(input, options) ⇒ DateArchive
Returns a new instance of DateArchive.
38 39 40 41 42 |
# File 'lib/hx/listing/datearchive.rb', line 38 def initialize(input, ) @input = input @date_fields = Array([:date_fields] || %w(created updated)) @index_name = [:index_name] || "index" end |
Class Method Details
.new(input, options) ⇒ Object
33 34 35 36 |
# File 'lib/hx/listing/datearchive.rb', line 33 def self.new(input, ) listing = super(input, ) Listing.(listing, ) 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 |
# File 'lib/hx/listing/datearchive.rb', line 44 def each_entry(selector) indices = {} @input.each_entry(Path::ALL) do |path, entry| date = @date_fields.map { |field| entry[field] }.compact.first next unless date month_path = "%04d/%02d/#{@index_name}" % [date.year, date.month] year_path = "%04d/#{@index_name}" % [date.year] for index_path in [month_path, year_path] next unless selector.accept_path? index_path index_entry = indices[index_path] unless index_entry index_entry = {"items" => [], "year" => date.year, "updated" => date} index_entry["month"] = date.month if index_path == month_path indices[index_path] = index_entry end index_entry["updated"] = date if date > index_entry["updated"] index_entry["items"] << {"path" => path, "entry" => entry} end end indices.each do |index_path, index_entry| yield index_path, index_entry end self end |