From 90964f569138c6d0dade3351aecceb071b70f242 Mon Sep 17 00:00:00 2001 From: Denis Defreyne Date: Mon, 20 Mar 2017 21:49:16 +0100 Subject: [PATCH 1/2] Add spec for #1130 --- spec/nanoc/regressions/gh_1130_spec.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 spec/nanoc/regressions/gh_1130_spec.rb diff --git a/spec/nanoc/regressions/gh_1130_spec.rb b/spec/nanoc/regressions/gh_1130_spec.rb new file mode 100644 index 0000000000..213ea3c336 --- /dev/null +++ b/spec/nanoc/regressions/gh_1130_spec.rb @@ -0,0 +1,19 @@ +describe 'GH-1130', site: true, stdio: true do + before do + File.write('content/foo', 'asdf') + + File.write('Rules', < Date: Mon, 20 Mar 2017 22:26:10 +0100 Subject: [PATCH 2/2] Use post-compile views for checks --- .../base/views/post_compile_item_rep_view.rb | 4 ++ lib/nanoc/checking/check.rb | 2 +- .../views/post_compile_item_rep_view_spec.rb | 58 +++++++++++++++++++ 3 files changed, 63 insertions(+), 1 deletion(-) diff --git a/lib/nanoc/base/views/post_compile_item_rep_view.rb b/lib/nanoc/base/views/post_compile_item_rep_view.rb index d57e774edc..c490548202 100644 --- a/lib/nanoc/base/views/post_compile_item_rep_view.rb +++ b/lib/nanoc/base/views/post_compile_item_rep_view.rb @@ -16,5 +16,9 @@ def compiled_content(snapshot: nil) content.string end + + def raw_path(snapshot: :last) + @item_rep.raw_path(snapshot: snapshot) + end end end diff --git a/lib/nanoc/checking/check.rb b/lib/nanoc/checking/check.rb index 36ea313475..36fd64c3b4 100644 --- a/lib/nanoc/checking/check.rb +++ b/lib/nanoc/checking/check.rb @@ -23,7 +23,7 @@ def self.create(site) view_context = site.compiler.compilation_context.create_view_context(Nanoc::Int::DependencyTracker::Null.new) context = { - items: Nanoc::ItemCollectionWithRepsView.new(site.items, view_context), + items: Nanoc::PostCompileItemCollectionView.new(site.items, view_context), layouts: Nanoc::LayoutCollectionView.new(site.layouts, view_context), config: Nanoc::ConfigView.new(site.config, view_context), output_filenames: output_filenames, diff --git a/spec/nanoc/base/views/post_compile_item_rep_view_spec.rb b/spec/nanoc/base/views/post_compile_item_rep_view_spec.rb index 17ae7d17c5..d2002ad9e4 100644 --- a/spec/nanoc/base/views/post_compile_item_rep_view_spec.rb +++ b/spec/nanoc/base/views/post_compile_item_rep_view_spec.rb @@ -34,6 +34,64 @@ end end + describe '#raw_path' do + context 'no args' do + subject { view.raw_path } + + it 'does not raise' do + subject + end + + context 'no path specified' do + it { is_expected.to be_nil } + end + + context 'path for default snapshot specified' do + before do + item_rep.raw_paths = { last: ['output/about/index.html'] } + end + + it { is_expected.to eql('output/about/index.html') } + end + + context 'path specified, but not for default snapshot' do + before do + item_rep.raw_paths = { pre: ['output/about/index.html'] } + end + + it { is_expected.to be_nil } + end + end + + context 'snapshot arg' do + subject { view.raw_path(snapshot: :special) } + + it 'does not raise' do + subject + end + + context 'no path specified' do + it { is_expected.to be_nil } + end + + context 'path for default snapshot specified' do + before do + item_rep.raw_paths = { special: ['output/about/index.html'] } + end + + it { is_expected.to eql('output/about/index.html') } + end + + context 'path specified, but not for default snapshot' do + before do + item_rep.raw_paths = { pre: ['output/about/index.html'] } + end + + it { is_expected.to be_nil } + end + end + end + describe '#compiled_content' do subject { view.compiled_content }