Class: Dimples::Post
Overview
A page from a site with a date.
Constant Summary
Constants inherited from Entry
Instance Attribute Summary
Attributes inherited from Entry
#contents, #metadata, #path, #rendered_contents
Instance Method Summary collapse
-
#initialize(site:, path:) ⇒ Post
constructor
A new instance of Post.
- #output_directory ⇒ Object
- #slug ⇒ Object
- #template ⇒ Object
- #to_h ⇒ Object
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_directory ⇒ Object
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 |
#slug ⇒ Object
17 18 19 |
# File 'lib/dimples/post.rb', line 17 def slug File.basename(@path, File.extname(@path))&.downcase end |
#template ⇒ Object
21 22 23 |
# File 'lib/dimples/post.rb', line 21 def template @template ||= Tilt::RedcarpetTemplate.new { @contents } end |
#to_h ⇒ Object
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 |