From 4b8e3cfdbddeee2fb4634c7e0152780c4801f766 Mon Sep 17 00:00:00 2001 From: Martin Jorn Rogalla Date: Thu, 5 Mar 2015 13:30:29 +0100 Subject: [PATCH] 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 --- lib/jekyll/cleaner.rb | 4 ++-- lib/jekyll/collection.rb | 4 ++-- lib/jekyll/convertible.rb | 6 +++--- lib/jekyll/document.rb | 4 ++-- lib/jekyll/draft.rb | 2 +- lib/jekyll/layout.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/reader.rb | 36 ++++++------------------------------ lib/jekyll/regenerator.rb | 4 ++-- lib/jekyll/renderer.rb | 4 ++-- lib/jekyll/site.rb | 24 ++++++++++++++++++++++++ lib/jekyll/static_file.rb | 2 +- lib/jekyll/tags/include.rb | 6 +++--- test/test_regenerator.rb | 2 +- 17 files changed, 55 insertions(+), 55 deletions(-) diff --git a/lib/jekyll/cleaner.rb b/lib/jekyll/cleaner.rb index 4c93411d..a8b269f4 100644 --- a/lib/jekyll/cleaner.rb +++ b/lib/jekyll/cleaner.rb @@ -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 diff --git a/lib/jekyll/collection.rb b/lib/jekyll/collection.rb index 4b07b2af..b09a7ed9 100644 --- a/lib/jekyll/collection.rb +++ b/lib/jekyll/collection.rb @@ -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. diff --git a/lib/jekyll/convertible.rb b/lib/jekyll/convertible.rb index becc78ed..d587f8f3 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(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"]] diff --git a/lib/jekyll/document.rb b/lib/jekyll/document.rb index 5419647c..cd407dfa 100644 --- a/lib/jekyll/document.rb +++ b/lib/jekyll/document.rb @@ -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 diff --git a/lib/jekyll/draft.rb b/lib/jekyll/draft.rb index 4167f154..16daefdf 100644 --- a/lib/jekyll/draft.rb +++ b/lib/jekyll/draft.rb @@ -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 diff --git a/lib/jekyll/layout.rb b/lib/jekyll/layout.rb index 81ba7f81..c29f353f 100644 --- a/lib/jekyll/layout.rb +++ b/lib/jekyll/layout.rb @@ -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 = {} diff --git a/lib/jekyll/layout_reader.rb b/lib/jekyll/layout_reader.rb index 645d3cf8..a8466beb 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 - site.reader.in_source_dir(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 75ca190c..ca824245 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 = 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 diff --git a/lib/jekyll/plugin_manager.rb b/lib/jekyll/plugin_manager.rb index 5abfd47c..64dea860 100644 --- a/lib/jekyll/plugin_manager.rb +++ b/lib/jekyll/plugin_manager.rb @@ -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 diff --git a/lib/jekyll/post.rb b/lib/jekyll/post.rb index c80a35e4..780f40f7 100644 --- a/lib/jekyll/post.rb +++ b/lib/jekyll/post.rb @@ -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 diff --git a/lib/jekyll/reader.rb b/lib/jekyll/reader.rb index 731937ff..79464d46 100644 --- a/lib/jekyll/reader.rb +++ b/lib/jekyll/reader.rb @@ -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, '.*')) diff --git a/lib/jekyll/regenerator.rb b/lib/jekyll/regenerator.rb index 07273db6..0616fdd9 100644 --- a/lib/jekyll/regenerator.rb +++ b/lib/jekyll/regenerator.rb @@ -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 diff --git a/lib/jekyll/renderer.rb b/lib/jekyll/renderer.rb index fd58bff9..f25ca343 100644 --- a/lib/jekyll/renderer.rb +++ b/lib/jekyll/renderer.rb @@ -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"]] diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index fd1b2661..1e902e2d 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -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 diff --git a/lib/jekyll/static_file.rb b/lib/jekyll/static_file.rb index cb1b3079..b83f4fae 100644 --- a/lib/jekyll/static_file.rb +++ b/lib/jekyll/static_file.rb @@ -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 diff --git a/lib/jekyll/tags/include.rb b/lib/jekyll/tags/include.rb index fcac41b2..b809ffe7 100644 --- a/lib/jekyll/tags/include.rb +++ b/lib/jekyll/tags/include.rb @@ -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 diff --git a/test/test_regenerator.rb b/test/test_regenerator.rb index cc505e39..15819487 100644 --- a/test/test_regenerator.rb +++ b/test/test_regenerator.rb @@ -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