nanoc / features

Collection of feature requests
2 stars 1 forks source link

Option for the Capturing helper to do copy-and-paste #67

Open luc-j-bourhis opened 1 year ago

luc-j-bourhis commented 1 year ago

Current behaviour

In its current incarnation, the capturing helper is cut-and-paste. That is to say that the following

<p>Some text before</p>
<% content_for :summary do %>
  <p>On this item, Nanoc is introduced, blah blah.</p>
<% end %>
<p>Some text after</p>

will output

<p>Some text before</p>
<p>Some text after</p>

If one wants the captured text where it was written, one has to paste it right after cutting it

<p>Some text before</p>
<% content_for :summary do %>
  <p>On this item, Nanoc is introduced, blah blah.</p>
<% end %>
<%= content_for(@item, :summary) %>
<p>Some text after</p>

Or course <%= content_for(..., :summary) %> would be used elsewhere!

Desired behavior

But I have a use case where a paragraph is used as an introduction on several different pages. It would be nice to have an option to avoid typing <%= content_for(@item, :summary) %> just after the capturing context. Maybe something like.

<p>Some text before</p>
<% content_for :summary, cut: false do %>
  <p>On this item, Nanoc is introduced, blah blah.</p>
<% end %>
<p>Some text after</p>

which would result in

<p>Some text before</p>
  <p>On this item, Nanoc is introduced, blah blah.</p>
<p>Some text after</p>

as well as capturing the paragraph to be reused elsewhere. I.e. copy-and-paste.

denisdefreyne commented 1 year ago

I like that idea!

I’ll move it to the nanoc/features repository, where I collect ideas for features and improvements.

If you want to and feel up for it, you can open up a PR. The Capturing helper has a test suite that hopefully should be pretty easy to adjust too.