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:
Martin Jorn Rogalla 2015-03-05 13:30:29 +01:00
parent 9e1cb96a7e
commit 4b8e3cfdbd
17 changed files with 55 additions and 55 deletions

View File

@ -36,7 +36,7 @@ module Jekyll
# Returns a Set with the file paths # Returns a Set with the file paths
def existing_files def existing_files
files = Set.new 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) files << file unless file =~ /\/\.{1,2}$/ || file =~ keep_file_regex || keep_dirs.include?(file)
end end
files files
@ -83,7 +83,7 @@ module Jekyll
# #
# Returns a Set with the directory paths # Returns a Set with the directory paths
def keep_dirs 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 end
# Private: Creates a regular expression from the config's keep_files array # Private: Creates a regular expression from the config's keep_files array

View File

@ -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.reader.in_source_dir(relative_directory) @directory ||= site.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.reader.in_source_dir(relative_directory, *files) site.in_source_dir(relative_directory, *files)
end end
# Checks whether the directory "exists" for this collection. # Checks whether the directory "exists" for this collection.

View File

@ -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.reader.in_source_dir(base, name), self.content = File.read(site.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.reader.in_source_dir(path), site.in_source_dir(path),
site.reader.in_source_dir(layout.path) site.in_source_dir(layout.path)
) )
if layout = layouts[layout.data["layout"]] if layout = layouts[layout.data["layout"]]

View File

@ -162,8 +162,8 @@ module Jekyll
# #
# Returns the full path to the output file of this document. # Returns the full path to the output file of this document.
def destination(base_directory) def destination(base_directory)
dest = site.reader.in_dest_dir(base_directory) dest = site.in_dest_dir(base_directory)
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 = File.join(path, "index.html") if url.end_with?("/")
path << output_ext unless path.end_with?(output_ext) path << output_ext unless path.end_with?(output_ext)
path path

View File

@ -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.reader.in_source_dir(dir, '_drafts') site.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

View File

@ -29,7 +29,7 @@ module Jekyll
@site = site @site = site
@base = base @base = base
@name = name @name = name
@path = site.reader.in_source_dir(base, name) @path = site.in_source_dir(base, name)
self.data = {} self.data = {}

View File

@ -38,7 +38,7 @@ module Jekyll
end end
def layout_directory_inside_source def layout_directory_inside_source
site.reader.in_source_dir(site.config['layouts']) site.in_source_dir(site.config['layouts'])
end end
def layout_directory_in_cwd def layout_directory_in_cwd

View File

@ -140,7 +140,7 @@ module Jekyll
# #
# Returns the destination file path String. # Returns the destination file path String.
def destination(dest) 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 = File.join(path, "index.html") if url.end_with?("/")
path << output_ext unless path.end_with?(output_ext) path << output_ext unless path.end_with?(output_ext)
path path

View File

@ -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.reader.in_source_dir(site.config['plugins'])] [site.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

View File

@ -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.reader.in_source_dir(dir, '_posts') site.in_source_dir(dir, '_posts')
end end
# Read the YAML frontmatter. # Read the YAML frontmatter.
@ -278,7 +278,7 @@ module Jekyll
# Returns destination file path String. # Returns destination file path String.
def destination(dest) def destination(dest)
# The url needs to be unescaped in order to preserve the correct filename # 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 = File.join(path, "index.html") if self.url.end_with?("/")
path << output_ext unless path.end_with?(output_ext) path << output_ext unless path.end_with?(output_ext)
path path

View File

@ -19,30 +19,6 @@ module Jekyll
read_collections read_collections
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(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 # Filter out any files/directories that are hidden or backup files (start
# with "." or "#" or end with "~"), or contain site content (start with "_"), # with "." or "#" or end with "~"), or contain site content (start with "_"),
# or are excluded in the site configuration, unless they are web server # 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 # Returns the list of entries to process
def get_entries(dir, subfolder) def get_entries(dir, subfolder)
base = in_source_dir(dir, subfolder) base = site.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?(site.in_source_dir(base, e)) }
end end
@ -92,7 +68,7 @@ module Jekyll
# #
# Returns nothing. # Returns nothing.
def read_directories(dir = '') def read_directories(dir = '')
base = in_source_dir(dir) base = site.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)
@ -101,7 +77,7 @@ module Jekyll
limit_posts if site.limit_posts > 0 # limit the posts if :limit_posts option is set limit_posts if site.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 = site.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 site.dest.sub(/\/$/, '') == f_abs read_directories(f_rel) unless site.dest.sub(/\/$/, '') == f_abs
@ -168,7 +144,7 @@ module Jekyll
# #
# Returns nothing # Returns nothing
def read_data(dir) def read_data(dir)
base = in_source_dir(dir) base = site.in_source_dir(dir)
read_data_to(base, site.data) read_data_to(base, site.data)
end end
@ -187,7 +163,7 @@ module Jekyll
end end
entries.each do |entry| entries.each do |entry|
path = in_source_dir(dir, entry) path = site.in_source_dir(dir, entry)
next if File.symlink?(path) && site.safe next if File.symlink?(path) && site.safe
key = sanitize_filename(File.basename(entry, '.*')) key = sanitize_filename(File.basename(entry, '.*'))

View File

@ -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.reader.in_source_dir(document.relative_path)) modified?(site.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.reader.in_source_dir('.jekyll-metadata') site.in_source_dir('.jekyll-metadata')
end end
# Check if metadata has been disabled # Check if metadata has been disabled

View File

@ -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.reader.in_source_dir(document.path), site.in_source_dir(document.path),
site.reader.in_source_dir(layout.path) site.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"]]

View File

@ -342,6 +342,30 @@ module Jekyll
@publisher ||= Publisher.new(self) @publisher ||= Publisher.new(self)
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.
#
# 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 private
# Checks if the site has any pages containing relative links # Checks if the site has any pages containing relative links

View File

@ -35,7 +35,7 @@ module Jekyll
# #
# Returns destination file path. # Returns destination file path.
def destination(dest) 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 end
def destination_rel_dir def destination_rel_dir

View File

@ -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.reader.in_source_dir(context.registers[:page]["path"]), site.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].reader.in_source_dir(@includes_dir) context.registers[:site].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].reader.in_source_dir(page_path(context)) context.registers[:site].in_source_dir(page_path(context))
end end
end end
end end

View File

@ -63,7 +63,7 @@ class TestRegenerator < JekyllUnitTest
})) }))
@site.process @site.process
@path = @site.reader.in_source_dir(@site.pages.first.path) @path = @site.in_source_dir(@site.pages.first.path)
@regenerator = @site.regenerator @regenerator = @site.regenerator
end end