Skip to content

Commit

Permalink
Merge branch 'pathawks-readers'
Browse files Browse the repository at this point in the history
* pathawks-readers:
  I will chain blocks if I want to chain blocks.
  Rubocop: Readers
  Rubocop: lib/jekyll/readers/static_file_reader.rb
  Rubocop: lib/jekyll/readers/post_reader.rb
  Rubocop: lib/jekyll/readers/page_reader.rb
  Rubocop: lib/jekyll/readers/layout_reader.rb
  Rubocop: lib/jekyll/reader.rb
  • Loading branch information
parkr committed May 26, 2016
2 parents 7a02f29 + 3a3405f commit 35b3c91
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 31 deletions.
5 changes: 0 additions & 5 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ AllCops:
- lib/jekyll/document.rb
- lib/jekyll/filters.rb
- lib/jekyll/frontmatter_defaults.rb
- lib/jekyll/reader.rb
- lib/jekyll/readers/layout_reader.rb
- lib/jekyll/readers/page_reader.rb
- lib/jekyll/readers/post_reader.rb
- lib/jekyll/readers/static_file_reader.rb
- lib/jekyll/regenerator.rb
- lib/jekyll/renderer.rb
- lib/jekyll/site.rb
Expand Down
18 changes: 11 additions & 7 deletions lib/jekyll/reader.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# encoding: UTF-8
require 'csv'
require "csv"

module Jekyll
class Reader
Expand All @@ -16,7 +16,7 @@ def read
@site.layouts = LayoutReader.new(site).read
read_directories
sort_files!
@site.data = DataReader.new(site).read(site.config['data_dir'])
@site.data = DataReader.new(site).read(site.config["data_dir"])
CollectionReader.new(site).read
end

Expand All @@ -34,13 +34,15 @@ def sort_files!
# dir - The String relative path of the directory to read. Default: ''.
#
# Returns nothing.
def read_directories(dir = '')
def read_directories(dir = "")
base = site.in_source_dir(dir)

dot = Dir.chdir(base) { filter_entries(Dir.entries('.'), base) }
dot = Dir.chdir(base) { filter_entries(Dir.entries("."), base) }
dot_dirs = dot.select { |file| File.directory?(@site.in_source_dir(base, file)) }
dot_files = (dot - dot_dirs)
dot_pages = dot_files.select { |file| Utils.has_yaml_header?(@site.in_source_dir(base, file)) }
dot_pages = dot_files.select do |file|
Utils.has_yaml_header?(@site.in_source_dir(base, file))
end
dot_static_files = dot_files - dot_pages

retrieve_posts(dir)
Expand Down Expand Up @@ -71,7 +73,9 @@ def retrieve_dirs(_base, dir, dot_dirs)
dot_dirs.map do |file|
dir_path = site.in_source_dir(dir, file)
rel_path = File.join(dir, file)
@site.reader.read_directories(rel_path) unless @site.dest.sub(/\/$/, '') == dir_path
unless @site.dest.sub(%r!/$!, "") == dir_path
@site.reader.read_directories(rel_path)
end
end
end

Expand Down Expand Up @@ -119,7 +123,7 @@ def filter_entries(entries, base_directory = nil)
def get_entries(dir, subfolder)
base = site.in_source_dir(dir, subfolder)
return [] unless File.exist?(base)
entries = Dir.chdir(base) { filter_entries(Dir['**/*'], base) }
entries = Dir.chdir(base) { filter_entries(Dir["**/*"], base) }
entries.delete_if { |e| File.directory?(site.in_source_dir(base, e)) }
end
end
Expand Down
14 changes: 7 additions & 7 deletions lib/jekyll/readers/layout_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ def initialize(site)

def read
layout_entries.each do |layout_file|
@layouts[layout_name(layout_file)] = Layout.new(site, layout_directory, layout_file)
@layouts[layout_name(layout_file)] = \
Layout.new(site, layout_directory, layout_file)
end

theme_layout_entries.each do |layout_file|
@layouts[layout_name(layout_file)] ||= Layout.new(site, theme_layout_directory, layout_file)
@layouts[layout_name(layout_file)] ||= \
Layout.new(site, theme_layout_directory, layout_file)
end

@layouts
Expand All @@ -39,7 +41,7 @@ def theme_layout_entries
def entries_in(dir)
entries = []
within(dir) do
entries = EntryFilter.new(site).filter(Dir['**/*.*'])
entries = EntryFilter.new(site).filter(Dir["**/*.*"])
end
entries
end
Expand All @@ -54,15 +56,13 @@ def within(directory)
end

def layout_directory_inside_source
site.in_source_dir(site.config['layouts_dir'])
site.in_source_dir(site.config["layouts_dir"])
end

def layout_directory_in_cwd
dir = Jekyll.sanitized_path(Dir.pwd, site.config['layouts_dir'])
dir = Jekyll.sanitized_path(Dir.pwd, site.config["layouts_dir"])
if File.directory?(dir) && !site.safe
dir
else
nil
end
end
end
Expand Down
4 changes: 3 additions & 1 deletion lib/jekyll/readers/page_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ def initialize(site, dir)
#
# Returns an array of static pages.
def read(files)
files.map { |page| @unfiltered_content << Page.new(@site, @site.source, @dir, page) }
files.map do |page|
@unfiltered_content << Page.new(@site, @site.source, @dir, page)
end
@unfiltered_content.select { |page| site.publisher.publish?(page) }
end
end
Expand Down
19 changes: 9 additions & 10 deletions lib/jekyll/readers/post_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def initialize(site)
#
# Returns nothing.
def read_drafts(dir)
read_publishable(dir, '_drafts', Document::DATELESS_FILENAME_MATCHER)
read_publishable(dir, "_drafts", Document::DATELESS_FILENAME_MATCHER)
end

# Read all the files in <source>/<dir>/_posts and create a new Document
Expand All @@ -22,7 +22,7 @@ def read_drafts(dir)
#
# Returns nothing.
def read_posts(dir)
read_publishable(dir, '_posts', Document::DATE_FILENAME_MATCHER)
read_publishable(dir, "_posts", Document::DATE_FILENAME_MATCHER)
end

# Read all the files in <source>/<dir>/<magic_dir> and create a new
Expand All @@ -32,15 +32,14 @@ def read_posts(dir)
#
# Returns nothing.
def read_publishable(dir, magic_dir, matcher)
read_content(dir, magic_dir, matcher).tap do |docs|
docs.each(&:read)
end.select do |doc|
site.publisher.publish?(doc).tap do |will_publish|
if !will_publish && site.publisher.hidden_in_the_future?(doc)
Jekyll.logger.debug "Skipping:", "#{doc.relative_path} has a future date"
read_content(dir, magic_dir, matcher).tap { |docs| docs.each(&:read) }
.select do |doc|
site.publisher.publish?(doc).tap do |will_publish|
if !will_publish && site.publisher.hidden_in_the_future?(doc)
Jekyll.logger.debug "Skipping:", "#{doc.relative_path} has a future date"
end
end
end
end
end

# Read all the content files from <source>/<dir>/magic_dir
Expand All @@ -57,7 +56,7 @@ def read_content(dir, magic_dir, matcher)
next unless entry =~ matcher
path = @site.in_source_dir(File.join(dir, magic_dir, entry))
Document.new(path, {
:site => @site,
:site => @site,
:collection => @site.posts
})
end.reject(&:nil?)
Expand Down
4 changes: 3 additions & 1 deletion lib/jekyll/readers/static_file_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ def initialize(site, dir)
#
# Returns an array of static files.
def read(files)
files.map { |file| @unfiltered_content << StaticFile.new(@site, @site.source, @dir, file) }
files.map do |file|
@unfiltered_content << StaticFile.new(@site, @site.source, @dir, file)
end
@unfiltered_content
end
end
Expand Down

0 comments on commit 35b3c91

Please sign in to comment.