Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

override EXCERPT_ATTRIBUTES_FOR_LIQUID #2408

Merged
merged 1 commit into from
May 15, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/jekyll/excerpt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def initialize(post)
end

def to_liquid
post.to_liquid(Post::EXCERPT_ATTRIBUTES_FOR_LIQUID)
post.to_liquid(post.class::EXCERPT_ATTRIBUTES_FOR_LIQUID)
end

# Fetch YAML front-matter data from related post, without layout key
Expand Down
2 changes: 1 addition & 1 deletion lib/jekyll/post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def render(layouts, site_payload)
# construct payload
payload = Utils.deep_merge_hashes({
"site" => { "related_posts" => related_posts(site_payload["site"]["posts"]) },
"page" => to_liquid(EXCERPT_ATTRIBUTES_FOR_LIQUID)
"page" => to_liquid(self.class::EXCERPT_ATTRIBUTES_FOR_LIQUID)
}, site_payload)

if generate_excerpt?
Expand Down
11 changes: 11 additions & 0 deletions test/test_excerpt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@ def do_render(post)
assert_equal %w[first second third jekyllrb.com], @excerpt.to_liquid["tags"]
assert_equal "_posts/2013-07-22-post-excerpt-with-layout.markdown", @excerpt.to_liquid["path"]
end

should "consider inheritance" do
klass = Class.new(Jekyll::Post)
assert_gets_called = false
klass.send(:define_method, :assert_gets_called) { assert_gets_called = true }
klass.const_set(:EXCERPT_ATTRIBUTES_FOR_LIQUID, Jekyll::Post::EXCERPT_ATTRIBUTES_FOR_LIQUID + ['assert_gets_called'])
post = klass.new(@site, source_dir, '', "2008-02-02-published.textile")
Jekyll::Excerpt.new(post).to_liquid

assert assert_gets_called, 'assert_gets_called did not get called on post.'
end
end

context "#content" do
Expand Down
11 changes: 11 additions & 0 deletions test/test_post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,17 @@ def do_render(post)
assert_equal Time, post.to_liquid["date"].class
end

should "to_liquid should consider inheritance" do
klass = Class.new(Jekyll::Post)
assert_gets_called = false
klass.send(:define_method, :assert_gets_called) { assert_gets_called = true }
klass.const_set(:EXCERPT_ATTRIBUTES_FOR_LIQUID, Jekyll::Post::EXCERPT_ATTRIBUTES_FOR_LIQUID + ['assert_gets_called'])
post = klass.new(@site, source_dir, '', "2008-02-02-published.textile")
do_render(post)

assert assert_gets_called, 'assert_gets_called did not get called on post.'
end

should "recognize category in yaml" do
post = setup_post("2009-01-27-category.textile")
assert post.categories.include?('foo')
Expand Down