Extracted draft, post reader into external classes.
Organized the draft, post and layout reader into the *readers* classes. Fixed all references and ran tests. Signed-off-by: Martin Jorn Rogalla <martin@martinrogalla.com>
This commit is contained in:
parent
4b8e3cfdbd
commit
bebd80342e
|
@ -49,7 +49,9 @@ module Jekyll
|
|||
autoload :Filters, 'jekyll/filters'
|
||||
autoload :FrontmatterDefaults, 'jekyll/frontmatter_defaults'
|
||||
autoload :Layout, 'jekyll/layout'
|
||||
autoload :LayoutReader, 'jekyll/layout_reader'
|
||||
autoload :LayoutReader, 'jekyll/readers/layout_reader'
|
||||
autoload :DraftReader, 'jekyll/readers/draft_reader'
|
||||
autoload :PostReader, 'jekyll/readers/post_reader'
|
||||
autoload :LogAdapter, 'jekyll/log_adapter'
|
||||
autoload :Page, 'jekyll/page'
|
||||
autoload :PluginManager, 'jekyll/plugin_manager'
|
||||
|
|
|
@ -71,8 +71,12 @@ module Jekyll
|
|||
base = site.in_source_dir(dir)
|
||||
entries = Dir.chdir(base) { filter_entries(Dir.entries('.'), base) }
|
||||
|
||||
read_posts(dir)
|
||||
read_drafts(dir) if site.show_drafts
|
||||
site.posts += PostReader.new(site).read(dir)
|
||||
|
||||
if site.show_drafts
|
||||
site.posts += DraftReader.new(site).read(dir)
|
||||
end
|
||||
|
||||
site.posts.sort!
|
||||
limit_posts if site.limit_posts > 0 # limit the posts if :limit_posts option is set
|
||||
|
||||
|
@ -88,41 +92,10 @@ module Jekyll
|
|||
site.static_files << StaticFile.new(site, site.source, dir, f)
|
||||
end
|
||||
end
|
||||
|
||||
site.pages.sort_by!(&:name)
|
||||
site.static_files.sort_by!(&:relative_path)
|
||||
end
|
||||
|
||||
# Read all the files in <source>/<dir>/_posts and create a new Post
|
||||
# object with each one.
|
||||
#
|
||||
# dir - The String relative path of the directory to read.
|
||||
#
|
||||
# Returns nothing.
|
||||
def read_posts(dir)
|
||||
posts = read_content(dir, '_posts', Post)
|
||||
|
||||
posts.each do |post|
|
||||
aggregate_post_info(post) if site.publisher.publish?(post)
|
||||
end
|
||||
end
|
||||
|
||||
# Read all the files in <source>/<dir>/_drafts and create a new Post
|
||||
# object with each one.
|
||||
#
|
||||
# dir - The String relative path of the directory to read.
|
||||
#
|
||||
# Returns nothing.
|
||||
def read_drafts(dir)
|
||||
drafts = read_content(dir, '_drafts', Draft)
|
||||
|
||||
drafts.each do |draft|
|
||||
if draft.published?
|
||||
aggregate_post_info(draft)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Read all the content files from <source>/<dir>/magic_dir
|
||||
# and return them with the type klass.
|
||||
#
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
module Jekyll
|
||||
class DraftReader
|
||||
attr_reader :site, :unfiltered_content
|
||||
def initialize(site)
|
||||
@site = site
|
||||
@unfiltered_content = Array.new
|
||||
end
|
||||
|
||||
# Read all the files in <source>/<dir>/_drafts and create a new Draft
|
||||
# object with each one.
|
||||
#
|
||||
# dir - The String relative path of the directory to read.
|
||||
#
|
||||
# Returns nothing.
|
||||
def read(dir)
|
||||
@unfiltered_content = @site.reader.read_content(dir, '_drafts', Draft)
|
||||
@unfiltered_content.select{ |draft| site.publisher.publish?(draft) }
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,20 @@
|
|||
module Jekyll
|
||||
class PostReader
|
||||
attr_reader :site, :unfiltered_content
|
||||
def initialize(site)
|
||||
@site = site
|
||||
@unfiltered_content = Array.new
|
||||
end
|
||||
|
||||
# Read all the files in <source>/<dir>/_posts and create a new Post
|
||||
# object with each one.
|
||||
#
|
||||
# dir - The String relative path of the directory to read.
|
||||
#
|
||||
# Returns nothing.
|
||||
def read(dir)
|
||||
@unfiltered_content = @site.reader.read_content(dir, '_posts', Post)
|
||||
@unfiltered_content.select{ |post| site.publisher.publish?(post) }
|
||||
end
|
||||
end
|
||||
end
|
|
@ -4,7 +4,7 @@ require 'csv'
|
|||
module Jekyll
|
||||
class Site
|
||||
attr_reader :source, :dest, :config
|
||||
attr_accessor :layouts, :posts, :pages, :static_files,
|
||||
attr_accessor :layouts, :posts, :pages, :static_files, :drafts,
|
||||
:exclude, :include, :lsi, :highlighter, :permalink_style,
|
||||
:time, :future, :unpublished, :safe, :plugins, :limit_posts,
|
||||
:show_drafts, :keep_files, :baseurl, :data, :file_read_opts,
|
||||
|
|
|
@ -189,7 +189,7 @@ class TestSite < JekyllUnitTest
|
|||
end
|
||||
|
||||
should "read posts" do
|
||||
@site.reader.read_posts('')
|
||||
@site.posts += PostReader.new(@site).read('')
|
||||
posts = Dir[source_dir('_posts', '**', '*')]
|
||||
posts.delete_if { |post| File.directory?(post) && !Post.valid?(post) }
|
||||
assert_equal posts.size - @num_invalid_posts, @site.posts.size
|
||||
|
|
|
@ -13,7 +13,7 @@ class TestTags < JekyllUnitTest
|
|||
site = Site.new(Jekyll.configuration)
|
||||
|
||||
if override['read_posts']
|
||||
site.reader.read_posts('')
|
||||
site.posts += PostReader.new(site).read('')
|
||||
end
|
||||
|
||||
info = { :filters => [Jekyll::Filters], :registers => { :site => site } }
|
||||
|
|
Loading…
Reference in New Issue