class JekyllRPG::ReferenceTable

Generates Reference Table

Attributes

html[RW]

Public Class Methods

new(site, doc) click to toggle source
# File lib/reference_table.rb, line 8
def initialize(site, doc)
  @html = ''
  @html = refs_table(doc.data['referenced_by']) if refs_table_required(site, doc)
end

Public Instance Methods

refs_rows(refs) click to toggle source
# File lib/reference_table.rb, line 43
    def refs_rows(refs)
      row = ''
      refs.each do |reference|
        row += <<~ROW
          <tr>
            <td markdown="span"><b> #{reference[0].capitalize} </b></td>
            <td markdown="span"> #{refs_links(reference)} </td>
          </tr>
        ROW
      end
      row
    end
refs_table(refs) click to toggle source
# File lib/reference_table.rb, line 25
    def refs_table(refs)
      table = <<~TABLE
        \n# Referenced By:
        <table>
          <thead>
            <tr>
              <th>Collection</th>
              <th>Links</th>
            </tr>
          </thead>
          <tbody>
            #{refs_rows(refs)}
          </tbody>
        </table>
      TABLE
      table
    end
refs_table_required(site, doc) click to toggle source

Determines if refs table is required based on document, then collection, then site

# File lib/reference_table.rb, line 15
def refs_table_required(site, doc)
  if doc.data.key?('refs')
    doc.data['refs']
  elsif site.config['collections'][doc.collection.label].key?('refs')
    site.config['collections'][doc.collection.label]['refs']
  elsif site.config.key?('refs')
    site.config['refs']
  end
end