Extracted `in_source_dir` from site.rb and into reader.rb.
Extracted `in_source_dir` from site.rb into reader.rb. Updated all the references and tests. Signed-off-by: Martin Jorn Rogalla <martin@martinrogalla.com>
This commit is contained in:
parent
5e9b7343bf
commit
bb9d43dff5
|
@ -55,6 +55,7 @@ module Jekyll
|
||||||
autoload :PluginManager, 'jekyll/plugin_manager'
|
autoload :PluginManager, 'jekyll/plugin_manager'
|
||||||
autoload :Post, 'jekyll/post'
|
autoload :Post, 'jekyll/post'
|
||||||
autoload :Publisher, 'jekyll/publisher'
|
autoload :Publisher, 'jekyll/publisher'
|
||||||
|
autoload :Reader, 'jekyll/reader'
|
||||||
autoload :Regenerator, 'jekyll/regenerator'
|
autoload :Regenerator, 'jekyll/regenerator'
|
||||||
autoload :RelatedPosts, 'jekyll/related_posts'
|
autoload :RelatedPosts, 'jekyll/related_posts'
|
||||||
autoload :Renderer, 'jekyll/renderer'
|
autoload :Renderer, 'jekyll/renderer'
|
||||||
|
|
|
@ -89,7 +89,7 @@ module Jekyll
|
||||||
# Returns a String containing th directory name where the collection
|
# Returns a String containing th directory name where the collection
|
||||||
# is stored on the filesystem.
|
# is stored on the filesystem.
|
||||||
def directory
|
def directory
|
||||||
@directory ||= site.in_source_dir(relative_directory)
|
@directory ||= site.reader.in_source_dir(relative_directory)
|
||||||
end
|
end
|
||||||
|
|
||||||
# The full path to the directory containing the collection, with
|
# The full path to the directory containing the collection, with
|
||||||
|
@ -102,7 +102,7 @@ module Jekyll
|
||||||
# is stored on the filesystem.
|
# is stored on the filesystem.
|
||||||
def collection_dir(*files)
|
def collection_dir(*files)
|
||||||
return directory if files.empty?
|
return directory if files.empty?
|
||||||
site.in_source_dir(relative_directory, *files)
|
site.reader.in_source_dir(relative_directory, *files)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Checks whether the directory "exists" for this collection.
|
# Checks whether the directory "exists" for this collection.
|
||||||
|
|
|
@ -43,7 +43,7 @@ module Jekyll
|
||||||
# Returns nothing.
|
# Returns nothing.
|
||||||
def read_yaml(base, name, opts = {})
|
def read_yaml(base, name, opts = {})
|
||||||
begin
|
begin
|
||||||
self.content = File.read(site.in_source_dir(base, name),
|
self.content = File.read(site.reader.in_source_dir(base, name),
|
||||||
merged_file_read_opts(opts))
|
merged_file_read_opts(opts))
|
||||||
if content =~ /\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)/m
|
if content =~ /\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)/m
|
||||||
self.content = $POSTMATCH
|
self.content = $POSTMATCH
|
||||||
|
@ -209,8 +209,8 @@ module Jekyll
|
||||||
|
|
||||||
# Add layout to dependency tree
|
# Add layout to dependency tree
|
||||||
site.regenerator.add_dependency(
|
site.regenerator.add_dependency(
|
||||||
site.in_source_dir(path),
|
site.reader.in_source_dir(path),
|
||||||
site.in_source_dir(layout.path)
|
site.reader.in_source_dir(layout.path)
|
||||||
)
|
)
|
||||||
|
|
||||||
if layout = layouts[layout.data["layout"]]
|
if layout = layouts[layout.data["layout"]]
|
||||||
|
|
|
@ -15,7 +15,7 @@ module Jekyll
|
||||||
|
|
||||||
# Get the full path to the directory containing the draft files
|
# Get the full path to the directory containing the draft files
|
||||||
def containing_dir(dir)
|
def containing_dir(dir)
|
||||||
site.in_source_dir(dir, '_drafts')
|
site.reader.in_source_dir(dir, '_drafts')
|
||||||
end
|
end
|
||||||
|
|
||||||
# The path to the draft source file, relative to the site source
|
# The path to the draft source file, relative to the site source
|
||||||
|
|
|
@ -29,7 +29,7 @@ module Jekyll
|
||||||
@site = site
|
@site = site
|
||||||
@base = base
|
@base = base
|
||||||
@name = name
|
@name = name
|
||||||
@path = site.in_source_dir(base, name)
|
@path = site.reader.in_source_dir(base, name)
|
||||||
|
|
||||||
self.data = {}
|
self.data = {}
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ module Jekyll
|
||||||
end
|
end
|
||||||
|
|
||||||
def layout_directory_inside_source
|
def layout_directory_inside_source
|
||||||
site.in_source_dir(site.config['layouts'])
|
site.reader.in_source_dir(site.config['layouts'])
|
||||||
end
|
end
|
||||||
|
|
||||||
def layout_directory_in_cwd
|
def layout_directory_in_cwd
|
||||||
|
|
|
@ -82,7 +82,7 @@ module Jekyll
|
||||||
# Returns an Array of plugin search paths
|
# Returns an Array of plugin search paths
|
||||||
def plugins_path
|
def plugins_path
|
||||||
if (site.config['plugins'] == Jekyll::Configuration::DEFAULTS['plugins'])
|
if (site.config['plugins'] == Jekyll::Configuration::DEFAULTS['plugins'])
|
||||||
[site.in_source_dir(site.config['plugins'])]
|
[site.reader.in_source_dir(site.config['plugins'])]
|
||||||
else
|
else
|
||||||
Array(site.config['plugins']).map { |d| File.expand_path(d) }
|
Array(site.config['plugins']).map { |d| File.expand_path(d) }
|
||||||
end
|
end
|
||||||
|
|
|
@ -91,7 +91,7 @@ module Jekyll
|
||||||
|
|
||||||
# Get the full path to the directory containing the post files
|
# Get the full path to the directory containing the post files
|
||||||
def containing_dir(dir)
|
def containing_dir(dir)
|
||||||
site.in_source_dir(dir, '_posts')
|
site.reader.in_source_dir(dir, '_posts')
|
||||||
end
|
end
|
||||||
|
|
||||||
# Read the YAML frontmatter.
|
# Read the YAML frontmatter.
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
# encoding: UTF-8
|
||||||
|
require 'csv'
|
||||||
|
|
||||||
|
module Jekyll
|
||||||
|
class Reader
|
||||||
|
# Public: Initialize a new Reader.
|
||||||
|
|
||||||
|
# @return [Object]
|
||||||
|
def initialize(source, dest)
|
||||||
|
@source = source
|
||||||
|
@dest = dest
|
||||||
|
end
|
||||||
|
|
||||||
|
# Public: Prefix a given path with the source directory.
|
||||||
|
#
|
||||||
|
# paths - (optional) path elements to a file or directory within the
|
||||||
|
# source directory
|
||||||
|
#
|
||||||
|
# Returns a path which is prefixed with the source directory.
|
||||||
|
def in_source_dir(*paths)
|
||||||
|
paths.reduce(@source) do |base, path|
|
||||||
|
Jekyll.sanitized_path(base, path)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Public: Prefix a given path with the destination directory.
|
||||||
|
#
|
||||||
|
# paths - (optional) path elements to a file or directory within the
|
||||||
|
# destination directory
|
||||||
|
#
|
||||||
|
# Returns a path which is prefixed with the destination directory.
|
||||||
|
def in_dest_dir(*paths)
|
||||||
|
paths.reduce(@dest) do |base, path|
|
||||||
|
Jekyll.sanitized_path(base, path)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -19,7 +19,7 @@ module Jekyll
|
||||||
case document
|
case document
|
||||||
when Post, Page
|
when Post, Page
|
||||||
document.asset_file? || document.data['regenerate'] ||
|
document.asset_file? || document.data['regenerate'] ||
|
||||||
modified?(site.in_source_dir(document.relative_path))
|
modified?(site.reader.in_source_dir(document.relative_path))
|
||||||
when Document
|
when Document
|
||||||
!document.write? || document.data['regenerate'] || modified?(document.path)
|
!document.write? || document.data['regenerate'] || modified?(document.path)
|
||||||
else
|
else
|
||||||
|
@ -113,7 +113,7 @@ module Jekyll
|
||||||
#
|
#
|
||||||
# Returns the String path of the file.
|
# Returns the String path of the file.
|
||||||
def metadata_file
|
def metadata_file
|
||||||
site.in_source_dir('.jekyll-metadata')
|
site.reader.in_source_dir('.jekyll-metadata')
|
||||||
end
|
end
|
||||||
|
|
||||||
# Check if metadata has been disabled
|
# Check if metadata has been disabled
|
||||||
|
|
|
@ -141,8 +141,8 @@ module Jekyll
|
||||||
|
|
||||||
# Add layout to dependency tree
|
# Add layout to dependency tree
|
||||||
site.regenerator.add_dependency(
|
site.regenerator.add_dependency(
|
||||||
site.in_source_dir(document.path),
|
site.reader.in_source_dir(document.path),
|
||||||
site.in_source_dir(layout.path)
|
site.reader.in_source_dir(layout.path)
|
||||||
) if document.write?
|
) if document.write?
|
||||||
|
|
||||||
if layout = site.layouts[layout.data["layout"]]
|
if layout = site.layouts[layout.data["layout"]]
|
||||||
|
|
|
@ -10,7 +10,7 @@ module Jekyll
|
||||||
:show_drafts, :keep_files, :baseurl, :data, :file_read_opts,
|
:show_drafts, :keep_files, :baseurl, :data, :file_read_opts,
|
||||||
:gems, :plugin_manager
|
:gems, :plugin_manager
|
||||||
|
|
||||||
attr_accessor :converters, :generators
|
attr_accessor :converters, :generators, :reader
|
||||||
attr_reader :regenerator
|
attr_reader :regenerator
|
||||||
|
|
||||||
# Public: Initialize a new Site.
|
# Public: Initialize a new Site.
|
||||||
|
@ -28,6 +28,8 @@ module Jekyll
|
||||||
@source = File.expand_path(config['source']).freeze
|
@source = File.expand_path(config['source']).freeze
|
||||||
@dest = File.expand_path(config['destination']).freeze
|
@dest = File.expand_path(config['destination']).freeze
|
||||||
|
|
||||||
|
@reader = Reader.new(@source,@dest);
|
||||||
|
|
||||||
# Initialize incremental regenerator
|
# Initialize incremental regenerator
|
||||||
@regenerator = Regenerator.new(self)
|
@regenerator = Regenerator.new(self)
|
||||||
|
|
||||||
|
@ -97,18 +99,6 @@ module Jekyll
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Public: Prefix a given path with the source directory.
|
|
||||||
#
|
|
||||||
# paths - (optional) path elements to a file or directory within the
|
|
||||||
# source directory
|
|
||||||
#
|
|
||||||
# Returns a path which is prefixed with the source directory.
|
|
||||||
def in_source_dir(*paths)
|
|
||||||
paths.reduce(source) do |base, path|
|
|
||||||
Jekyll.sanitized_path(base, path)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Public: Prefix a given path with the destination directory.
|
# Public: Prefix a given path with the destination directory.
|
||||||
#
|
#
|
||||||
# paths - (optional) path elements to a file or directory within the
|
# paths - (optional) path elements to a file or directory within the
|
||||||
|
@ -116,9 +106,7 @@ module Jekyll
|
||||||
#
|
#
|
||||||
# Returns a path which is prefixed with the destination directory.
|
# Returns a path which is prefixed with the destination directory.
|
||||||
def in_dest_dir(*paths)
|
def in_dest_dir(*paths)
|
||||||
paths.reduce(dest) do |base, path|
|
reader.in_dest_dir(*paths)
|
||||||
Jekyll.sanitized_path(base, path)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# The list of collections and their corresponding Jekyll::Collection instances.
|
# The list of collections and their corresponding Jekyll::Collection instances.
|
||||||
|
@ -165,7 +153,7 @@ module Jekyll
|
||||||
#
|
#
|
||||||
# Returns nothing.
|
# Returns nothing.
|
||||||
def read_directories(dir = '')
|
def read_directories(dir = '')
|
||||||
base = in_source_dir(dir)
|
base = reader.in_source_dir(dir)
|
||||||
entries = Dir.chdir(base) { filter_entries(Dir.entries('.'), base) }
|
entries = Dir.chdir(base) { filter_entries(Dir.entries('.'), base) }
|
||||||
|
|
||||||
read_posts(dir)
|
read_posts(dir)
|
||||||
|
@ -174,7 +162,7 @@ module Jekyll
|
||||||
limit_posts! if limit_posts > 0 # limit the posts if :limit_posts option is set
|
limit_posts! if limit_posts > 0 # limit the posts if :limit_posts option is set
|
||||||
|
|
||||||
entries.each do |f|
|
entries.each do |f|
|
||||||
f_abs = in_source_dir(base, f)
|
f_abs = reader.in_source_dir(base, f)
|
||||||
if File.directory?(f_abs)
|
if File.directory?(f_abs)
|
||||||
f_rel = File.join(dir, f)
|
f_rel = File.join(dir, f)
|
||||||
read_directories(f_rel) unless dest.sub(/\/$/, '') == f_abs
|
read_directories(f_rel) unless dest.sub(/\/$/, '') == f_abs
|
||||||
|
@ -232,7 +220,7 @@ module Jekyll
|
||||||
#
|
#
|
||||||
# Returns nothing
|
# Returns nothing
|
||||||
def read_data(dir)
|
def read_data(dir)
|
||||||
base = in_source_dir(dir)
|
base = reader.in_source_dir(dir)
|
||||||
read_data_to(base, self.data)
|
read_data_to(base, self.data)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -251,7 +239,7 @@ module Jekyll
|
||||||
end
|
end
|
||||||
|
|
||||||
entries.each do |entry|
|
entries.each do |entry|
|
||||||
path = in_source_dir(dir, entry)
|
path = reader.in_source_dir(dir, entry)
|
||||||
next if File.symlink?(path) && safe
|
next if File.symlink?(path) && safe
|
||||||
|
|
||||||
key = sanitize_filename(File.basename(entry, '.*'))
|
key = sanitize_filename(File.basename(entry, '.*'))
|
||||||
|
@ -454,10 +442,10 @@ module Jekyll
|
||||||
#
|
#
|
||||||
# Returns the list of entries to process
|
# Returns the list of entries to process
|
||||||
def get_entries(dir, subfolder)
|
def get_entries(dir, subfolder)
|
||||||
base = in_source_dir(dir, subfolder)
|
base = reader.in_source_dir(dir, subfolder)
|
||||||
return [] unless File.exist?(base)
|
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?(in_source_dir(base, e)) }
|
entries.delete_if { |e| File.directory?(reader.in_source_dir(base, e)) }
|
||||||
end
|
end
|
||||||
|
|
||||||
# Aggregate post information
|
# Aggregate post information
|
||||||
|
|
|
@ -117,7 +117,7 @@ eos
|
||||||
# Add include to dependency tree
|
# Add include to dependency tree
|
||||||
if context.registers[:page] and context.registers[:page].has_key? "path"
|
if context.registers[:page] and context.registers[:page].has_key? "path"
|
||||||
site.regenerator.add_dependency(
|
site.regenerator.add_dependency(
|
||||||
site.in_source_dir(context.registers[:page]["path"]),
|
site.reader.in_source_dir(context.registers[:page]["path"]),
|
||||||
path
|
path
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
@ -135,7 +135,7 @@ eos
|
||||||
end
|
end
|
||||||
|
|
||||||
def resolved_includes_dir(context)
|
def resolved_includes_dir(context)
|
||||||
context.registers[:site].in_source_dir(@includes_dir)
|
context.registers[:site].reader.in_source_dir(@includes_dir)
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate_path(path, dir, safe)
|
def validate_path(path, dir, safe)
|
||||||
|
@ -170,7 +170,7 @@ eos
|
||||||
end
|
end
|
||||||
|
|
||||||
def resolved_includes_dir(context)
|
def resolved_includes_dir(context)
|
||||||
context.registers[:site].in_source_dir(page_path(context))
|
context.registers[:site].reader.in_source_dir(page_path(context))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -63,7 +63,7 @@ class TestRegenerator < JekyllUnitTest
|
||||||
}))
|
}))
|
||||||
|
|
||||||
@site.process
|
@site.process
|
||||||
@path = @site.in_source_dir(@site.pages.first.path)
|
@path = @site.reader.in_source_dir(@site.pages.first.path)
|
||||||
@regenerator = @site.regenerator
|
@regenerator = @site.regenerator
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue