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

Add behaviors to #content_for #744

Merged
merged 1 commit into from Nov 29, 2015

Conversation

Projects
None yet
2 participants
@ddfreyne
Copy link
Member

ddfreyne commented Nov 29, 2015

Fixes #704.

#content_for, when given a block, now gains a second parameter, :existing, which determines what to do when existing content already exists. The three possible values are:

  • :error (current behavior): when content already exists and is not identical, raise an error.
  • :overwrite: overwrite the previously captured content with the newly captured content
  • :append: append the newly captured content to the previously captured content

For example:

<% content_for(:stuff) do %>banana<% end %>
<% content_for(:stuff, existing: :append) do %>donkey<% end %>

will result in content_for(:stuff) containing "bananadonkey"

<% content_for(:stuff) do %>banana<% end %>
<% content_for(:stuff, existing: :error) do %>donkey<% end %>

will raise an exception

<% content_for(:stuff) do %>banana<% end %>
<% content_for(:stuff, existing: :overwrite) do %>donkey<% end %>

will result in content_for(:stuff) containing "donkey"

@ddfreyne ddfreyne added this to the 4.1.0 milestone Nov 29, 2015

@ddfreyne ddfreyne force-pushed the content-for-behaviors branch 4 times, most recently from 1951a2b to 7f5c090 Nov 29, 2015

@ddfreyne ddfreyne added to review and removed status:wip 🔧 labels Nov 29, 2015

@ddfreyne

This comment has been minimized.

Copy link
Member Author

ddfreyne commented Nov 29, 2015

CC @Fjan — this is the behavior you’re looking for.

@ddfreyne ddfreyne force-pushed the content-for-behaviors branch from 7f5c090 to 7705a89 Nov 29, 2015

@ddfreyne ddfreyne force-pushed the content-for-behaviors branch from 7705a89 to 2517cba Nov 29, 2015

@ddfreyne ddfreyne force-pushed the content-for-behaviors branch from 2517cba to f5b07c8 Nov 29, 2015

@Fjan

This comment has been minimized.

Copy link
Contributor

Fjan commented Nov 29, 2015

Yes, thank you. I would probably still be a good idea to make :append the default at some point to make it's behaviour similar to the content_for in Rails.

@ddfreyne

This comment has been minimized.

Copy link
Member Author

ddfreyne commented Nov 29, 2015

That’ll have to be for Nanoc 5 (since it’s a breaking change).

@Fjan

This comment has been minimized.

Copy link
Contributor

Fjan commented Nov 29, 2015

We can be pretty confident that the current default behaviour is not used by anyone, because it would raise an exception, so I wouldn't call it a breaking change. But I'm fine with waiting until the next version.

ddfreyne added a commit that referenced this pull request Nov 29, 2015

Merge pull request #744 from nanoc/content-for-behaviors
Add behaviors to #content_for

@ddfreyne ddfreyne merged commit 31393f0 into master Nov 29, 2015

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls Coverage increased (+0.04%) to 91.634%
Details

@ddfreyne ddfreyne deleted the content-for-behaviors branch Nov 29, 2015

@ddfreyne ddfreyne removed the to review label Nov 29, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.