Skip to content

Commit

Permalink
Merge pull request #893 from nanoc/wrong-preprocessed-item-dependencies
Browse files Browse the repository at this point in the history
Ensure dependency graph includes preprocessor items
  • Loading branch information
denisdefreyne committed Jul 2, 2016
2 parents 4b2d757 + 54e2a94 commit 65273dc
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/nanoc/base/compilation/compiler.rb
Expand Up @@ -98,6 +98,10 @@ def run
end

def load_stores
# FIXME: icky hack to update the dependency store’s list of objects
# (does not include preprocessed objects otherwise)
dependency_store.objects = site.items.to_a + site.layouts.to_a

stores.each(&:load)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/nanoc/base/repos/dependency_store.rb
Expand Up @@ -2,7 +2,7 @@ module Nanoc::Int
# @api private
class DependencyStore < ::Nanoc::Int::Store
# @return [Array<Nanoc::Int::Item, Nanoc::Int::Layout>]
attr_reader :objects
attr_accessor :objects

# @param [Array<Nanoc::Int::Item, Nanoc::Int::Layout>] objects
def initialize(objects)
Expand Down
30 changes: 30 additions & 0 deletions spec/nanoc/regressions/gh_885_spec.rb
@@ -0,0 +1,30 @@
describe 'GH-885', site: true, stdio: true do
before do
File.write(
'content/index.html',
"<%= @items['/hello.*'].compiled_content %> - <%= Time.now.to_f %>",
)

File.write('Rules', <<EOS)
preprocess do
items.create('hi!', {}, '/hello.html')
end
compile '/**/*' do
filter :erb
write item.identifier.without_ext + '.html'
end
EOS
end

example do
Nanoc::CLI.run(%w(compile))
before = File.read('output/index.html')

sleep(0.1)
Nanoc::CLI.run(%w(compile))
after = File.read('output/index.html')
expect(after).to eql(before)
expect(after).to match(/\Ahi! - \d+/)
end
end
26 changes: 26 additions & 0 deletions spec/nanoc/regressions/gh_891_spec.rb
@@ -0,0 +1,26 @@
describe 'GH-891', site: true, stdio: true do
before do
File.write('layouts/foo.erb', 'giraffes? <%= yield %>')
File.write('Rules', <<EOS)
preprocess do
items.create('yes!', {}, '/hello.html')
end
compile '/**/*' do
layout '/foo.*'
write item.identifier.without_ext + '.html'
end
layout '/foo.*', :erb
EOS
end

example do
Nanoc::CLI.run(%w(compile))
expect(File.read('output/hello.html')).to include('giraffes?')

File.write('layouts/foo.erb', 'donkeys? <%= yield %>')
Nanoc::CLI.run(%w(compile))
expect(File.read('output/hello.html')).to include('donkeys?')
end
end

0 comments on commit 65273dc

Please sign in to comment.