From 7a933893dbcaf1b57dbfafd6dc41edaadef43197 Mon Sep 17 00:00:00 2001 From: Anatoliy Yastreb Date: Thu, 16 Jun 2016 13:14:50 +0300 Subject: [PATCH] rubocop: fix code style --- .rubocop.yml | 1 - lib/jekyll/static_file.rb | 50 +++++++++++++++++++-------------------- test/test_site.rb | 2 -- 3 files changed, 24 insertions(+), 29 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index adb0ca870e0..8c90c0494de 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -10,7 +10,6 @@ AllCops: - lib/jekyll/document.rb - lib/jekyll/regenerator.rb - lib/jekyll/renderer.rb - - lib/jekyll/static_file.rb - lib/jekyll/utils.rb - bin/**/* - benchmark/**/* diff --git a/lib/jekyll/static_file.rb b/lib/jekyll/static_file.rb index 3e7d0d25d51..5471c2a9aff 100644 --- a/lib/jekyll/static_file.rb +++ b/lib/jekyll/static_file.rb @@ -1,8 +1,5 @@ module Jekyll class StaticFile - # The cache of last modification times [path] -> mtime. - @@mtimes = {} - attr_reader :relative_path, :extname # Initialize a new StaticFile. @@ -11,6 +8,7 @@ class StaticFile # base - The String path to the . # dir - The String path between and the file. # name - The String filename of the file. + # rubocop: disable ParameterLists def initialize(site, base, dir, name, collection = nil) @site = site @base = base @@ -19,7 +17,10 @@ def initialize(site, base, dir, name, collection = nil) @collection = collection @relative_path = File.join(*[@dir, @name].compact) @extname = File.extname(@name) + # The cache of last modification times [path] -> mtime. + @mtimes = {} end + # rubocop: enable ParameterLists # Returns source file path. def path @@ -56,7 +57,7 @@ def mtime # # Returns true if modified since last write. def modified? - @@mtimes[path] != mtime + @mtimes[path] != mtime end # Whether to write the file to the filesystem @@ -64,7 +65,7 @@ def modified? # Returns true unless the defaults for the destination path from # _config.yml contain `published: false`. def write? - defaults.fetch('published', true) + defaults.fetch("published", true) end # Write the static file to the destination directory (if modified). @@ -76,28 +77,16 @@ def write(dest) dest_path = destination(dest) return false if File.exist?(dest_path) && !modified? - @@mtimes[path] = mtime + @mtimes[path] = mtime FileUtils.mkdir_p(File.dirname(dest_path)) FileUtils.rm(dest_path) if File.exist?(dest_path) - if @site.safe || Jekyll.env == "production" - FileUtils.cp(path, dest_path) - else - FileUtils.copy_entry(path, dest_path) - end - File.utime(@@mtimes[path], @@mtimes[path], dest_path) + copy_file(dest_path) + File.utime(@mtimes[path], @mtimes[path], dest_path) true end - # Reset the mtimes cache (for testing purposes). - # - # Returns nothing. - def self.reset_cache - @@mtimes = {} - nil - end - def to_liquid { "extname" => extname, @@ -109,11 +98,11 @@ def to_liquid def placeholders { :collection => @collection.label, - :path => relative_path[ + :path => relative_path[ @collection.relative_directory.size..relative_path.size], - :output_ext => '', - :name => '', - :title => '' + :output_ext => "", + :name => "", + :title => "" } end @@ -125,10 +114,10 @@ def url relative_path else ::Jekyll::URL.new({ - :template => @collection.url_template, + :template => @collection.url_template, :placeholders => placeholders }) - end.to_s.gsub(/\/$/, '') + end.to_s.gsub(%r!/$!, "") end # Returns the type of the collection if present, nil otherwise. @@ -141,5 +130,14 @@ def type def defaults @defaults ||= @site.frontmatter_defaults.all url, type end + + private + def copy_file(dest_path) + if @site.safe || Jekyll.env == "production" + FileUtils.cp(path, dest_path) + else + FileUtils.copy_entry(path, dest_path) + end + end end end diff --git a/test/test_site.rb b/test/test_site.rb index 4e9e18a57ab..6ac27ccc730 100644 --- a/test/test_site.rb +++ b/test/test_site.rb @@ -100,7 +100,6 @@ def generate(site) should "write only modified static files" do clear_dest - StaticFile.reset_cache @site.regenerator.clear @site.process @@ -130,7 +129,6 @@ def generate(site) should "write static files if not modified but missing in destination" do clear_dest - StaticFile.reset_cache @site.regenerator.clear @site.process