Moved the in_(source/dest)_dir back to site.rb.
After carefully looking at these two methods, as of right now they do not belong in the reader, as they should also be used by the writer. Thus the decision was made to move them back into the class containing the source and dest fields, site.rb. Signed-off-by: Martin Jorn Rogalla <martin@martinrogalla.com>
This commit is contained in:
parent
9e1cb96a7e
commit
4b8e3cfdbd
|
@ -36,7 +36,7 @@ module Jekyll
|
|||
# Returns a Set with the file paths
|
||||
def existing_files
|
||||
files = Set.new
|
||||
Dir.glob(site.reader.in_dest_dir("**", "*"), File::FNM_DOTMATCH) do |file|
|
||||
Dir.glob(site.in_dest_dir("**", "*"), File::FNM_DOTMATCH) do |file|
|
||||
files << file unless file =~ /\/\.{1,2}$/ || file =~ keep_file_regex || keep_dirs.include?(file)
|
||||
end
|
||||
files
|
||||
|
@ -83,7 +83,7 @@ module Jekyll
|
|||
#
|
||||
# Returns a Set with the directory paths
|
||||
def keep_dirs
|
||||
site.keep_files.map { |file| parent_dirs(site.reader.in_dest_dir(file)) }.flatten.to_set
|
||||
site.keep_files.map { |file| parent_dirs(site.in_dest_dir(file)) }.flatten.to_set
|
||||
end
|
||||
|
||||
# Private: Creates a regular expression from the config's keep_files array
|
||||
|
|
|
@ -89,7 +89,7 @@ module Jekyll
|
|||
# Returns a String containing th directory name where the collection
|
||||
# is stored on the filesystem.
|
||||
def directory
|
||||
@directory ||= site.reader.in_source_dir(relative_directory)
|
||||
@directory ||= site.in_source_dir(relative_directory)
|
||||
end
|
||||
|
||||
# The full path to the directory containing the collection, with
|
||||
|
@ -102,7 +102,7 @@ module Jekyll
|
|||
# is stored on the filesystem.
|
||||
def collection_dir(*files)
|
||||
return directory if files.empty?
|
||||
site.reader.in_source_dir(relative_directory, *files)
|
||||
site.in_source_dir(relative_directory, *files)
|
||||
end
|
||||
|
||||
# Checks whether the directory "exists" for this collection.
|
||||
|
|
|
@ -43,7 +43,7 @@ module Jekyll
|
|||
# Returns nothing.
|
||||
def read_yaml(base, name, opts = {})
|
||||
begin
|
||||
self.content = File.read(site.reader.in_source_dir(base, name),
|
||||
self.content = File.read(site.in_source_dir(base, name),
|
||||
merged_file_read_opts(opts))
|
||||
if content =~ /\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)/m
|
||||
self.content = $POSTMATCH
|
||||
|
@ -209,8 +209,8 @@ module Jekyll
|
|||
|
||||
# Add layout to dependency tree
|
||||
site.regenerator.add_dependency(
|
||||
site.reader.in_source_dir(path),
|
||||
site.reader.in_source_dir(layout.path)
|
||||
site.in_source_dir(path),
|
||||
site.in_source_dir(layout.path)
|
||||
)
|
||||
|
||||
if layout = layouts[layout.data["layout"]]
|
||||
|
|
|
@ -162,8 +162,8 @@ module Jekyll
|
|||
#
|
||||
# Returns the full path to the output file of this document.
|
||||
def destination(base_directory)
|
||||
dest = site.reader.in_dest_dir(base_directory)
|
||||
path = site.reader.in_dest_dir(dest, URL.unescape_path(url))
|
||||
dest = site.in_dest_dir(base_directory)
|
||||
path = site.in_dest_dir(dest, URL.unescape_path(url))
|
||||
path = File.join(path, "index.html") if url.end_with?("/")
|
||||
path << output_ext unless path.end_with?(output_ext)
|
||||
path
|
||||
|
|
|
@ -15,7 +15,7 @@ module Jekyll
|
|||
|
||||
# Get the full path to the directory containing the draft files
|
||||
def containing_dir(dir)
|
||||
site.reader.in_source_dir(dir, '_drafts')
|
||||
site.in_source_dir(dir, '_drafts')
|
||||
end
|
||||
|
||||
# The path to the draft source file, relative to the site source
|
||||
|
|
|
@ -29,7 +29,7 @@ module Jekyll
|
|||
@site = site
|
||||
@base = base
|
||||
@name = name
|
||||
@path = site.reader.in_source_dir(base, name)
|
||||
@path = site.in_source_dir(base, name)
|
||||
|
||||
self.data = {}
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ module Jekyll
|
|||
end
|
||||
|
||||
def layout_directory_inside_source
|
||||
site.reader.in_source_dir(site.config['layouts'])
|
||||
site.in_source_dir(site.config['layouts'])
|
||||
end
|
||||
|
||||
def layout_directory_in_cwd
|
||||
|
|
|
@ -140,7 +140,7 @@ module Jekyll
|
|||
#
|
||||
# Returns the destination file path String.
|
||||
def destination(dest)
|
||||
path = site.reader.in_dest_dir(dest, URL.unescape_path(url))
|
||||
path = site.in_dest_dir(dest, URL.unescape_path(url))
|
||||
path = File.join(path, "index.html") if url.end_with?("/")
|
||||
path << output_ext unless path.end_with?(output_ext)
|
||||
path
|
||||
|
|
|
@ -82,7 +82,7 @@ module Jekyll
|
|||
# Returns an Array of plugin search paths
|
||||
def plugins_path
|
||||
if (site.config['plugins'] == Jekyll::Configuration::DEFAULTS['plugins'])
|
||||
[site.reader.in_source_dir(site.config['plugins'])]
|
||||
[site.in_source_dir(site.config['plugins'])]
|
||||
else
|
||||
Array(site.config['plugins']).map { |d| File.expand_path(d) }
|
||||
end
|
||||
|
|
|
@ -91,7 +91,7 @@ module Jekyll
|
|||
|
||||
# Get the full path to the directory containing the post files
|
||||
def containing_dir(dir)
|
||||
site.reader.in_source_dir(dir, '_posts')
|
||||
site.in_source_dir(dir, '_posts')
|
||||
end
|
||||
|
||||
# Read the YAML frontmatter.
|
||||
|
@ -278,7 +278,7 @@ module Jekyll
|
|||
# Returns destination file path String.
|
||||
def destination(dest)
|
||||
# The url needs to be unescaped in order to preserve the correct filename
|
||||
path = site.reader.in_dest_dir(dest, URL.unescape_path(url))
|
||||
path = site.in_dest_dir(dest, URL.unescape_path(url))
|
||||
path = File.join(path, "index.html") if self.url.end_with?("/")
|
||||
path << output_ext unless path.end_with?(output_ext)
|
||||
path
|
||||
|
|
|
@ -19,30 +19,6 @@ module Jekyll
|
|||
read_collections
|
||||
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(site.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(site.dest) do |base, path|
|
||||
Jekyll.sanitized_path(base, path)
|
||||
end
|
||||
end
|
||||
|
||||
# Filter out any files/directories that are hidden or backup files (start
|
||||
# with "." or "#" or end with "~"), or contain site content (start with "_"),
|
||||
# or are excluded in the site configuration, unless they are web server
|
||||
|
@ -62,10 +38,10 @@ module Jekyll
|
|||
#
|
||||
# Returns the list of entries to process
|
||||
def get_entries(dir, subfolder)
|
||||
base = in_source_dir(dir, subfolder)
|
||||
base = site.in_source_dir(dir, subfolder)
|
||||
return [] unless File.exist?(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?(site.in_source_dir(base, e)) }
|
||||
end
|
||||
|
||||
|
||||
|
@ -92,7 +68,7 @@ module Jekyll
|
|||
#
|
||||
# Returns nothing.
|
||||
def read_directories(dir = '')
|
||||
base = in_source_dir(dir)
|
||||
base = site.in_source_dir(dir)
|
||||
entries = Dir.chdir(base) { filter_entries(Dir.entries('.'), base) }
|
||||
|
||||
read_posts(dir)
|
||||
|
@ -101,7 +77,7 @@ module Jekyll
|
|||
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)
|
||||
f_abs = site.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
|
||||
|
@ -168,7 +144,7 @@ module Jekyll
|
|||
#
|
||||
# Returns nothing
|
||||
def read_data(dir)
|
||||
base = in_source_dir(dir)
|
||||
base = site.in_source_dir(dir)
|
||||
read_data_to(base, site.data)
|
||||
end
|
||||
|
||||
|
@ -187,7 +163,7 @@ module Jekyll
|
|||
end
|
||||
|
||||
entries.each do |entry|
|
||||
path = in_source_dir(dir, entry)
|
||||
path = site.in_source_dir(dir, entry)
|
||||
next if File.symlink?(path) && site.safe
|
||||
|
||||
key = sanitize_filename(File.basename(entry, '.*'))
|
||||
|
|
|
@ -19,7 +19,7 @@ module Jekyll
|
|||
case document
|
||||
when Post, Page
|
||||
document.asset_file? || document.data['regenerate'] ||
|
||||
modified?(site.reader.in_source_dir(document.relative_path))
|
||||
modified?(site.in_source_dir(document.relative_path))
|
||||
when Document
|
||||
!document.write? || document.data['regenerate'] || modified?(document.path)
|
||||
else
|
||||
|
@ -113,7 +113,7 @@ module Jekyll
|
|||
#
|
||||
# Returns the String path of the file.
|
||||
def metadata_file
|
||||
site.reader.in_source_dir('.jekyll-metadata')
|
||||
site.in_source_dir('.jekyll-metadata')
|
||||
end
|
||||
|
||||
# Check if metadata has been disabled
|
||||
|
|
|
@ -141,8 +141,8 @@ module Jekyll
|
|||
|
||||
# Add layout to dependency tree
|
||||
site.regenerator.add_dependency(
|
||||
site.reader.in_source_dir(document.path),
|
||||
site.reader.in_source_dir(layout.path)
|
||||
site.in_source_dir(document.path),
|
||||
site.in_source_dir(layout.path)
|
||||
) if document.write?
|
||||
|
||||
if layout = site.layouts[layout.data["layout"]]
|
||||
|
|
|
@ -342,6 +342,30 @@ module Jekyll
|
|||
@publisher ||= Publisher.new(self)
|
||||
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
|
||||
|
||||
private
|
||||
|
||||
# Checks if the site has any pages containing relative links
|
||||
|
|
|
@ -35,7 +35,7 @@ module Jekyll
|
|||
#
|
||||
# Returns destination file path.
|
||||
def destination(dest)
|
||||
@site.reader.in_dest_dir(*[dest, destination_rel_dir, @name].compact)
|
||||
@site.in_dest_dir(*[dest, destination_rel_dir, @name].compact)
|
||||
end
|
||||
|
||||
def destination_rel_dir
|
||||
|
|
|
@ -117,7 +117,7 @@ eos
|
|||
# Add include to dependency tree
|
||||
if context.registers[:page] and context.registers[:page].has_key? "path"
|
||||
site.regenerator.add_dependency(
|
||||
site.reader.in_source_dir(context.registers[:page]["path"]),
|
||||
site.in_source_dir(context.registers[:page]["path"]),
|
||||
path
|
||||
)
|
||||
end
|
||||
|
@ -135,7 +135,7 @@ eos
|
|||
end
|
||||
|
||||
def resolved_includes_dir(context)
|
||||
context.registers[:site].reader.in_source_dir(@includes_dir)
|
||||
context.registers[:site].in_source_dir(@includes_dir)
|
||||
end
|
||||
|
||||
def validate_path(path, dir, safe)
|
||||
|
@ -170,7 +170,7 @@ eos
|
|||
end
|
||||
|
||||
def resolved_includes_dir(context)
|
||||
context.registers[:site].reader.in_source_dir(page_path(context))
|
||||
context.registers[:site].in_source_dir(page_path(context))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -63,7 +63,7 @@ class TestRegenerator < JekyllUnitTest
|
|||
}))
|
||||
|
||||
@site.process
|
||||
@path = @site.reader.in_source_dir(@site.pages.first.path)
|
||||
@path = @site.in_source_dir(@site.pages.first.path)
|
||||
@regenerator = @site.regenerator
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue