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 output_dir when checking for excludes in pruner #1317

Merged
merged 1 commit into from Feb 17, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion nanoc/lib/nanoc/base/services/pruner.rb
Expand Up @@ -43,10 +43,18 @@ def exclude?(component)
#
# @return [Boolean] true if the given file is excluded, false otherwise
def filename_excluded?(filename)
pathname = Pathname.new(filename)
pathname = Pathname.new(strip_output_dir(filename))
@exclude.any? { |e| pathname_components(pathname).include?(e) }
end

def strip_output_dir(filename)
if filename.start_with?(@config[:output_dir])
filename[@config[:output_dir].size..-1]
else
filename
end
end

def pathname_components(pathname)
components = []
tmp = pathname
Expand Down
27 changes: 26 additions & 1 deletion nanoc/spec/nanoc/base/services/pruner_spec.rb
Expand Up @@ -3,7 +3,7 @@
describe Nanoc::Pruner do
subject(:pruner) { described_class.new(config, reps, dry_run: dry_run, exclude: exclude) }

let(:config) { Nanoc::Int::Configuration.new({}) }
let(:config) { Nanoc::Int::Configuration.new({}).with_defaults }
let(:dry_run) { false }
let(:exclude) { [] }

Expand All @@ -25,6 +25,31 @@
expect(Nanoc::Extra::Pruner).to equal(Nanoc::Pruner)
end

describe '#filename_excluded?' do
subject { pruner.filename_excluded?(filename) }

let(:filename) { 'output/foo/bar.html' }

context 'nothing excluded' do
it { is_expected.to be(false) }
end

context 'matching identifier component excluded' do
let(:exclude) { ['foo'] }
it { is_expected.to be(true) }
end

context 'non-matching identifier component excluded' do
let(:exclude) { ['xyz'] }
it { is_expected.to be(false) }
end

context 'output dir excluded' do
let(:exclude) { ['output'] }
it { is_expected.to be(false) }
end
end

describe '#pathname_components' do
subject { pruner.pathname_components(pathname) }

Expand Down