Module: NicePartials::CapturingYieldDetection

Defined in:
lib/nice_partials/monkey_patch.rb

Instance Method Summary collapse

Instance Method Details

#has_capturing_yield?Boolean

Matches yields that’ll end up calling ‘capture`:

<%= yield %>
<%= yield something_else %>

Doesn’t match obfuscated ‘content_for` invocations, nor custom yields:

<%= yield :message %>
<%= something.yield %>

Note: ‘<%= yield %>` becomes `yield :layout` with no `render` `block`, though this method assumes a block is passed.

Returns:

  • (Boolean)


130
131
132
133
# File 'lib/nice_partials/monkey_patch.rb', line 130

def has_capturing_yield?
  defined?(@has_capturing_yield) ? @has_capturing_yield :
    @has_capturing_yield = source.match?(/[^\.\b]yield[\(? ]+(%>|[^:])/)
end