More removal of File.join

This commit is contained in:
Parker Moore 2014-09-07 11:50:09 -07:00
parent 98182aab4a
commit 0bc88975c8
8 changed files with 30 additions and 21 deletions

View File

@ -54,8 +54,8 @@ module Jekyll
# relative to the collection's directory # relative to the collection's directory
def entries def entries
return Array.new unless exists? return Array.new unless exists?
Dir.glob(File.join(directory, "**", "*.*")).map do |entry| Dir.glob(collection_dir("**", "*.*")).map do |entry|
entry[File.join(directory, "")] = ''; entry entry[collection_dir("")] = ''; entry
end end
end end
@ -94,7 +94,8 @@ 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 collection_dir(*files) def collection_dir(*files)
site.in_source_dir(File.join(directory, *files)) return directory if files.empty?
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(Jekyll.sanitized_path(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

View File

@ -159,7 +159,7 @@ 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)
path = Jekyll.sanitized_path(base_directory, url) path = site.in_dest_dir(base_directory, url)
path = File.join(path, "index.html") if url =~ /\/$/ path = File.join(path, "index.html") if url =~ /\/$/
path path
end end

View File

@ -38,7 +38,7 @@ module Jekyll
end end
def layout_directory_inside_source def layout_directory_inside_source
Jekyll.sanitized_path(site.source, 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 = Jekyll.sanitized_path(dest, URL.unescape_path(url)) path = site.in_dest_dir(dest, URL.unescape_path(url))
path = File.join(path, "index.html") if url =~ /\/$/ path = File.join(path, "index.html") if url =~ /\/$/
path path
end end

View File

@ -66,7 +66,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'])
[Jekyll.sanitized_path(site.source, 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

@ -268,8 +268,8 @@ 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 = Jekyll.sanitized_path(dest, URL.unescape_path(url)) path = site.in_dest_dir(dest, URL.unescape_path(url))
path = File.join(path, "index.html") if path[/\.html?$/].nil? path = File.join(path, "index.html") if path[/\.html$/].nil?
path path
end end

View File

@ -23,9 +23,9 @@ module Jekyll
self.send("#{opt}=", config[opt]) self.send("#{opt}=", config[opt])
end end
# Source and destination may not be changed after the site has been created.
@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
self.permalink_style = config['permalink'].to_sym
self.plugin_manager = Jekyll::PluginManager.new(self) self.plugin_manager = Jekyll::PluginManager.new(self)
self.plugins = plugin_manager.plugins_path self.plugins = plugin_manager.plugins_path
@ -33,6 +33,8 @@ module Jekyll
self.file_read_opts = {} self.file_read_opts = {}
self.file_read_opts[:encoding] = config['encoding'] if config['encoding'] self.file_read_opts[:encoding] = config['encoding'] if config['encoding']
self.permalink_style = config['permalink'].to_sym
Jekyll.sites << self Jekyll.sites << self
reset reset
@ -93,16 +95,22 @@ module Jekyll
# Public: Prefix a given path with the source directory. # 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. # Returns a path which is prefixed with the source directory.
def in_source_dir(path) def in_source_dir(*paths)
Jekyll.sanitized_path(source, path) Jekyll.sanitized_path(source, File.join(*paths.flatten))
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
# destination directory
#
# Returns a path which is prefixed with the destination directory. # Returns a path which is prefixed with the destination directory.
def in_dest_dir(path) def in_dest_dir(*paths)
Jekyll.sanitized_path(dest, path) Jekyll.sanitized_path(dest, File.join(*paths))
end end
# The list of collections and their corresponding Jekyll::Collection instances. # The list of collections and their corresponding Jekyll::Collection instances.
@ -149,7 +157,7 @@ module Jekyll
# #
# Returns nothing. # Returns nothing.
def read_directories(dir = '') def read_directories(dir = '')
base = File.join(source, dir) base = 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)
@ -158,7 +166,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 = File.join(base, f) f_abs = 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
@ -215,7 +223,7 @@ module Jekyll
# #
# Returns nothing # Returns nothing
def read_data(dir) def read_data(dir)
base = Jekyll.sanitized_path(source, dir) base = in_source_dir(dir)
read_data_to(base, self.data) read_data_to(base, self.data)
end end
@ -234,7 +242,7 @@ module Jekyll
end end
entries.each do |entry| entries.each do |entry|
path = Jekyll.sanitized_path(dir, entry) path = 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, '.*'))
@ -424,10 +432,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 = File.join(source, dir, subfolder) base = 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?(File.join(base, e)) } entries.delete_if { |e| File.directory?(in_source_dir(base, e)) }
end end
# Aggregate post information # Aggregate post information