Skip to content

Commit

Permalink
Merge pull request #1131 from nanoc/gh-1130
Browse files Browse the repository at this point in the history
Use post-compile views in checks
  • Loading branch information
denisdefreyne committed Mar 20, 2017
2 parents 9a127e6 + 548faa7 commit c12fe42
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/nanoc/base/views/post_compile_item_rep_view.rb
Expand Up @@ -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
2 changes: 1 addition & 1 deletion lib/nanoc/checking/check.rb
Expand Up @@ -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,
Expand Down
58 changes: 58 additions & 0 deletions spec/nanoc/base/views/post_compile_item_rep_view_spec.rb
Expand Up @@ -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 }

Expand Down
19 changes: 19 additions & 0 deletions 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', <<EOS)
passthrough '/**/*'
EOS

File.write('Checks', <<EOS)
check :wat do
@items.flat_map(&:reps).map(&:raw_path)
end
EOS
end

it 'does not raise fiber error' do
Nanoc::CLI.run(%w(check wat))
end
end

0 comments on commit c12fe42

Please sign in to comment.