Class: Lifer::Entry::TXT

Inherits:
Lifer::Entry show all
Defined in:
lib/lifer/entry/txt.rb

Overview

One may want to provide browser-readable text files without any layout or metadata information. In those cases, here’s a good entry subclass. Just make sure the entry ends in ‘.txt`.

Constant Summary

Constants inherited from Lifer::Entry

DEFAULT_DATE, FILENAME_DATE_FORMAT, TAG_DELIMITER_REGEX, TRUNCATION_THRESHOLD

Instance Attribute Summary

Attributes inherited from Lifer::Entry

#collection, #file

Instance Method Summary collapse

Methods inherited from Lifer::Entry

#authors, #body, #feedable?, #frontmatter, #full_text, generate, #initialize, manifest, #path, #permalink, #published_at, #summary, supported?, #tags, #updated_at

Constructor Details

This class inherits a constructor from Lifer::Entry

Instance Method Details

#titleString

If there is no available metadata in the text file, we can extract a makeshift title from the permalink.

Depending on the filename and URI strategy being used for the collection, it’s possible that the extracted title would be “index”, which is not very descriptive. If that’s the case, we attempt to go up a directory to find a non-“index” title.

Returns:

  • (String)

    The given or extracted title of the entry.



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/lifer/entry/txt.rb', line 19

def title
  return frontmatter[:title] if frontmatter[:title]

  candidate = File.basename(permalink, ".txt")

  if candidate.include?("index") && !file.to_s.include?("index")
    File.basename(permalink.sub(/\/#{candidate}\.html$/, ""))
  else
    candidate
  end
end

#to_htmlString

While we don’t actually output text to HTML, we need to implement this method so that the RSS feed builder can add text files as feed entries.

Returns:

  • (String)

    The output HTML (not actually HTML).



37
# File 'lib/lifer/entry/txt.rb', line 37

def to_html = body