Permalink
Browse files

Plugins: support engines with isolated_namespace

Links in the header need to work when the default layout is used by a
plugin with isolated namespace. Also, use the url prefix as the "as"
argument to mount so that the helper class is correct (for some reason
it seems to disregard engine_name).
  • Loading branch information...
1 parent 36477ef commit 4dca556f207e0efb867061a93f967740b0f2d51b @mikldt mikldt committed Dec 21, 2012
Showing with 23 additions and 13 deletions.
  1. +22 −12 app/views/elements/_topmenu_contents.html.erb
  2. +1 −1 config/initializers/12-plugins.rb
@@ -1,24 +1,34 @@
+<% # Important note on linking from the topmenu:
+ #
+ # The application layout and this topmenu will be included into
+ # view for plugins, where the Concerto controller's routing
+ # helpers will not be in scope. Therefore, we refer to these links
+ # using the "main_app" object.
+ #
+ # For example: main_app.feeds_path yields the path to the normal
+ # feeds controller, and works both from Concerto and plugins.
+%>
<nav id="top-menu">
<% if not user_signed_in? %>
- <%= link_to "Concerto", root_url, :id => "top-menu-logobutton" %>
+ <%= link_to "Concerto", main_app.root_url, :id => "top-menu-logobutton" %>
<p id="top-menu-logintext">
- <%= link_to t(:sign_in), new_user_session_path, :id => "login-dropdown" %> <%=t(:signin_login_spiel) %>
+ <%= link_to t(:sign_in), main_app.new_user_session_path, :id => "login-dropdown" %> <%=t(:signin_login_spiel) %>
<% if can? :create, User %>
- <%= t(:no_account) %> <%= link_to t(:sign_up), new_user_registration_path %> <%= t(:now) %>
+ <%= t(:no_account) %> <%= link_to t(:sign_up), main_app.new_user_registration_path %> <%= t(:now) %>
<% end %>
</p>
<% else %>
- <%= link_to root_url, :id => "top-menu-logobutton", :class => "full" do %>
+ <%= link_to main_app.root_url, :id => "top-menu-logobutton", :class => "full" do %>
<i class="icon-logobutton"></i>
<% end %>
<!-- Begin Menu for CONTENT -->
<section>
<div class="top-menu-sectop">
- <%= link_to t(:browse), feeds_path, :class => "btn #{ current_page?(feeds_path) || current_page?(root_path) ? 'selected' : '' }" %>
- <%= link_to t(:add), new_content_path, :class => "btn #{ current_page?(new_content_path) ? 'selected' : '' }" if can? :create, Content %>
+ <%= link_to t(:browse), main_app.feeds_path, :class => "btn #{ current_page?(main_app.feeds_path) || current_page?(main_app.root_path) ? 'selected' : '' }" %>
+ <%= link_to t(:add), main_app.new_content_path, :class => "btn #{ current_page?(main_app.new_content_path) ? 'selected' : '' }" if can? :create, Content %>
<% if @pending_submissions_count %>
- <%= link_to moderate_path, :class => "tooltip-basic btn #{ current_page?(moderate_path) ? 'selected' : '' }", 'data-tooltip-text' => "You have #{ @pending_submissions_count } submissions to moderate" do %>
+ <%= link_to main_app.moderate_path, :class => "tooltip-basic btn #{ current_page?(main_app.moderate_path) ? 'selected' : '' }", 'data-tooltip-text' => "You have #{ @pending_submissions_count } submissions to moderate" do %>
<%= t(:moderate) %>&nbsp;<span class="badge<% if @pending_submissions_count > 0 %> action<% end %>"><%= @pending_submissions_count %></span>
<% end %>
<% end %>
@@ -32,8 +42,8 @@
<!-- Begin Menu for NETWORK -->
<section>
<div class="top-menu-sectop">
- <%= link_to t(:screens), screens_path, :class => "btn #{ controller.controller_name == 'screens' ? 'selected' : '' }" %>
- <%= link_to t(:users_and_groups), groups_path, :class => "btn #{ controller.controller_name == 'groups' ? 'selected' : '' }" %>
+ <%= link_to t(:screens), main_app.screens_path, :class => "btn #{ controller.controller_name == 'screens' ? 'selected' : '' }" %>
+ <%= link_to t(:users_and_groups), main_app.groups_path, :class => "btn #{ controller.controller_name == 'groups' ? 'selected' : '' }" %>
</div>
<div class="top-menu-secbot">
<h1><%= t(:network) %></h1>
@@ -44,7 +54,7 @@
<!-- Begin Menu for ADMIN -->
<section>
<div class="top-menu-sectop">
- <%= link_to t(:dashboard), dashboard_path, :class => "btn #{ controller.controller_name == 'dashboard' ? 'selected' : '' }" %>
+ <%= link_to t(:dashboard), main_app.dashboard_path, :class => "btn #{ controller.controller_name == 'dashboard' ? 'selected' : '' }" %>
</div>
<div class="top-menu-secbot">
<h1><%= t(:admin) %></h1>
@@ -60,8 +70,8 @@
<% if can? :update, Group %><i class="icon-user-leader tooltip-basic" data-tooltip-text="<%= t(:leader) %>"></i><% end %>
</div>
<div class="pull-right">
- <h2><%= link_to current_user.name, current_user %></h2>
- <p><%= link_to t(:settings), edit_user_path(current_user) %>&nbsp;&nbsp;&nbsp;<%= link_to t(:log_out), destroy_user_session_path %></p>
+ <h2><%= link_to current_user.name, [main_app, current_user] %></h2>
+ <p><%= link_to t(:settings), main_app.edit_user_path(current_user) %>&nbsp;&nbsp;&nbsp;<%= link_to t(:log_out), main_app.destroy_user_session_path %></p>
</div>
</div>
@@ -16,7 +16,7 @@
Rails.application.routes.append do
if ConcertoPlugin.apps_to_mount.is_a? Array
ConcertoPlugin.apps_to_mount.each do |app|
- mount app[:rack_app] => "/" + app[:url_string]
+ mount app[:rack_app] => "/" + app[:url_string], :as => app[:url_string]
# e.g. mount ConcertoHardware::Engine => "/hardware"
end
end

0 comments on commit 4dca556

Please sign in to comment.