Skip to content

Commit 2ba867d

Browse files
authored
Use Liquid drop to expose attributes to templates (#158)
Merge pull request 158
1 parent 9d3d3cb commit 2ba867d

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

lib/jekyll-archives.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
module Jekyll
66
module Archives
77
# Internal requires
8-
autoload :Archive, "jekyll-archives/archive"
9-
autoload :VERSION, "jekyll-archives/version"
8+
autoload :Archive, "jekyll-archives/archive"
9+
autoload :PageDrop, "jekyll-archives/page_drop"
10+
autoload :VERSION, "jekyll-archives/version"
1011

1112
class Archives < Jekyll::Generator
1213
safe true

lib/jekyll-archives/archive.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ def inspect
120120
"#<Jekyll:Archive @type=#{@type} @title=#{@title} @data=#{@data.inspect}>"
121121
end
122122

123+
# The Liquid representation of this page.
124+
def to_liquid
125+
@to_liquid ||= Jekyll::Archives::PageDrop.new(self)
126+
end
127+
123128
private
124129

125130
# Generate slug if @title attribute is a string.

lib/jekyll-archives/page_drop.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# frozen_string_literal: true
2+
3+
module Jekyll
4+
module Archives
5+
class PageDrop < Jekyll::Drops::Drop
6+
extend Forwardable
7+
8+
mutable false
9+
10+
def_delegators :@obj, :posts, :type, :title, :date, :name, :path, :url, :permalink
11+
private def_delegator :@obj, :data, :fallback_data
12+
end
13+
end
14+
end

0 commit comments

Comments
 (0)