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

Fixes #13235 - content from application layout extracted into a partial #3081

Closed
wants to merge 1 commit into from
Closed

Conversation

tstrachota
Copy link
Member

Extracting the content_for part of application layout into a separate partial will enable for using in with different parent layouts. This is key for rendering the standard foreman views with layout containing bastion_katello assets.

Intended usage:

# katello/layouts/foreman_with_bastion.html.erb
<%= content_for(:content) do %>
  <%= render :partial => 'layouts/application_content' %>
<% end %>

<%= render :file => 'bastion/layouts/assets' %>

@tstrachota
Copy link
Member Author

[test]

@ohadlevy
Copy link
Member

ohadlevy commented Jan 18, 2016 via email

@tstrachota
Copy link
Member Author

@ohadlevy I actually want to reuse contents of the content_for in a different layout. Please see https://github.com/Katello/katello/pull/5710/files#diff-6af49641613a044997bb75949b885104 for example usage.

<%= yield %>
</div>
</div>
<%= render :partial => 'layouts/application_content' %>
<% end %>

<%= render :template => 'layouts/base' %>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't you use deface and:

Deface::Override.new(
  :virtual_path => 'layouts/application',
  :name => 'bastion_assets',
  :insert_after => 'erb[loud]:contains("layouts/base")',
  :text => "<%= render :file => 'bastion/layouts/assets' %>")

? I just tried and it loads the assets just fine. It can be done before the content_for too if you need that.

@dLobatog
Copy link
Member

@tstrachota I replied inline with an example on how to do this with deface, you say you want to use application_content with another wrapper, but I don't see that on https://github.com/Katello/katello/pull/5710/files#diff-6af49641613a044997bb75949b885104 ?

If it's just to add the assets, I don't think it's needed. If you want to use a different wrapper that's not content_tag(:content), can't you use Deface's :surround and match the main div?

@tstrachota
Copy link
Member Author

@dLobatog https://github.com/Katello/katello/pull/5710/files#diff-6af49641613a044997bb75949b885104 uses foreman's original content_for in bastion's asset layout. You got it right, it's there just to add bastion and bastion_katello assets.

I played with deface too but without any success. I'm not any deface expert so I have couple of questions you could help me with:

  • Did you try your example with installed katello? When bastion_katello is added to a page with url that doesn't match any of the defined angular states it keeps reloading it (probably bug in bastion). Did you encounter such behaviour?
  • I was able to replace the layout for the whole application (:virtual_path => 'layouts/application') but I'm not sure how to limit it only to smart_proxies/show. Without that you get the issue from the previous bullet.

Although I don't understand the benefits of using deface over splitting the partials, I'm happy to throw this PR away if someone helps me to find a working deface solution.

@tstrachota
Copy link
Member Author

Just for the record, on the meeting yesterday we talked about using javascript helper instead of custom layout. I don't think that's a good idea since there's quite some in-place js code https://github.com/Katello/bastion/blob/master/app/views/bastion/layouts/assets.html.erb

@dLobatog dLobatog self-assigned this Jan 19, 2016
@dLobatog
Copy link
Member

@tstrachota The problem I see on the Katello PR is that it goes as far as to require a controller extension just to add the bastion assets. Aside from that, I worry that thinking we cannot add assets & disable stuff via deface lead us to maintain things like a "database of pages where turbolinks has top be disabled": #3086 -
The burden of adding this stuff should be primarily on the plugin developer, not on core I'd say. Especially when deface allows to do that simply. Making these conventions in core also tie core with plugins so much that it'll be very difficult to get rid of them if we need to.

You can add it just on smart_proxies/show with something like this:

Deface::Override.new(
  :virtual_path => 'smart_proxies/show',
  :name => 'bastion_assets',
  :insert_after => '.proxy-show',
  :text => "<%= render :file => 'bastion/layouts/assets' %>")

In case you need your assets to be loaded after the whole layout (no need for it I think?):

Deface::Override.new(
  :virtual_path => 'layouts/application',
  :name => 'bastion_assets',
  :insert_after => 'erb[loud]:contains("layouts/base")',
  :text => "<% if current_page?(:controller => 'smart_proxies',
                                :action => 'show', 
                                :id => (params[:id] || 0)) %>
            <%= render :file => 'bastion/layouts/assets' %>
            <% end %>")

Let me know if I'm missing something, both examples above seemed to work fine on my devel environment.

@tstrachota
Copy link
Member Author

@dLobatog did the examples work for you also with katello? I didn't manage to get them working.
bastion/layouts/assets is not a partial containing only the assets but complete layout. Again, I know very little about deface, but you can't use :insert_after in such case, can you?

I was able to get it working with

Deface::Override.new(
  :virtual_path => 'layouts/application',
  :name => 'bastion_assets',
  :replace => 'erb[loud]:contains("layouts/base")',
  :text => "<% if current_page?(:controller => 'smart_proxies',
                                :action => 'show',
                                :id => (params[:id] || 0)) %>
            <%= render :file => 'bastion/layouts/assets' %>
            <% else %>
            <%= render :file => 'layouts/base' %>
            <% end %>")

but that's not very nice.

@dLobatog
Copy link
Member

Merged as 647e331, thanks @tstrachota!

@dLobatog dLobatog closed this Jan 20, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants