Use 'Forwardable' module to pass along some attribute calls to @post

This commit is contained in:
Parker Moore 2014-01-10 22:54:06 -08:00
parent 459a4c1e55
commit 5a52986db0
1 changed files with 8 additions and 6 deletions

View File

@ -1,10 +1,18 @@
require 'jekyll/convertible'
require 'forwardable'
module Jekyll module Jekyll
class Excerpt class Excerpt
include Convertible include Convertible
extend Forwardable
attr_accessor :post attr_accessor :post
attr_accessor :content, :output, :ext attr_accessor :content, :output, :ext
def_delegator :@post, :site, :site
def_delegator :@post, :name, :name
def_delegator :@post, :ext, :ext
# Initialize this Post instance. # Initialize this Post instance.
# #
# site - The Site. # site - The Site.
@ -17,12 +25,6 @@ module Jekyll
self.content = extract_excerpt(post.content) self.content = extract_excerpt(post.content)
end end
%w[site name ext].each do |meth|
define_method(meth) do
post.send(meth)
end
end
def to_liquid def to_liquid
post.to_liquid(Post::EXCERPT_ATTRIBUTES_FOR_LIQUID) post.to_liquid(Post::EXCERPT_ATTRIBUTES_FOR_LIQUID)
end end