Class: Dimples::Post

Inherits:
Entry
  • Object
show all
Defined in:
lib/dimples/post.rb

Overview

A single post for a site.

Constant Summary

Constants inherited from Entry

Entry::DEFAULT_FILENAME, Entry::FRONT_MATTER_PATTERN

Class Attribute Summary collapse

Instance Attribute Summary collapse

Attributes inherited from Entry

#contents, #metadata, #path

Instance Method Summary collapse

Methods inherited from Entry

#method_missing, #parse_metadata, #respond_to_missing?

Constructor Details

#initialize(path:) ⇒ Post

Returns a new instance of Post.



14
15
16
# File 'lib/dimples/post.rb', line 14

def initialize(path:)
  super(source: Pathname.new(path))
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Dimples::Entry

Class Attribute Details

.markdownObject (readonly)

Returns the value of attribute markdown.



9
10
11
# File 'lib/dimples/post.rb', line 9

def markdown
  @markdown
end

Instance Attribute Details

#rendered_contentsObject (readonly)

Returns the value of attribute rendered_contents.



12
13
14
# File 'lib/dimples/post.rb', line 12

def rendered_contents
  @rendered_contents
end

Instance Method Details

#render(context: nil) ⇒ Object



22
23
24
25
26
# File 'lib/dimples/post.rb', line 22

def render(context: nil)
  @rendered_contents ||= Redcarpet::Render::SmartyPants.render(
    Dimples::Post.markdown.render(contents)
  )
end

#slugObject



18
19
20
# File 'lib/dimples/post.rb', line 18

def slug
  File.basename(path, File.extname(path))&.downcase
end