Skip to content

Commit

Permalink
Use Liquid drop to expose attributes to templates (#158)
Browse files Browse the repository at this point in the history
Merge pull request 158
  • Loading branch information
ashmaroli authored Dec 16, 2022
1 parent 9d3d3cb commit 2ba867d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/jekyll-archives.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
module Jekyll
module Archives
# Internal requires
autoload :Archive, "jekyll-archives/archive"
autoload :VERSION, "jekyll-archives/version"
autoload :Archive, "jekyll-archives/archive"
autoload :PageDrop, "jekyll-archives/page_drop"
autoload :VERSION, "jekyll-archives/version"

class Archives < Jekyll::Generator
safe true
Expand Down
5 changes: 5 additions & 0 deletions lib/jekyll-archives/archive.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ def inspect
"#<Jekyll:Archive @type=#{@type} @title=#{@title} @data=#{@data.inspect}>"
end

# The Liquid representation of this page.
def to_liquid
@to_liquid ||= Jekyll::Archives::PageDrop.new(self)
end

private

# Generate slug if @title attribute is a string.
Expand Down
14 changes: 14 additions & 0 deletions lib/jekyll-archives/page_drop.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

module Jekyll
module Archives
class PageDrop < Jekyll::Drops::Drop
extend Forwardable

mutable false

def_delegators :@obj, :posts, :type, :title, :date, :name, :path, :url, :permalink
private def_delegator :@obj, :data, :fallback_data
end
end
end

0 comments on commit 2ba867d

Please sign in to comment.