class JekyllRPG::CollectionDocument
Represents a document that may be in a Jekyll collection, extracted from either a document itself, or a markdown link.
Attributes
collection[RW]
name[RW]
slug[RW]
viewable[RW]
Public Instance Methods
document_exists()
click to toggle source
Checks whether document exists in a site
# File lib/collection_document.rb, line 29 def document_exists !@site.collections[@collection].nil? && !find_document.nil? end
extract_doc(doc)
click to toggle source
# File lib/collection_document.rb, line 10 def extract_doc(doc) @name = doc.data['name'] @collection = doc.collection.label @slug = doc.data['slug'] @viewable = true self end
extract_markdown(site, link)
click to toggle source
extracts link text, collection and slug
# File lib/collection_document.rb, line 19 def extract_markdown(site, link) @site = site @collection = link.collection @slug = link.slug @viewable = viewable @name = @viewable ? find_document.data['name'] : link.name self end
find_document()
click to toggle source
Find a document based on its collection and slug
# File lib/collection_document.rb, line 34 def find_document @site.collections[@collection].docs.find { |doc| doc.data['slug'] == @slug } end
hash()
click to toggle source
# File lib/collection_document.rb, line 48 def hash { 'name' => @name, 'collection' => @collection, 'slug' => @slug, 'link' => markdown_link } end
markdown_link()
click to toggle source
# File lib/collection_document.rb, line 44 def markdown_link "[#{@name}](/#{@collection}/#{@slug})" end