Sinatra-Partial icon indicating copy to clipboard operation
Sinatra-Partial copied to clipboard

Pass block to partial to enable yielding from partials

Open archiloque opened this issue 8 years ago • 4 comments

archiloque avatar Nov 07 '15 10:11 archiloque

Hi @archiloque

Thanks for this. It looks fine, but I either need a spec to go with it or an example I can use.

Regards, iain

yb66 avatar Nov 07 '15 10:11 yb66

Hello,

an example, since I'm not sure how to make a relevant test

  • when using https://gist.github.com/seanami/496702 you can write sinatra helpers with blocks
  • write this kind of partial
<form>
  <% yield %>
</form>
  • then declare a helper like this
def my_partial_with_block(&block)
  buffer << partial(:'my_helper.html', &block)
end
  • then in your erb file you can call the partial with a block
<% my_partial_with_block do %>
<!-- some html here -->
<% end %>

It's handy to make your templates cleaner when using things like bootstrap that require much boilerplate html.

archiloque avatar Nov 07 '15 10:11 archiloque

Ok, thanks. I'll give it a look over the weekend and try to knock up some relevant specs for it.

regards, iain

yb66 avatar Nov 07 '15 10:11 yb66

After thinking about it I wonder if it would make sense to include the gist content in the gem since using partial with blocks like in rails is a not-so-rare usecase, what do you think ?

archiloque avatar Nov 07 '15 16:11 archiloque