class Jekyll::Drops::DocumentDrop

Constants

NESTED_OBJECT_FIELD_BLACKLIST

Public Instance Methods

<=>(other) click to toggle source
# File lib/jekyll/drops/document_drop.rb, line 32
def <=>(other)
  return nil unless other.is_a? DocumentDrop

  cmp = self["date"] <=> other["date"]
  cmp = self["path"] <=> other["path"] if cmp.nil? || cmp.zero?
  cmp
end
collapse_document(doc) click to toggle source

Generate a Hash which breaks the recursive chain. Certain fields which are normally available are omitted.

Returns a Hash with only non-recursive fields present.

# File lib/jekyll/drops/document_drop.rb, line 67
def collapse_document(doc)
  doc.keys.each_with_object({}) do |(key, _), result|
    result[key] = doc[key] unless NESTED_OBJECT_FIELD_BLACKLIST.include?(key)
  end
end
collection() click to toggle source
# File lib/jekyll/drops/document_drop.rb, line 20
def collection
  @obj.collection.label
end
excerpt() click to toggle source
# File lib/jekyll/drops/document_drop.rb, line 24
def excerpt
  fallback_data["excerpt"].to_s
end
hash_for_json(state = nil) click to toggle source

Generate a Hash for use in generating JSON. This is useful if fields need to be cleared before the JSON can generate.

state - the JSON::State object which determines the state of current processing.

Returns a Hash ready for JSON generation.

# File lib/jekyll/drops/document_drop.rb, line 54
def hash_for_json(state = nil)
  to_h.tap do |hash|
    if state && state.depth >= 2
      hash["previous"] = collapse_document(hash["previous"]) if hash["previous"]
      hash["next"]     = collapse_document(hash["next"]) if hash["next"]
    end
  end
end
name() click to toggle source
# File lib/jekyll/drops/document_drop.rb, line 28
def name
  fallback_data["name"] || @obj.basename
end
next() click to toggle source
# File lib/jekyll/drops/document_drop.rb, line 44
def next
  @obj.next_doc.to_liquid
end
previous() click to toggle source
# File lib/jekyll/drops/document_drop.rb, line 40
def previous
  @obj.previous_doc.to_liquid
end