Skip to content
Permalink
Browse files

Merge pull request #1099 from nanoc/gh-1097

Let #raw_path require rep to be compiled
  • Loading branch information...
ddfreyne committed Mar 3, 2017
2 parents bd68540 + c5457dd commit e3c883dbcfc41867e4fa2e71e66adf40fc3ae5fe
@@ -75,7 +75,14 @@ def item
# @api private
def raw_path(snapshot: :last)
@context.dependency_tracker.bounce(unwrap.item, path: true)
@item_rep.raw_path(snapshot: snapshot)

res = @item_rep.raw_path(snapshot: snapshot)

unless @item_rep.compiled?
Fiber.yield(Nanoc::Int::Errors::UnmetDependency.new(@item_rep))
end

res
end

# @api private
@@ -26,7 +26,7 @@ def xml_sitemap(params = {})
xml.urlset(xmlns: 'http://www.sitemaps.org/schemas/sitemap/0.9') do
# Add item
items.sort_by(&:identifier).each do |item|
reps = item.reps.reject { |r| r.raw_path.nil? }
reps = item.reps.select(&:path)
reps.select! { |r| select_proc[r] } if select_proc
reps.sort_by { |r| r.name.to_s }.each do |rep|
xml.url do
@@ -283,7 +283,7 @@
end

describe '#raw_path' do
subject { view.raw_path }
subject { Fiber.new { view.raw_path }.resume }

let(:view) { described_class.new(rep, view_context) }

@@ -299,22 +299,45 @@
Nanoc::Int::Item.new('content', {}, '/asdf.md')
end

it 'creates a dependency' do
expect { subject }.to change { dependency_store.objects_causing_outdatedness_of(base_item) }.from([]).to([item])
end
context 'rep is not compiled' do
it 'creates a dependency' do
expect { subject }.to change { dependency_store.objects_causing_outdatedness_of(base_item) }.from([]).to([item])
end

it 'creates a dependency with the right props' do
subject
dep = dependency_store.dependencies_causing_outdatedness_of(base_item)[0]
it 'creates a dependency with the right props' do
subject
dep = dependency_store.dependencies_causing_outdatedness_of(base_item)[0]

expect(dep.props.path?).to eq(true)
expect(dep.props.path?).to eq(true)

expect(dep.props.raw_content?).to eq(false)
expect(dep.props.attributes?).to eq(false)
expect(dep.props.compiled_content?).to eq(false)
expect(dep.props.raw_content?).to eq(false)
expect(dep.props.attributes?).to eq(false)
expect(dep.props.compiled_content?).to eq(false)
end

it { should be_a(Nanoc::Int::Errors::UnmetDependency) }
end

it { should eq('output/about/index.html') }
context 'rep is compiled' do
before { rep.compiled = true }

it 'creates a dependency' do
expect { subject }.to change { dependency_store.objects_causing_outdatedness_of(base_item) }.from([]).to([item])
end

it 'creates a dependency with the right props' do
subject
dep = dependency_store.dependencies_causing_outdatedness_of(base_item)[0]

expect(dep.props.path?).to eq(true)

expect(dep.props.raw_content?).to eq(false)
expect(dep.props.attributes?).to eq(false)
expect(dep.props.compiled_content?).to eq(false)
end

it { should eq('output/about/index.html') }
end
end

describe '#binary?' do
@@ -0,0 +1,21 @@
describe 'GH-1097', site: true, stdio: true do
before do
File.write('content/a.dat', 'foo')
File.write('content/index.html', '<%= @items.find_all("/*.dat").flat_map(&:reps).all? { |r| File.file?(r.raw_path) } %>')
File.write('content/z.dat', 'quux')

File.write('Rules', <<EOS)
compile '/**/*.html' do
filter :erb
write item.identifier.to_s
end

passthrough '/**/*.dat'
EOS
end

it 'generates dependency on all reps' do
Nanoc::CLI.run(%w(compile))
expect(File.read('output/index.html')).to eql('true')
end
end

0 comments on commit e3c883d

Please sign in to comment.
You can’t perform that action at this time.