Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore directories rather than all similar paths #65

Merged
merged 4 commits into from
Nov 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/jekyll/watcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,16 @@ def listen_ignore_paths(options)
next unless absolute_path.exist?
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

private
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|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

patterns.any? {|pattern| path =~ pattern } might be more concise here

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-site/_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-site/_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