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
Support Padrino's partial to accept block #1099
Comments
I must add that the feature is not yet released on rubygems. It works on Padrino edge with version 0.12.0.rc. |
Thanks for the heads up. We've had to do a bit of monkey patching in the past for convoluted template chaining. People do insane things like call Slim partials from Haml inside an Erb layout. Maybe that's not necessary any more. When |
Yes, we test mixed engines since padrino/padrino-framework@e0e0bf7. It should be working. Engine/block detection also more clean and precise now. |
Sweet |
I have come up with a way to do the requested functionality with existing Middleman implementation. I've created a Source: https://gist.github.com/lolmaus/7772057 Example partial (Haml): .comment
%h2= options[:user]
%p= options[:text]
= options[:yield] Example usage (Haml): = mixin :comment, user: 'Pete', text: 'What is love?' do
= mixin :comment, user: 'Julia', text: 'Baby don\'t hurt me' Resulting HTML: <div class="comment">
<h2>Pete</h2>
<p>What is love?</p>
<div class="comment">
<h2>Julia</h2>
<p>Baby don't hurt me</p>
</div>
</div> To achieve the same with vanilla - second_comment = capture_html do
- partial 'mixins/comment', locals: { options: {user: 'Julia', text: 'Baby don\'t hurt me'}}
= partial 'mixins/comment', locals: { options: {user: 'Pete', text: 'What is love?', yield: second_comment}} ...which is very inconvenient and kinda counter-intuitive. As you can see, the
The traditional
There's explicit usage info provided alongside helper's code. I find this helper to be so useful and effective that i humbly ask you to consider including it into Middleman. |
Any update - has anyone tried this since we upgraded Padrino? |
Do you mean Git version of Middleman? The Gem version hasn't been updated since 3.2.2 in January. PS I've just noticed that Padrino is not mentioned in the |
Padrino is bundled with Middleman until the next release of Padrino which makes it possible to unbundle. |
So do i have to use Git version of Middleman to try to answer @bhollis's question? If yes, which branch? I'm currently using a funny helper to mimic that functionality so i also want to try it out. |
Use the |
I confirm that it's now working with Haml. But it fails with ERB. When you do: <%= partial :foo do %>
Bar
<% end %> You receive an error that says Middleman tries to do |
Oh, it's not supposed to. We've already discussed it here: #1250 . Who needs ERB anyway when there's Haml. Right, guys? Guys?.. |
Is the gem used |
@ujifgc It's |
I know it has been a while, but this does in fact work:
Then simply I will look into adding that to the docs. |
@jgillich that looks like just what I need! I wasn't able to get the do yield block to work. :( in _homepage-slider.erb and in /feature-pieces/homepage-slider-1.erb
I get this error: |
@jgillich I'm not sure what my issue was, but you are right your example works perfectly. Sorry for the false alarm. |
I had the same issue as @davidsilvasmith and it was because I used |
Something interesting I just found: This fails: <% partial "partials/header" do %>
<% end %> This works like a charm: <% partial "partials/header" do %>
<% end %> Do you notice the line between the "partial" and the close tag? :D |
Padrino now supports passing a block to a partial.
Partial:
Page:
= partial 'foo' do Yay, a codeblock!
Resulting HTML:
This functionality is absolutely awesome. Now Pardrino doesn't fall behind Sass and Jade which have supported passing blocks to mixins since forever.
Unfortunately, this won't work in Middleman. Middleman produces the following HTML:
@ujifgc, a Padrino maintainer who was kind to implement this feature, supposes that the problem in Middleman might take place due to this monkey patch. He suggests that we should:
The reason for the issue may hide elsewhere though.
Here's a sandbox project that can be used to test the issue quickly: https://github.com/lolmaus/middleman-padrino-test-partial-block
PS Yes, i know that Padrino/Middleman partials can accept code blocks by processing them through
capture_html
, assigning the result to variables and passing the variables to partials. But this is just ugly. Partials should be able to accept code blocks naturally, just like mixins in Sass and Jade. Padrino already made that happen. Please make Middleman compatible.The text was updated successfully, but these errors were encountered: