Merge branch 'pathawks-fp/ExcerptDrop'
* pathawks-fp/ExcerptDrop: Rubocop fixes excerpt drop should give access to document's layout look up the content methods for drops in a smarter way Use require_relative Add ExcerptDrop and remove excerpt's ability to refer to itself in Liquid
This commit is contained in:
commit
10543e7c46
|
@ -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 = [:fallback_data].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
|
||||||
|
@ -86,7 +86,7 @@ module Jekyll
|
||||||
# Returns an Array of strings which represent method-specific keys.
|
# Returns an Array of strings which represent method-specific keys.
|
||||||
def content_methods
|
def content_methods
|
||||||
@content_methods ||= (
|
@content_methods ||= (
|
||||||
self.class.instance_methods(false) - NON_CONTENT_METHODS
|
self.class.instance_methods - Jekyll::Drops::Drop.instance_methods - NON_CONTENT_METHODS
|
||||||
).map(&:to_s).reject do |method|
|
).map(&:to_s).reject do |method|
|
||||||
method.end_with?("=")
|
method.end_with?("=")
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
# encoding: UTF-8
|
||||||
|
|
||||||
|
module Jekyll
|
||||||
|
module Drops
|
||||||
|
class ExcerptDrop < DocumentDrop
|
||||||
|
def layout
|
||||||
|
@obj.doc.data["layout"]
|
||||||
|
end
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
|
@ -28,7 +28,7 @@ require "minitest/autorun"
|
||||||
require "minitest/reporters"
|
require "minitest/reporters"
|
||||||
require "minitest/profile"
|
require "minitest/profile"
|
||||||
require "rspec/mocks"
|
require "rspec/mocks"
|
||||||
require "jekyll"
|
require_relative "../lib/jekyll.rb"
|
||||||
|
|
||||||
Jekyll.logger = Logger.new(StringIO.new)
|
Jekyll.logger = Logger.new(StringIO.new)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
require "helper"
|
||||||
|
|
||||||
|
class TestExcerptDrop < JekyllUnitTest
|
||||||
|
context "an excerpt drop" do
|
||||||
|
setup do
|
||||||
|
@site = fixture_site
|
||||||
|
@site.read
|
||||||
|
@doc = @site.docs_to_write.find { |d| !d.data["layout"].nil? }
|
||||||
|
@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 the layout for the drop but not the excerpt" do
|
||||||
|
assert_nil @excerpt.data["layout"]
|
||||||
|
assert_equal @excerpt_drop["layout"], @doc_drop["layout"]
|
||||||
|
end
|
||||||
|
|
||||||
|
should "inherit values from the document" do
|
||||||
|
assert_equal @excerpt_drop.keys.sort, @doc_drop.keys.sort
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue