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

Conversation

Projects
None yet
4 participants
@ddfreyne
Member

ddfreyne commented Mar 7, 2015

Fix for #537.

The :pre snapshot can now be accessed within the item itself, provided that the :post snapshot is present (because at that point, the :pre snapshot stops moving).

The implementation of the fix in this PR is conceptually the same as in the aforementioned bug, but refactored.

CC @nanoc/contributors @jethrogb

@ddfreyne

This comment has been minimized.

Show comment
Hide comment
@ddfreyne

ddfreyne Apr 18, 2015

Member

Can I get a code review?

Member

ddfreyne commented Apr 18, 2015

Can I get a code review?

@ddfreyne ddfreyne modified the milestone: 3.7.6 Apr 19, 2015

@mpapis

This comment has been minimized.

Show comment
Hide comment
@mpapis

mpapis Apr 19, 2015

Member

👍 looks reasonable - although I do not have full understanding of it so I might be missing something

Member

mpapis commented Apr 19, 2015

👍 looks reasonable - although I do not have full understanding of it so I might be missing something

@bobthecow

This comment has been minimized.

Show comment
Hide comment
@bobthecow

bobthecow Apr 19, 2015

Member

Is the :pre snapshot usable after other (explicit) snapshots have been created but before :post is present?

Member

bobthecow commented Apr 19, 2015

Is the :pre snapshot usable after other (explicit) snapshots have been created but before :post is present?

@ddfreyne

This comment has been minimized.

Show comment
Hide comment
@ddfreyne

ddfreyne Apr 19, 2015

Member

Yeah, :pre is always usable.

Edit: :pre is usable except in the item itself. See this comment.

Member

ddfreyne commented Apr 19, 2015

Yeah, :pre is always usable.

Edit: :pre is usable except in the item itself. See this comment.

@bobthecow

This comment has been minimized.

Show comment
Hide comment
@bobthecow

bobthecow Apr 20, 2015

Member

Then maybe I missed something? I thought this was setting it up to allow accessing :pre once :post is present?

Member

bobthecow commented Apr 20, 2015

Then maybe I missed something? I thought this was setting it up to allow accessing :pre once :post is present?

@ddfreyne

This comment has been minimized.

Show comment
Hide comment
@ddfreyne

ddfreyne Apr 20, 2015

Member

@bobthecow This allows accessing :pre from the item itself, once :post is set. Previously, accessing :pre was only possible from other items.

Member

ddfreyne commented Apr 20, 2015

@bobthecow This allows accessing :pre from the item itself, once :post is set. Previously, accessing :pre was only possible from other items.

@bobthecow

This comment has been minimized.

Show comment
Hide comment
@bobthecow

bobthecow Apr 20, 2015

Member

Right. So I was asking if you should be able to access :pre from the item itself, once, e.g., :mysnapshot is set.

Member

bobthecow commented Apr 20, 2015

Right. So I was asking if you should be able to access :pre from the item itself, once, e.g., :mysnapshot is set.

@ddfreyne

This comment has been minimized.

Show comment
Hide comment
@ddfreyne

ddfreyne Apr 21, 2015

Member

@bobthecow Hm, re-reading the original question, I think my answer is misleading.

From within the item itself, using :pre when there is no :post snapshot will lead to an exception (since you’d recursively let compiled content depend on itself). When there is a :post snapshot, that works from within the item itself (since :pre cannot move anymore).

When accessing the compiled content from another item, accessing :pre is possible even if there is no :post: nanoc will compile the accessed item first, guaranteeing that :pre is in its final position.

These moving pre-snapshots and post-snapshots are difficult to reason about and one of the reasons why they’ll be gone in nanoc 4!

Member

ddfreyne commented Apr 21, 2015

@bobthecow Hm, re-reading the original question, I think my answer is misleading.

From within the item itself, using :pre when there is no :post snapshot will lead to an exception (since you’d recursively let compiled content depend on itself). When there is a :post snapshot, that works from within the item itself (since :pre cannot move anymore).

When accessing the compiled content from another item, accessing :pre is possible even if there is no :post: nanoc will compile the accessed item first, guaranteeing that :pre is in its final position.

These moving pre-snapshots and post-snapshots are difficult to reason about and one of the reasons why they’ll be gone in nanoc 4!

@gpakosz

This comment has been minimized.

Show comment
Hide comment
@gpakosz

gpakosz Apr 21, 2015

Member

Does it make :pre accessible at the time you're laying out an item? A while ago, when I tried to extract a TOC from @item.compiled_content(:snapshot => :pre) inside my default layout.haml layout, I think nanoc bailed out. So I used yield instead:

%main#content.container
  - toc = extract_toc(yield, :depth => @item[:toc_depth])
Member

gpakosz commented Apr 21, 2015

Does it make :pre accessible at the time you're laying out an item? A while ago, when I tried to extract a TOC from @item.compiled_content(:snapshot => :pre) inside my default layout.haml layout, I think nanoc bailed out. So I used yield instead:

%main#content.container
  - toc = extract_toc(yield, :depth => @item[:toc_depth])
@ddfreyne

This comment has been minimized.

Show comment
Hide comment
@ddfreyne

ddfreyne Apr 21, 2015

Member

@gpakosz That’s still not possible, but yield is intended to be used in that case anyway.

Member

ddfreyne commented Apr 21, 2015

@gpakosz That’s still not possible, but yield is intended to be used in that case anyway.

@ddfreyne ddfreyne removed the to review label Apr 25, 2015

ddfreyne added a commit that referenced this pull request Apr 25, 2015

Merge pull request #538 from nanoc/allow-accessing-pre-in-self
Allow acessing :pre snapshot in item itself

@ddfreyne ddfreyne merged commit fb21273 into release-3.7.x Apr 25, 2015

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

@ddfreyne ddfreyne deleted the allow-accessing-pre-in-self branch Apr 25, 2015

ddfreyne added a commit that referenced this pull request May 1, 2015

@ddfreyne ddfreyne modified the milestone: 3.7.6 May 4, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment