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
Allow partials accept blocks #1504
Comments
@lolmaus thank you for your suggestion. Does the commit do what you wanted? |
I tried manually creating a helper with your code in a sandbox Middleman project and it didn't work out. :(
|
@ujifgc Igor, are you going to work on this further? I'm not good in Ruby enough to try finishing this on my own. I even failed to find where |
Yes, later. Not right away. |
@lolmaus could you sketch up a broken test app and publish it at github? I never used middleman before. |
Here you go: https://github.com/lolmaus/middleman-padrino-test-partial-block It's not producing an error as i had said (have you added commits?), but it doesn't work as expected. I've got a partial: %h1 prefix
.haml-block
= yield
%h3 postfix I call it like this: = partial 'foo' do
Am i the only one around here who has this failing? Resulting HTML: Am i the only one around here who has this failing?
<h1>prefix</h1>
<div class="haml-block">
0
</div>
<h3>postfix</h3> |
I fixed the issue and added a test. I'm aware that middleman stays broken but it's because recent improvements to padrino rendering extensions. The problem is, as I understand, the monkey patch https://github.com/middleman/middleman/blob/master/middleman-core/lib/middleman-more/core_extensions/default_helpers.rb#L74 that expects old code. |
Do you see how Middleman can be fixed? |
Investigate the reasons of monkey patching, remove them. Or patch to use
|
@ujifgc, Igor, can you please open an issue ticket for Middleman, explain the problem in detail and state your suggestions? I don't want to play Chinese whispers here. |
No, I'm sorry, I don't use Middleman. I looked at their code and can't figure out what are they trying to do with our helpers and why. I can guess that's some patching needed on version 0.11.4. |
Thank you @ujifgc. ^__^ |
It is awesome how Jade allows you to call mixins with different options and content blocks.
Jade:
The same functionality is found in Sass, but surprisingly is missing in Padrino's template engines. Padrino has partials functionality abstracted out of template engines into a Padrino helper, and Padrino partial helper does not accept content blocks! :(
Middleman introduces the wrap_layout helper that lets you pass a block to a layout (which in this case is almost the same as partial). Unfortunately, it does not accept options, so you can't, for example, pass local variables. :( Also, migrating partials into templates would be an ugly workaround.
I've managed to mimic the desired funcitonality by leveraging Padrino's
capture_html
. Here's an already working example (in Middleman):Partial
_test.haml
:Page
index.html.haml
:But this approach is also kinda ugly because it requires to write a block before partial call and use an ad-hoc variable to store it.
Note: you can't use
content_for
for this purpose because contents ofcontent_for
is accumulated rather than redefined when you use it multiple times.I also tried creating a helper instead of a partial-that-accepts-a-block. It made using the helper-partial awesomely clean, just as i request. But the HTML of the helper-partial had to be written in Ruby strings and assembled via
content_tag
in reverse order, which is very ugly. :(So i suggest the following syntax for Padrino partials. It is just a concept and open for discussion.
Haml:
Also, please have a look at how DerbyJS allows passing multiple blocks to a partial.
DerbyJS + Jade:
I wonder whether something similar can be done in Padrino without falling back to the
capture_html
workaround.The text was updated successfully, but these errors were encountered: