Skip to content

Commit

Permalink
Merge pull request #931 from nanoc/gh-927-layout-view-dep-tracker
Browse files Browse the repository at this point in the history
Fix checking outdatedness of LayoutView
  • Loading branch information
denisdefreyne committed Aug 22, 2016
2 parents e62384d + d603d06 commit 4fb4eec
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
5 changes: 5 additions & 0 deletions lib/nanoc/base/compilation/dependency_tracker.rb
Expand Up @@ -12,11 +12,14 @@ def bounce(_obj)
end
end

include Nanoc::Int::ContractsSupport

def initialize(dependency_store)
@dependency_store = dependency_store
@stack = []
end

contract C::Or[Nanoc::Int::Item, Nanoc::Int::Layout] => C::Any
def enter(obj)
unless @stack.empty?
Nanoc::Int::NotificationCenter.post(:dependency_created, @stack.last, obj)
Expand All @@ -26,10 +29,12 @@ def enter(obj)
@stack.push(obj)
end

contract C::Or[Nanoc::Int::Item, Nanoc::Int::Layout] => C::Any
def exit(_obj)
@stack.pop
end

contract C::Or[Nanoc::Int::Item, Nanoc::Int::Layout] => C::Any
def bounce(obj)
enter(obj)
exit(obj)
Expand Down
11 changes: 6 additions & 5 deletions lib/nanoc/helpers/rendering.rb
Expand Up @@ -13,9 +13,10 @@ module Rendering
# @return [String, nil]
def render(identifier, other_assigns = {}, &block)
# Find layout
layout = @layouts[identifier]
layout ||= @layouts[identifier.__nanoc_cleaned_identifier]
raise Nanoc::Int::Errors::UnknownLayout.new(identifier) if layout.nil?
layout_view = @layouts[identifier]
layout_view ||= @layouts[identifier.__nanoc_cleaned_identifier]
raise Nanoc::Int::Errors::UnknownLayout.new(identifier) if layout_view.nil?
layout = layout_view.unwrap

# Visit
dependency_tracker = @config._context.dependency_tracker
Expand All @@ -30,7 +31,7 @@ def render(identifier, other_assigns = {}, &block)
item: @item,
item_rep: @item_rep,
items: @items,
layout: layout,
layout: layout_view,
layouts: @layouts,
config: @config,
}.merge(other_assigns)
Expand All @@ -51,7 +52,7 @@ def render(identifier, other_assigns = {}, &block)
Nanoc::Int::NotificationCenter.post(:processing_started, layout)

# Layout
content = layout.unwrap.content
content = layout.content
arg = content.binary? ? content.filename : content.string
result = filter.setup_and_run(arg, filter_args)

Expand Down
23 changes: 18 additions & 5 deletions spec/nanoc/helpers/rendering_spec.rb
Expand Up @@ -2,15 +2,22 @@
describe '#render' do
subject { helper.instance_eval { render('/partial.erb') } }

before do
layout = ctx.create_layout(layout_content, {}, layout_identifier)
ctx.update_rule_memory(layout, rule_memory_for_layout)
end

let(:rule_memory_for_layout) do
[Nanoc::Int::RuleMemoryActions::Filter.new(:erb, {})]
end

let(:layout_view) do
ctx.create_layout(layout_content, {}, layout_identifier)
end

let(:layout) do
layout_view.unwrap
end

before do
ctx.update_rule_memory(layout, rule_memory_for_layout)
end

context 'legacy identifier' do
let(:layout_identifier) { Nanoc::Identifier.new('/partial/', type: :legacy) }

Expand All @@ -19,7 +26,13 @@

context 'layout without instructions' do
let(:layout_content) { 'blah' }

it { is_expected.to eql('blah') }

it 'tracks proper dependencies' do
expect(ctx.dependency_tracker).to receive(:enter).with(layout)
subject
end
end

context 'layout with instructions' do
Expand Down
5 changes: 4 additions & 1 deletion test/base/test_dependency_tracker.rb
Expand Up @@ -87,7 +87,10 @@ def test_objects_outdated_due_to
end

def test_enter_and_exit
items = [mock, mock]
items = [
Nanoc::Int::Item.new('Foo', {}, '/foo.md'),
Nanoc::Int::Item.new('Bar', {}, '/bar.md'),
]

store = Nanoc::Int::DependencyStore.new(items)
tracker = Nanoc::Int::DependencyTracker.new(store)
Expand Down

0 comments on commit 4fb4eec

Please sign in to comment.