Skip to content
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 'gf' to find view partials when rendering layouts #149

Closed
wants to merge 1 commit into from

Conversation

robertwahler
Copy link

This treats

<%= render(:layout => 'shared/filter_group') do %>

the same as

<%= render(:partial => 'shared/filter_default') %>

when doing a 'gf'

This treats

   <%= render(:layout => 'shared/filter_group') do  %>

the same as

    <%= render(:partial => 'shared/filter_default') %>

when doing a 'gf'
@tpope
Copy link
Owner

tpope commented Apr 1, 2012

I've never seen render :layout in a view before. (For that matter, I've never seen render in a view take a block, either.) Is this documented somewhere?

@Mange
Copy link

Mange commented Apr 1, 2012

ActionView::PartialRenderer, look under "Rendering partials with layouts".

As a coincidence, I saw it for the first time a few days ago.

@robertwahler
Copy link
Author

I don't know how long the syntax has been available but it is pretty handy to be able to pass a block to a partial. I've been using it recently to move most of my markup into shared partials.

@tpope
Copy link
Owner

tpope commented Apr 1, 2012

Okay, hmm, surprised I missed this.

Since this is a layout, and as such defaults to the layouts directory, this should be implemented with s:findlayout() rather than s:findview(). s:findlayout() doesn't support overriding the directory, so you'll have to fix that as well (which should be easy, but speak up if you have trouble). Side note: It's weird that you put the layout in shared when Rails clearly wants you to put it in layouts. But I'm not judging.

And since this behavior is incorrect for a controller, at the very least it needs to be wrapped in a if !buffer.type_name('controller') conditional. Bonus points if you implement the correct behavior for controllers as well.

@robertwahler
Copy link
Author

What you are asking me to do, while reasonable, will take me out of my vim script comfort-zone. If you think this functionality is worth the effort, would you just drop my pull request and implement it correctly from scratch? Thanks!

BTW, I do have a location convention for storing layouts and partials. Layouts go in 'layouts' and shared partials go in 'shared'. Just like you would expect. Everything in my 'shared' folder can be called using the ':partial' syntax even though they can also yield if a block is given. I think of partials as small chunks of reusable markup that don't require a
block and layouts as larger chunks of markup that do require a block.

@tpope
Copy link
Owner

tpope commented Jul 8, 2012

Done and done. I was totally wrong about needing to default to the layouts directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants