Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow acessing :pre snapshot in item itself #538

Merged
merged 1 commit into from Apr 25, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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