Extracted `read_directories` from site.rb into reader.rb

- Extracted
  - Updated References
  - Ran Tests

Signed-off-by: Martin Jorn Rogalla <martin@martinrogalla.com
This commit is contained in:
Martin Jorn Rogalla 2015-03-04 20:51:26 +01:00
parent 9bcad08e3a
commit 2857350df1
3 changed files with 36 additions and 36 deletions

View File

@ -74,6 +74,39 @@ module Jekyll
end
end
# Recursively traverse directories to find posts, pages and static files
# that will become part of the site according to the rules in
# filter_entries.
#
# dir - The String relative path of the directory to read. Default: ''.
#
# Returns nothing.
def read_directories(dir = '')
base = 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.sort!
limit_posts() if site.limit_posts > 0 # limit the posts if :limit_posts option is set
entries.each do |f|
f_abs = in_source_dir(base, f)
if File.directory?(f_abs)
f_rel = File.join(dir, f)
read_directories(f_rel) unless site.dest.sub(/\/$/, '') == f_abs
elsif Utils.has_yaml_header?(f_abs)
page = Page.new(site, site.source, dir, f)
site.pages << page if site.publisher.publish?(page)
else
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.
#

View File

@ -130,44 +130,11 @@ module Jekyll
# Returns nothing.
def read
self.layouts = LayoutReader.new(self).read
read_directories
reader.read_directories
reader.read_data(config['data_source'])
read_collections
end
# Recursively traverse directories to find posts, pages and static files
# that will become part of the site according to the rules in
# filter_entries.
#
# dir - The String relative path of the directory to read. Default: ''.
#
# Returns nothing.
def read_directories(dir = '')
base = reader.in_source_dir(dir)
entries = Dir.chdir(base) { reader.filter_entries(Dir.entries('.'), base) }
reader.read_posts(dir)
reader.read_drafts(dir) if show_drafts
posts.sort!
reader.limit_posts() if limit_posts > 0 # limit the posts if :limit_posts option is set
entries.each do |f|
f_abs = reader.in_source_dir(base, f)
if File.directory?(f_abs)
f_rel = File.join(dir, f)
read_directories(f_rel) unless dest.sub(/\/$/, '') == f_abs
elsif Utils.has_yaml_header?(f_abs)
page = Page.new(self, source, dir, f)
pages << page if publisher.publish?(page)
else
static_files << StaticFile.new(self, source, dir, f)
end
end
pages.sort_by!(&:name)
static_files.sort_by!(&:relative_path)
end
# Read in all collections specified in the configuration
#
# Returns nothing.

View File

@ -62,7 +62,7 @@ class TestEntryFilter < JekyllUnitTest
should "not include symlinks in safe mode" do
site = Site.new(site_configuration('safe' => true))
site.read_directories("symlink-test")
site.reader.read_directories("symlink-test")
assert_equal [], site.pages
assert_equal [], site.static_files
end
@ -70,7 +70,7 @@ class TestEntryFilter < JekyllUnitTest
should "include symlinks in unsafe mode" do
site = Site.new(site_configuration)
site.read_directories("symlink-test")
site.reader.read_directories("symlink-test")
refute_equal [], site.pages
refute_equal [], site.static_files
end