Skip to content

Commit

Permalink
Remove the Document subclass, use the Metadata include
Browse files Browse the repository at this point in the history
  • Loading branch information
waferbaby committed Jan 19, 2024
1 parent 6fd4333 commit 06158fc
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
19 changes: 16 additions & 3 deletions lib/dimples/page.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
# frozen_string_literal: true

require_relative 'document'

module Dimples
class Page < Document
# A class representing a single page on a site.
class Page
include Metadata

def initialize(path: nil, metadata: {})
@path = path
@metadata = {}
@contents = ''

load_metadata(path) if path
@metadata.merge!(metadata) unless metadata.empty?
end

def layout
@metadata.fetch(:layout, 'page')
end
end
end
9 changes: 6 additions & 3 deletions lib/dimples/post.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# frozen_string_literal: true

require_relative 'document'

require 'date'

module Dimples
class Post < Document
# A class representing a single post on a site.
class Post < Page
def categories
@metadata.fetch(:categories, [])
end

def date
@metadata.fetch(:date, DateTime.now)
end
Expand Down
11 changes: 8 additions & 3 deletions lib/dimples/template.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
# frozen_string_literal: true

require_relative 'document'

module Dimples
class Template < Document
# A class representing a single template used for a layout on a site.
class Template
include Metadata

def initialize(path:)
@path = path
load_metadata(path)
end
end
end

0 comments on commit 06158fc

Please sign in to comment.