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
Merged

Conversation

denisdefreyne
Copy link
Member

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"

@denisdefreyne
Copy link
Member Author

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

@Fjan
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.

@denisdefreyne
Copy link
Member Author

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

@Fjan
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.

denisdefreyne added a commit that referenced this pull request Nov 29, 2015
@denisdefreyne denisdefreyne merged commit 31393f0 into master Nov 29, 2015
@denisdefreyne denisdefreyne deleted the content-for-behaviors branch November 29, 2015 21:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants