From 0bc88975c896988e0745bf0d15cd3ea5a14ee4f3 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sun, 7 Sep 2014 11:50:09 -0700 Subject: [PATCH] More removal of File.join --- lib/jekyll/collection.rb | 7 ++++--- lib/jekyll/convertible.rb | 2 +- lib/jekyll/document.rb | 2 +- lib/jekyll/layout_reader.rb | 2 +- lib/jekyll/page.rb | 2 +- lib/jekyll/plugin_manager.rb | 2 +- lib/jekyll/post.rb | 4 ++-- lib/jekyll/site.rb | 30 +++++++++++++++++++----------- 8 files changed, 30 insertions(+), 21 deletions(-) diff --git a/lib/jekyll/collection.rb b/lib/jekyll/collection.rb index fd739c16..84e207f8 100644 --- a/lib/jekyll/collection.rb +++ b/lib/jekyll/collection.rb @@ -54,8 +54,8 @@ module Jekyll # relative to the collection's directory def entries return Array.new unless exists? - Dir.glob(File.join(directory, "**", "*.*")).map do |entry| - entry[File.join(directory, "")] = ''; entry + Dir.glob(collection_dir("**", "*.*")).map do |entry| + entry[collection_dir("")] = ''; entry end end @@ -94,7 +94,8 @@ module Jekyll # Returns a String containing th directory name where the collection # is stored on the filesystem. 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 # Checks whether the directory "exists" for this collection. diff --git a/lib/jekyll/convertible.rb b/lib/jekyll/convertible.rb index 74c27117..2b52bca3 100644 --- a/lib/jekyll/convertible.rb +++ b/lib/jekyll/convertible.rb @@ -43,7 +43,7 @@ module Jekyll # Returns nothing. def read_yaml(base, name, opts = {}) 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)) if content =~ /\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)/m self.content = $POSTMATCH diff --git a/lib/jekyll/document.rb b/lib/jekyll/document.rb index 95a2bdcd..9cb4264e 100644 --- a/lib/jekyll/document.rb +++ b/lib/jekyll/document.rb @@ -159,7 +159,7 @@ module Jekyll # # Returns the full path to the output file of this document. 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 end diff --git a/lib/jekyll/layout_reader.rb b/lib/jekyll/layout_reader.rb index a9172c06..d67363fb 100644 --- a/lib/jekyll/layout_reader.rb +++ b/lib/jekyll/layout_reader.rb @@ -38,7 +38,7 @@ module Jekyll end def layout_directory_inside_source - Jekyll.sanitized_path(site.source, site.config['layouts']) + site.in_source_dir(site.config['layouts']) end def layout_directory_in_cwd diff --git a/lib/jekyll/page.rb b/lib/jekyll/page.rb index dcbd3ac5..98f730bf 100644 --- a/lib/jekyll/page.rb +++ b/lib/jekyll/page.rb @@ -140,7 +140,7 @@ module Jekyll # # Returns the destination file path String. 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 end diff --git a/lib/jekyll/plugin_manager.rb b/lib/jekyll/plugin_manager.rb index 7b817e38..c52a5205 100644 --- a/lib/jekyll/plugin_manager.rb +++ b/lib/jekyll/plugin_manager.rb @@ -66,7 +66,7 @@ module Jekyll # Returns an Array of plugin search paths def plugins_path if (site.config['plugins'] == Jekyll::Configuration::DEFAULTS['plugins']) - [Jekyll.sanitized_path(site.source, site.config['plugins'])] + [site.in_source_dir(site.config['plugins'])] else Array(site.config['plugins']).map { |d| File.expand_path(d) } end diff --git a/lib/jekyll/post.rb b/lib/jekyll/post.rb index 68b85acb..d89034ce 100644 --- a/lib/jekyll/post.rb +++ b/lib/jekyll/post.rb @@ -268,8 +268,8 @@ module Jekyll # Returns destination file path String. def destination(dest) # The url needs to be unescaped in order to preserve the correct filename - path = Jekyll.sanitized_path(dest, URL.unescape_path(url)) - path = File.join(path, "index.html") if path[/\.html?$/].nil? + path = site.in_dest_dir(dest, URL.unescape_path(url)) + path = File.join(path, "index.html") if path[/\.html$/].nil? path end diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index 5bf1fc09..0fc5130c 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -23,9 +23,9 @@ module Jekyll self.send("#{opt}=", config[opt]) end + # Source and destination may not be changed after the site has been created. @source = File.expand_path(config['source']).freeze @dest = File.expand_path(config['destination']).freeze - self.permalink_style = config['permalink'].to_sym self.plugin_manager = Jekyll::PluginManager.new(self) self.plugins = plugin_manager.plugins_path @@ -33,6 +33,8 @@ module Jekyll self.file_read_opts = {} self.file_read_opts[:encoding] = config['encoding'] if config['encoding'] + self.permalink_style = config['permalink'].to_sym + Jekyll.sites << self reset @@ -93,16 +95,22 @@ module Jekyll # 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(path) - Jekyll.sanitized_path(source, path) + def in_source_dir(*paths) + Jekyll.sanitized_path(source, File.join(*paths.flatten)) 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(path) - Jekyll.sanitized_path(dest, path) + def in_dest_dir(*paths) + Jekyll.sanitized_path(dest, File.join(*paths)) end # The list of collections and their corresponding Jekyll::Collection instances. @@ -149,7 +157,7 @@ module Jekyll # # Returns nothing. def read_directories(dir = '') - base = File.join(source, dir) + base = in_source_dir(dir) entries = Dir.chdir(base) { filter_entries(Dir.entries('.'), base) } read_posts(dir) @@ -158,7 +166,7 @@ module Jekyll limit_posts! if limit_posts > 0 # limit the posts if :limit_posts option is set entries.each do |f| - f_abs = File.join(base, f) + f_abs = in_source_dir(base, f) if File.directory?(f_abs) f_rel = File.join(dir, f) read_directories(f_rel) unless dest.sub(/\/$/, '') == f_abs @@ -215,7 +223,7 @@ module Jekyll # # Returns nothing def read_data(dir) - base = Jekyll.sanitized_path(source, dir) + base = in_source_dir(dir) read_data_to(base, self.data) end @@ -234,7 +242,7 @@ module Jekyll end entries.each do |entry| - path = Jekyll.sanitized_path(dir, entry) + path = in_source_dir(dir, entry) next if File.symlink?(path) && safe key = sanitize_filename(File.basename(entry, '.*')) @@ -424,10 +432,10 @@ module Jekyll # # Returns the list of entries to process def get_entries(dir, subfolder) - base = File.join(source, dir, subfolder) + base = in_source_dir(dir, subfolder) return [] unless File.exist?(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 # Aggregate post information