From 8f1959bbc40ec430105ed6b74b850ff2b19e9dfd Mon Sep 17 00:00:00 2001 From: Bogdan Date: Wed, 26 Jul 2017 02:20:20 +0300 Subject: [PATCH] Define path with __dir__ (#6087) Merge pull request 6087 --- Gemfile | 4 ++-- Rakefile | 2 +- exe/jekyll | 2 +- jekyll.gemspec | 2 +- lib/jekyll.rb | 4 ++-- lib/jekyll/commands/new.rb | 2 +- lib/jekyll/commands/serve.rb | 2 +- script/console | 4 ++-- script/stackprof | 4 ++-- script/vendor-mimes | 2 +- test/helper.rb | 4 ++-- test/test_convertible.rb | 4 ++-- test/test_new_command.rb | 2 +- 13 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Gemfile b/Gemfile index c8b4694f..0306c71a 100644 --- a/Gemfile +++ b/Gemfile @@ -27,8 +27,8 @@ group :test do gem "rspec" gem "rspec-mocks" gem "rubocop", "~> 0.49.1" - gem "test-dependency-theme", :path => File.expand_path("./test/fixtures/test-dependency-theme", File.dirname(__FILE__)) - gem "test-theme", :path => File.expand_path("./test/fixtures/test-theme", File.dirname(__FILE__)) + gem "test-dependency-theme", :path => File.expand_path("test/fixtures/test-dependency-theme", __dir__) + gem "test-theme", :path => File.expand_path("test/fixtures/test-theme", __dir__) gem "jruby-openssl" if RUBY_ENGINE == "jruby" end diff --git a/Rakefile b/Rakefile index 949e0fd8..c80324ab 100644 --- a/Rakefile +++ b/Rakefile @@ -4,7 +4,7 @@ require "rdoc" require "date" require "yaml" -$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "lib")) +$LOAD_PATH.unshift File.expand_path("lib", __dir__) require "jekyll/version" Dir.glob("rake/**.rake").each { |f| import f } diff --git a/exe/jekyll b/exe/jekyll index f0f41c93..baac0997 100755 --- a/exe/jekyll +++ b/exe/jekyll @@ -1,7 +1,7 @@ #!/usr/bin/env ruby STDOUT.sync = true -$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib")) +$LOAD_PATH.unshift File.expand_path("../lib", __dir__) require "jekyll" require "mercenary" diff --git a/jekyll.gemspec b/jekyll.gemspec index 5ae9277f..5ec2e9a2 100644 --- a/jekyll.gemspec +++ b/jekyll.gemspec @@ -1,6 +1,6 @@ # coding: utf-8 -lib = File.expand_path("../lib", __FILE__) +lib = File.expand_path("lib", __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require "jekyll/version" diff --git a/lib/jekyll.rb b/lib/jekyll.rb index 25bbaa0a..5e5923c2 100644 --- a/lib/jekyll.rb +++ b/lib/jekyll.rb @@ -1,4 +1,4 @@ -$LOAD_PATH.unshift File.dirname(__FILE__) # For use/testing when no gem is installed +$LOAD_PATH.unshift __dir__ # For use/testing when no gem is installed # Require all of the Ruby files in the given directory. # @@ -6,7 +6,7 @@ $LOAD_PATH.unshift File.dirname(__FILE__) # For use/testing when no gem is insta # # Returns nothing. def require_all(path) - glob = File.join(File.dirname(__FILE__), path, "*.rb") + glob = File.join(__dir__, path, "*.rb") Dir[glob].sort.each do |f| require f end diff --git a/lib/jekyll/commands/new.rb b/lib/jekyll/commands/new.rb index a3a850fe..d1aeb5a0 100644 --- a/lib/jekyll/commands/new.rb +++ b/lib/jekyll/commands/new.rb @@ -113,7 +113,7 @@ RUBY end def site_template - File.expand_path("../../site_template", File.dirname(__FILE__)) + File.expand_path("../../site_template", __dir__) end def scaffold_path diff --git a/lib/jekyll/commands/serve.rb b/lib/jekyll/commands/serve.rb index 50a85fac..4bc9eaf0 100644 --- a/lib/jekyll/commands/serve.rb +++ b/lib/jekyll/commands/serve.rb @@ -234,7 +234,7 @@ module Jekyll private def mime_types - file = File.expand_path("../mime.types", File.dirname(__FILE__)) + file = File.expand_path("../mime.types", __dir__) WEBrick::HTTPUtils.load_mime_types(file) end end diff --git a/script/console b/script/console index 34ad6e8a..38ca96a1 100755 --- a/script/console +++ b/script/console @@ -1,10 +1,10 @@ #!/usr/bin/env ruby require 'pry' -$LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w{ .. lib }) +$LOAD_PATH.unshift File.expand_path("../lib", __dir__) require 'jekyll' -TEST_DIR = File.expand_path(File.join(File.dirname(__FILE__), *%w{ .. test })) +TEST_DIR = File.expand_path("../test", __dir__) def fixture_site(overrides = {}) Jekyll::Site.new(site_configuration(overrides)) diff --git a/script/stackprof b/script/stackprof index e6e77f8d..12cbdd21 100755 --- a/script/stackprof +++ b/script/stackprof @@ -3,10 +3,10 @@ require "bundler/setup" require "json" require "stackprof" -require File.expand_path("../../lib/jekyll", __FILE__) +require File.expand_path("../lib/jekyll", __dir__) MODE = ARGV.first || "cpu" -PROF_OUTPUT_FILE = File.expand_path("../../tmp/stackprof-#{MODE}-#{Time.now.strftime("%Y%m%d%H%M")}.dump", __FILE__) +PROF_OUTPUT_FILE = File.expand_path("../tmp/stackprof-#{MODE}-#{Time.now.strftime("%Y%m%d%H%M")}.dump", __dir__) puts "Stackprof Mode: #{MODE}" diff --git a/script/vendor-mimes b/script/vendor-mimes index ea779232..6ea9c377 100755 --- a/script/vendor-mimes +++ b/script/vendor-mimes @@ -5,7 +5,7 @@ require 'json' require 'open-uri' -config = File.expand_path "../lib/jekyll/mime.types", File.dirname(__FILE__) +config = File.expand_path "../lib/jekyll/mime.types", __dir__ # Create an array of vendored mimetype => [extensions] mimes = {} diff --git a/test/helper.rb b/test/helper.rb index 74f2682e..83beaad3 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -13,7 +13,7 @@ if ENV["CI"] require "simplecov" SimpleCov.start else - require File.expand_path("../simplecov_custom_profile", __FILE__) + require File.expand_path("simplecov_custom_profile", __dir__) SimpleCov.start "gem" do add_filter "/vendor/gem" add_filter "/vendor/bundle" @@ -63,7 +63,7 @@ end module DirectoryHelpers def root_dir(*subdirs) - File.join(File.dirname(File.dirname(__FILE__)), *subdirs) + File.expand_path(File.join("..", *subdirs), __dir__) end def dest_dir(*subdirs) diff --git a/test/test_convertible.rb b/test/test_convertible.rb index 6e6defa6..ef703070 100644 --- a/test/test_convertible.rb +++ b/test/test_convertible.rb @@ -6,11 +6,11 @@ class TestConvertible < JekyllUnitTest setup do @convertible = OpenStruct.new( "site" => Site.new(Jekyll.configuration( - "source" => File.expand_path("../fixtures", __FILE__) + "source" => File.expand_path("fixtures", __dir__) )) ) @convertible.extend Jekyll::Convertible - @base = File.expand_path("../fixtures", __FILE__) + @base = File.expand_path("fixtures", __dir__) end should "parse the front matter correctly" do diff --git a/test/test_new_command.rb b/test/test_new_command.rb index 6a448eec..32db566d 100644 --- a/test/test_new_command.rb +++ b/test/test_new_command.rb @@ -9,7 +9,7 @@ class TestNewCommand < JekyllUnitTest end def site_template - File.expand_path("../lib/site_template", File.dirname(__FILE__)) + File.expand_path("../lib/site_template", __dir__) end context "when args contains a path" do