From d13112dbdc3b54c6a79c612a0ea32fc08affd6ac Mon Sep 17 00:00:00 2001 From: Anatoliy Yastreb Date: Sun, 19 Jun 2016 18:22:59 +0300 Subject: [PATCH 1/2] rubocop: fix code style --- .rubocop.yml | 1 - lib/jekyll/regenerator.rb | 75 ++++++++++++++++++++++++--------------- 2 files changed, 46 insertions(+), 30 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 8c90c049..dd0b6b01 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -8,7 +8,6 @@ AllCops: - lib/jekyll/configuration.rb - lib/jekyll/convertible.rb - lib/jekyll/document.rb - - lib/jekyll/regenerator.rb - lib/jekyll/renderer.rb - lib/jekyll/utils.rb - bin/**/* diff --git a/lib/jekyll/regenerator.rb b/lib/jekyll/regenerator.rb index 830ea914..b387732a 100644 --- a/lib/jekyll/regenerator.rb +++ b/lib/jekyll/regenerator.rb @@ -20,18 +20,14 @@ module Jekyll def regenerate?(document) case document when Page - document.asset_file? || document.data['regenerate'] || - source_modified_or_dest_missing?( - site.in_source_dir(document.relative_path), document.destination(@site.dest) - ) + regenerate_page?(document) when Document - !document.write? || document.data['regenerate'] || - source_modified_or_dest_missing?( - document.path, document.destination(@site.dest) - ) + regenerate_document?(document) else - source_path = document.respond_to?(:path) ? document.path : nil - dest_path = document.respond_to?(:destination) ? document.destination(@site.dest) : nil + source_path = document.respond_to?(:path) ? document.path : nil + dest_path = if document.respond_to?(:destination) + document.destination(@site.dest) + end source_modified_or_dest_missing?(source_path, dest_path) end end @@ -44,7 +40,7 @@ module Jekyll metadata[path] = { "mtime" => File.mtime(path), - "deps" => [] + "deps" => [] } cache[path] = true end @@ -94,23 +90,7 @@ module Jekyll return cache[path] end - # Check path that exists in metadata - data = metadata[path] - if data - data["deps"].each do |dependency| - if modified?(dependency) - return cache[dependency] = cache[path] = true - end - end - if File.exist?(path) && data["mtime"].eql?(File.mtime(path)) - return cache[path] = false - else - return add(path) - end - end - - # Path does not exist in metadata, add it - return add(path) + check_path_exists(path) end # Add a dependency of a path @@ -139,7 +119,7 @@ module Jekyll # # Returns the String path of the file. def metadata_file - site.in_source_dir('.jekyll-metadata') + site.in_source_dir(".jekyll-metadata") end # Check if metadata has been disabled @@ -173,5 +153,42 @@ module Jekyll {} end end + + private + def regenerate_page?(document) + document.asset_file? || document.data["regenerate"] || + source_modified_or_dest_missing?( + site.in_source_dir(document.relative_path), document.destination(@site.dest) + ) + end + + private + def regenerate_document?(document) + !document.write? || document.data["regenerate"] || + source_modified_or_dest_missing?( + document.path, document.destination(@site.dest) + ) + end + + # Private: Check path that exists in metadata + # + # Returns Boolean + private + def check_path_exists(path) + data = metadata[path] + if data + data["deps"].each do |dependency| + if modified?(dependency) + return cache[dependency] = cache[path] = true + end + end + if File.exist?(path) && data["mtime"].eql?(File.mtime(path)) + return cache[path] = false + end + end + + # Path does not exist in metadata, add it + add(path) + end end end From 0b169f77393ef320f2025c72f34d4ce60e5d4d50 Mon Sep 17 00:00:00 2001 From: Anatoliy Yastreb Date: Wed, 22 Jun 2016 14:15:13 +0300 Subject: [PATCH 2/2] rubocop: refactor modified? method --- lib/jekyll/regenerator.rb | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/lib/jekyll/regenerator.rb b/lib/jekyll/regenerator.rb index b387732a..4d89da2e 100644 --- a/lib/jekyll/regenerator.rb +++ b/lib/jekyll/regenerator.rb @@ -90,7 +90,14 @@ module Jekyll return cache[path] end - check_path_exists(path) + if metadata[path] + # If we have seen this file before, + # check if it or one of its dependencies has been modified + existing_file_modified?(path) + else + # If we have not seen this file before, add it to the metadata and regenerate it + add(path) + end end # Add a dependency of a path @@ -170,25 +177,23 @@ module Jekyll ) end - # Private: Check path that exists in metadata - # - # Returns Boolean private - def check_path_exists(path) - data = metadata[path] - if data - data["deps"].each do |dependency| - if modified?(dependency) - return cache[dependency] = cache[path] = true - end - end - if File.exist?(path) && data["mtime"].eql?(File.mtime(path)) - return cache[path] = false + def existing_file_modified?(path) + # If one of this file dependencies have been modified, + # set the regeneration bit for both the dependency and the file to true + metadata[path]["deps"].each do |dependency| + if modified?(dependency) + return cache[dependency] = cache[path] = true end end - # Path does not exist in metadata, add it - add(path) + if File.exist?(path) && metadata[path]["mtime"].eql?(File.mtime(path)) + # If this file has not been modified, set the regeneration bit to false + cache[path] = false + else + # If it has been modified, set it to true + add(path) + end end end end