Skip to content

Commit

Permalink
Ignore directories rather than all similar paths (#65)
Browse files Browse the repository at this point in the history
Merge pull request 65
  • Loading branch information
ashmaroli authored and jekyllbot committed Nov 10, 2018
1 parent e8e96c4 commit baf5903
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
5 changes: 3 additions & 2 deletions lib/jekyll/watcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,16 @@ def listen_ignore_paths(options)

begin
relative_path = absolute_path.relative_path_from(source).to_s
relative_path = File.join(relative_path, "") if absolute_path.directory?
unless relative_path.start_with?("../")
path_to_ignore = Regexp.new(Regexp.escape(relative_path))
path_to_ignore = %r!^#{Regexp.escape(relative_path)}!
Jekyll.logger.debug "Watcher:", "Ignoring #{path_to_ignore}"
path_to_ignore
end
rescue ArgumentError
# Could not find a relative path
end
end.compact + [%r!\.jekyll\-metadata!]
end.compact + [%r!^\.jekyll\-metadata!]
end

def sleep_forever
Expand Down
9 changes: 9 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,13 @@ def source_dir(*files)
def dest_dir(*files)
source_dir("_site", *files)
end

def ignore_path?(patterns, path)
path = path.to_s
patterns.each do |pattern|
return true if path =~ pattern
next
end
false
end
end
28 changes: 24 additions & 4 deletions spec/watcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

let(:options) { base_opts }
let(:site) { instance_double(Jekyll::Site) }
let(:default_ignored) { [%r!_config\.yml!, %r!_site!, %r!\.jekyll\-metadata!] }
let(:default_ignored) { [%r!^_config\.yml!, %r!^_site/!, %r!^\.jekyll\-metadata!] }
subject { described_class }
before(:each) do
FileUtils.mkdir(options["destination"]) if options["destination"]
Expand Down Expand Up @@ -107,6 +107,10 @@

it "ignores config.yml, .jekyll-metadata, and _site by default" do
expect(ignored).to eql(default_ignored)
expect(ignore_path?(ignored, "_site/foo.html")).to eql(true)
expect(ignore_path?(ignored, "_sitemapper/foo.html")).to eql(false)
expect(ignore_path?(ignored, "bar/_site/foo.html")).to eql(false)
expect(ignore_path?(ignored, "bar/_site-mapper.html")).to eql(false)
end

context "with something excluded" do
Expand All @@ -119,26 +123,34 @@
after(:each) { FileUtils.rm(excluded_absolute) }

it "ignores the excluded files" do
expect(ignored).to include(%r!README\.md!)
expect(ignored).to include(%r!LICENSE!)
expect(ignore_path?(ignored, "README.md")).to eql(true)
expect(ignore_path?(ignored, "LICENSE")).to eql(true)
end
end

context "with a custom destination" do
let(:default_ignored) { [%r!_config\.yml!, %r!_dest!, %r!\.jekyll\-metadata!] }
let(:default_ignored) { [%r!^_config\.yml!, %r!^_dest/!, %r!^\.jekyll\-metadata!] }

context "when source is absolute" do
context "when destination is absolute" do
let(:options) { base_opts.merge("destination" => source_dir("_dest")) }
it "ignores the destination" do
expect(ignored).to eql(default_ignored)
expect(ignore_path?(ignored, "_dest/foo.html")).to eql(true)
expect(ignore_path?(ignored, "_destination/foo.html")).to eql(false)
expect(ignore_path?(ignored, "bar/_dest/foo.html")).to eql(false)
expect(ignore_path?(ignored, "bar/_dest-nation.html")).to eql(false)
end
end

context "when destination is relative" do
let(:options) { base_opts.merge("destination" => "spec/test-sité/_dest") }
it "ignores the destination" do
expect(ignored).to eql(default_ignored)
expect(ignore_path?(ignored, "_dest/foo.html")).to eql(true)
expect(ignore_path?(ignored, "_destination/foo.html")).to eql(false)
expect(ignore_path?(ignored, "bar/_dest/foo.html")).to eql(false)
expect(ignore_path?(ignored, "bar/_dest-nation.html")).to eql(false)
end
end
end
Expand All @@ -155,13 +167,21 @@
let(:options) { base_opts.merge("destination" => source_dir("_dest")) }
it "ignores the destination" do
expect(ignored).to eql(default_ignored)
expect(ignore_path?(ignored, "_dest/foo.html")).to eql(true)
expect(ignore_path?(ignored, "_destination/foo.html")).to eql(false)
expect(ignore_path?(ignored, "bar/_dest/foo.html")).to eql(false)
expect(ignore_path?(ignored, "bar/_dest-nation.html")).to eql(false)
end
end

context "when destination is relative" do
let(:options) { base_opts.merge("destination" => "spec/test-sité/_dest") }
it "ignores the destination" do
expect(ignored).to eql(default_ignored)
expect(ignore_path?(ignored, "_dest/foo.html")).to eql(true)
expect(ignore_path?(ignored, "_destination/foo.html")).to eql(false)
expect(ignore_path?(ignored, "bar/_dest/foo.html")).to eql(false)
expect(ignore_path?(ignored, "bar/_dest-nation.html")).to eql(false)
end
end
end
Expand Down

0 comments on commit baf5903

Please sign in to comment.