Skip to content

Commit

Permalink
Allow acessing :pre snapshot in item itself
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdefreyne committed Mar 7, 2015
1 parent 59a0ef4 commit a453272
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
16 changes: 12 additions & 4 deletions lib/nanoc/base/result_data/item_rep.rb
Expand Up @@ -243,12 +243,20 @@ def compiled_content(params = {})
raise Nanoc::Errors::NoSuchSnapshot.new(self, snapshot)
end

# Require compilation
if @content[snapshot].nil? || (!self.compiled? && is_moving)
# Verify snapshot is usable
is_still_moving =
case snapshot
when :post, :last
true
when :pre
!@content.key?(:post)
end
is_usable_snapshot = @content[snapshot] && (self.compiled? || !is_still_moving)
unless is_usable_snapshot
raise Nanoc::Errors::UnmetDependency.new(self)
else
@content[snapshot]
end

@content[snapshot]
end

# Checks whether content exists at a given snapshot.
Expand Down
30 changes: 30 additions & 0 deletions test/base/test_item_rep.rb
Expand Up @@ -77,6 +77,36 @@ def test_compiled_content_with_uncompiled_content
end
end

def test_compiled_content_with_moving_pre_snapshot
# Create rep
item = Nanoc::Item.new(
'blah blah', {}, '/',
binary: false
)
rep = Nanoc::ItemRep.new(item, nil)
rep.expects(:compiled?).returns(false)
rep.instance_eval { @content = { pre: 'pre!', last: 'last!' } }

# Check
assert_raises(Nanoc::Errors::UnmetDependency) do
rep.compiled_content(snapshot: :pre)
end
end

def test_compiled_content_with_non_moving_pre_snapshot
# Create rep
item = Nanoc::Item.new(
'blah blah', {}, '/',
binary: false
)
rep = Nanoc::ItemRep.new(item, nil)
rep.expects(:compiled?).returns(false)
rep.instance_eval { @content = { pre: 'pre!', post: 'post!', last: 'last!' } }

# Check
assert_equal 'pre!', rep.compiled_content(snapshot: :pre)
end

def test_filter
# Mock site
site = MiniTest::Mock.new
Expand Down

0 comments on commit a453272

Please sign in to comment.