Add ExcerptDrop and remove excerpt's ability to refer to itself in Liquid
This commit is contained in:
parent
e02049727b
commit
b019234007
|
@ -3,7 +3,7 @@
|
||||||
module Jekyll
|
module Jekyll
|
||||||
module Drops
|
module Drops
|
||||||
class Drop < Liquid::Drop
|
class Drop < Liquid::Drop
|
||||||
NON_CONTENT_METHODS = [:[], :[]=, :inspect, :to_h, :fallback_data].freeze
|
NON_CONTENT_METHODS = [:[], :[]=, :inspect, :to_h, :fallback_data, :to_s].freeze
|
||||||
|
|
||||||
# Get or set whether the drop class is mutable.
|
# Get or set whether the drop class is mutable.
|
||||||
# Mutability determines whether or not pre-defined fields may be
|
# Mutability determines whether or not pre-defined fields may be
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
# encoding: UTF-8
|
||||||
|
|
||||||
|
module Jekyll
|
||||||
|
module Drops
|
||||||
|
class ExcerptDrop < DocumentDrop
|
||||||
|
def excerpt
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -7,7 +7,7 @@ module Jekyll
|
||||||
attr_writer :output
|
attr_writer :output
|
||||||
|
|
||||||
def_delegators :@doc, :site, :name, :ext, :relative_path, :extname,
|
def_delegators :@doc, :site, :name, :ext, :relative_path, :extname,
|
||||||
:render_with_liquid?, :collection, :related_posts
|
:render_with_liquid?, :collection, :related_posts, :url
|
||||||
|
|
||||||
# Initialize this Excerpt instance.
|
# Initialize this Excerpt instance.
|
||||||
#
|
#
|
||||||
|
@ -59,10 +59,7 @@ module Jekyll
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_liquid
|
def to_liquid
|
||||||
doc.data['excerpt'] = nil
|
Jekyll::Drops::ExcerptDrop.new(self)
|
||||||
@to_liquid ||= doc.to_liquid
|
|
||||||
doc.data['excerpt'] = self
|
|
||||||
@to_liquid
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns the shorthand String identifier of this doc.
|
# Returns the shorthand String identifier of this doc.
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
require 'helper'
|
||||||
|
|
||||||
|
class TestExcerptDrop < JekyllUnitTest
|
||||||
|
context "an excerpt drop" do
|
||||||
|
setup do
|
||||||
|
@site = fixture_site
|
||||||
|
@site.read
|
||||||
|
@doc = @site.docs_to_write.first
|
||||||
|
@doc_drop = @doc.to_liquid
|
||||||
|
@excerpt = @doc.data['excerpt']
|
||||||
|
@excerpt_drop = @excerpt.to_liquid
|
||||||
|
end
|
||||||
|
|
||||||
|
should "have the right thing" do
|
||||||
|
assert @doc.is_a? Jekyll::Document
|
||||||
|
assert @doc_drop.is_a? Jekyll::Drops::DocumentDrop
|
||||||
|
assert @excerpt.is_a? Jekyll::Excerpt
|
||||||
|
assert @excerpt_drop.is_a? Jekyll::Drops::ExcerptDrop
|
||||||
|
end
|
||||||
|
|
||||||
|
should "not have an excerpt" do
|
||||||
|
assert_nil @excerpt.data['excerpt']
|
||||||
|
assert @excerpt_drop.class.invokable? 'excerpt'
|
||||||
|
assert_nil @excerpt_drop['excerpt']
|
||||||
|
end
|
||||||
|
|
||||||
|
should "inherit values from the document" do
|
||||||
|
assert_equal @excerpt_drop.keys, @doc_drop.keys
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue