Class: Lifer::Entry::TXT
- Inherits:
-
Lifer::Entry
- Object
- Lifer::Entry
- Lifer::Entry::TXT
- 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
Instance Method Summary collapse
-
#title ⇒ String
If there is no available metadata in the text file, we can extract a makeshift title from the permalink.
-
#to_html ⇒ String
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.
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
#title ⇒ String
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.
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_html ⇒ String
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.
37 |
# File 'lib/lifer/entry/txt.rb', line 37 def to_html = body |