Class: Dimples::Post

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

Overview

A page from a site with a date.

Constant Summary

Constants inherited from Entry

Entry::FRONT_MATTER_PATTERN

Instance Attribute Summary

Attributes inherited from Entry

#contents, #metadata, #path, #rendered_contents

Instance Method Summary collapse

Methods inherited from Entry

#generate, #method_missing, #parse_metadata, #render, #respond_to_missing?, #url, #write

Constructor Details

#initialize(site:, path:) ⇒ Post

Returns a new instance of Post.



6
7
8
# File 'lib/dimples/post.rb', line 6

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

Dynamic Method Handling

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

Instance Method Details

#output_directoryObject



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

def output_directory
  @output_directory ||= File.dirname(@path).gsub(
    @site.config.source_paths[:posts],
    @site.config.build_paths[:posts]
  ).concat("/#{slug}/")
end

#slugObject



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

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

#templateObject



21
22
23
# File 'lib/dimples/post.rb', line 21

def template
  @template ||= Tilt::RedcarpetTemplate.new { @contents }
end

#to_hObject



25
26
27
28
29
30
# File 'lib/dimples/post.rb', line 25

def to_h
  super.reject { |k, _| i[filename layout].include?(k) }.tap do |output|
    output[:date] = output[:date].iso8601 unless output[:date].nil?
    output[:url] ||= url
  end
end